added toJSON func
This commit is contained in:
@@ -117,7 +117,8 @@ def oidc():
|
|||||||
|
|
||||||
user = create_or_retrieve_user_from_userinfo(flask.session['userinfo'])
|
user = create_or_retrieve_user_from_userinfo(flask.session['userinfo'])
|
||||||
|
|
||||||
return jsonify(user.to_dict())
|
#return jsonify(user.to_dict())
|
||||||
|
return user.toJSON()
|
||||||
if user is None:
|
if user is None:
|
||||||
return "Could not authenticate: could not find or create user.", 401
|
return "Could not authenticate: could not find or create user.", 401
|
||||||
if current_app.config.get("AUTH_RETURN_EXTERNAL_JWT", False):
|
if current_app.config.get("AUTH_RETURN_EXTERNAL_JWT", False):
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
"""
|
"""
|
||||||
Example user model and related models
|
Example user model and related models
|
||||||
"""
|
"""
|
||||||
|
import json
|
||||||
|
|
||||||
from sqlalchemy.orm import relation
|
from sqlalchemy.orm import relation
|
||||||
from sqlalchemy import MetaData
|
from sqlalchemy import MetaData
|
||||||
|
|
||||||
@@ -347,7 +349,12 @@ class User(UserMixin, db.Model):
|
|||||||
followers.c.follower_id == self.id).order_by(Post.timestamp.desc())
|
followers.c.follower_id == self.id).order_by(Post.timestamp.desc())
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
return dict(id=self.id, email=self.email, groups=self.groups)
|
#return self.__dict__
|
||||||
|
return dict(id=self.id, email=self.email, groups=[g.to_dict() for g in self.groups])
|
||||||
|
|
||||||
|
def toJSON(self):
|
||||||
|
return json.dumps(self.to_dict(), default=lambda o: o.__dict__,
|
||||||
|
sort_keys=True, indent=4)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<User %r>' % self.nickname
|
return '<User %r>' % self.nickname
|
||||||
@@ -403,3 +410,10 @@ class Group(db.Model):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
return dict(id=self.id, name=self.name)
|
||||||
|
|
||||||
|
def toJSON(self):
|
||||||
|
return json.dumps(self.to_dict(), default=lambda o: o.__dict__,
|
||||||
|
sort_keys=True, indent=4)
|
||||||
|
|||||||
Reference in New Issue
Block a user