Skip to content

Commit

Permalink
fix(login): add function get_user_data to fix inpn cas login
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentCauchois committed May 22, 2024
1 parent 63c8e2a commit 854c0a9
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/pypnusershub/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import logging

import datetime
from flask_login import login_user, logout_user, current_user
from flask_login import login_required, login_user, logout_user, current_user
from flask import (
Blueprint,
request,
Expand Down Expand Up @@ -89,6 +89,24 @@ def load_current_user():
from pypnusershub.decorators import check_auth


@routes.route("/get_current_user")
@login_required
def get_user_data():
user_dict = UserSchema(exclude=["remarques"], only=["+max_level_profil"]).dump(
g.current_user
)

token_exp = datetime.datetime.now(datetime.timezone.utc)
token_exp += datetime.timedelta(seconds=current_app.config.get("COOKIE_EXPIRATION", 3600))
data = {
"user": user_dict,
"token": encode_token(g.current_user.as_dict()).decode(),
"expires": token_exp.isoformat(),
}

return jsonify(data)


@routes.route("/login", methods=["POST"])
def login():
user_data = request.json
Expand Down

0 comments on commit 854c0a9

Please sign in to comment.