diff --git a/ClientProf/src/main.py b/ClientProf/src/main.py index 59f422a..aac056d 100644 --- a/ClientProf/src/main.py +++ b/ClientProf/src/main.py @@ -12,6 +12,8 @@ @app.route('/') def home() -> Response: + if is_logged_in(): + return redirect('/devoirs') return redirect('/login') @app.route('/nouveau', methods=['GET']) diff --git a/ClientProf/src/utils.py b/ClientProf/src/utils.py index dddef79..f99efee 100644 --- a/ClientProf/src/utils.py +++ b/ClientProf/src/utils.py @@ -35,7 +35,11 @@ def backend_request(f: Callable, url: str, **params: Any) -> Any: return response -# Vérifie si l'utilisateur connecté à le rôle d'admin +def is_logged_in() -> bool: + response = backend_request(requests.get, 'http://localhost:5000/api/is_logged_in', cookies=request.cookies) + return json.loads(response.content) == 'ok' + +# Récupère le username du login def get_username() -> Any: response = backend_request(requests.get, 'http://localhost:5000/api/username', cookies=request.cookies) return json.loads(response.content)['user'] diff --git a/Serveur/src/api.py b/Serveur/src/api.py index c180ffa..1a3168e 100644 --- a/Serveur/src/api.py +++ b/Serveur/src/api.py @@ -286,6 +286,12 @@ def get_enseignants() -> Response: def get_username() -> Response: return jsonify(user = get_jwt_identity()) + +@api.route('/is_logged_in', methods=['GET']) +@jwt_optional +def is_logged_in() -> Response: + return jsonify('ok' if get_jwt_identity else 'not ok') + @api.route('/is_admin', methods=['GET']) @jwt_required def get_is_admin() -> Response: