mirror of
https://github.com/simple-login/app.git
synced 2025-02-23 23:34:05 +08:00
return profile_picture_url in GET /user_info
This commit is contained in:
parent
0307793666
commit
3f40e3c1cf
3 changed files with 28 additions and 11 deletions
|
@ -744,7 +744,7 @@ Some errors should be fixed during development however: for example error like `
|
|||
|
||||
All following endpoint return `401` status code if the API Key is incorrect.
|
||||
|
||||
### Authentication endpoints
|
||||
### Account endpoints
|
||||
|
||||
#### POST /api/auth/login
|
||||
|
||||
|
@ -845,7 +845,8 @@ Output: if api key is correct, return a json with user name and whether user is
|
|||
"name": "John Wick",
|
||||
"is_premium": false,
|
||||
"email": "john@wick.com",
|
||||
"in_trial": true
|
||||
"in_trial": true,
|
||||
"profile_picture_url": "https://profile.png"
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -1,10 +1,31 @@
|
|||
import base64
|
||||
from io import BytesIO
|
||||
|
||||
from flask import jsonify, g, request, make_response
|
||||
from flask_login import logout_user
|
||||
|
||||
from app import s3
|
||||
from app.api.base import api_bp, require_api_auth
|
||||
from app.config import SESSION_COOKIE_NAME
|
||||
from app.extensions import db
|
||||
from app.models import ApiKey
|
||||
from app.models import ApiKey, File, User
|
||||
from app.utils import random_string
|
||||
|
||||
|
||||
def user_to_dict(user: User) -> dict:
|
||||
ret = {
|
||||
"name": user.name,
|
||||
"is_premium": user.is_premium(),
|
||||
"email": user.email,
|
||||
"in_trial": user.in_trial(),
|
||||
}
|
||||
|
||||
if user.profile_picture_id:
|
||||
ret["profile_picture_url"] = user.profile_picture.get_url()
|
||||
else:
|
||||
ret["profile_picture_url"] = None
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
@api_bp.route("/user_info")
|
||||
|
@ -15,14 +36,7 @@ def user_info():
|
|||
"""
|
||||
user = g.user
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
"name": user.name,
|
||||
"is_premium": user.is_premium(),
|
||||
"email": user.email,
|
||||
"in_trial": user.in_trial(),
|
||||
}
|
||||
)
|
||||
return jsonify(user_to_dict(user))
|
||||
|
||||
|
||||
@api_bp.route("/api_key", methods=["POST"])
|
||||
|
|
|
@ -2,6 +2,7 @@ from flask import url_for
|
|||
|
||||
from app.extensions import db
|
||||
from app.models import User, ApiKey
|
||||
from tests.utils import login
|
||||
|
||||
|
||||
def test_user_in_trial(flask_client):
|
||||
|
@ -24,6 +25,7 @@ def test_user_in_trial(flask_client):
|
|||
"name": "Test User",
|
||||
"email": "a@b.c",
|
||||
"in_trial": True,
|
||||
"profile_picture_url": None,
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue