Skip to content

Commit

Permalink
Rediction vers login si pas connectecté sinon /devoirs
Browse files Browse the repository at this point in the history
  • Loading branch information
EvannBerthou committed Jan 11, 2021
1 parent 7d6fe6b commit d2ba735
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ClientProf/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

@app.route('/')
def home() -> Response:
if is_logged_in():
return redirect('/devoirs')
return redirect('/login')

@app.route('/nouveau', methods=['GET'])
Expand Down
6 changes: 5 additions & 1 deletion ClientProf/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
6 changes: 6 additions & 0 deletions Serveur/src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d2ba735

Please sign in to comment.