本文整理汇总了Python中flask_jwt_extended.get_jwt_identity方法的典型用法代码示例。如果您正苦于以下问题:Python flask_jwt_extended.get_jwt_identity方法的具体用法?Python flask_jwt_extended.get_jwt_identity怎么用?Python flask_jwt_extended.get_jwt_identity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_jwt_extended
的用法示例。
在下文中一共展示了flask_jwt_extended.get_jwt_identity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
# 需要导入模块: import flask_jwt_extended [as 别名]
# 或者: from flask_jwt_extended import get_jwt_identity [as 别名]
def delete(self, id):
dbm = access.DBMan(LOST_CONFIG)
identity = get_jwt_identity()
user = dbm.get_user_by_id(identity)
if not user.has_role(roles.DESIGNER):
dbm.close_session()
return "You are not authorized.", 401
group = dbm.get_group_by_id(id)
if group:
dbm.delete(group)
dbm.commit()
dbm.close_session()
return 'success', 200
else:
dbm.close_session()
return "Group with ID '{}' not found.".format(id), 400
示例2: get
# 需要导入模块: import flask_jwt_extended [as 别名]
# 或者: from flask_jwt_extended import get_jwt_identity [as 别名]
def get(self):
dbm = access.DBMan(LOST_CONFIG)
identity = get_jwt_identity()
user = dbm.get_user_by_id(identity)
if not user.has_role(roles.DESIGNER):
dbm.close_session()
return "You need to be {} in order to perform this request.".format(roles.DESIGNER), 401
else:
# for group in user.groups:
# print("--- printing group of user.groups ---")
# print(group)
group_ids = [g.idx for g in user.groups]
re = pipeline_service.get_pipelines(dbm, group_ids)
dbm.close_session()
# print("--- PipelineList result ---")
# print(re)
return re
示例3: post
# 需要导入模块: import flask_jwt_extended [as 别名]
# 或者: from flask_jwt_extended import get_jwt_identity [as 别名]
def post(self):
dbm = access.DBMan(LOST_CONFIG)
identity = get_jwt_identity()
user = dbm.get_user_by_id(identity)
if not user.has_role(roles.DESIGNER):
dbm.close_session()
return "You need to be {} in order to perform this request.".format(roles.DESIGNER), 401
else:
data = request.data
# quick and dirty here, data was binary but should be dictonary without using json.loads locally.
import json
data = json.loads(data)
group_id = None
for user_group in dbm.get_user_groups_by_user_id(identity):
if user_group.group.is_user_default:
group_id = user_group.group.idx
if group_id:
pipeline_service.start(dbm, data, identity, group_id)
dbm.close_session()
return "success"
else:
dbm.close_session()
return "default group for user {} not found.".format(identity), 400
示例4: get
# 需要导入模块: import flask_jwt_extended [as 别名]
# 或者: from flask_jwt_extended import get_jwt_identity [as 别名]
def get(self):
dbm = access.DBMan(LOST_CONFIG)
identity = get_jwt_identity()
user = dbm.get_user_by_id(identity)
if not user.has_role(roles.ANNOTATOR):
dbm.close_session()
return "You are not authorized.", 401
else:
group_ids = [g.idx for g in user.groups]
annotask_list = annotask_service.get_available_annotasks(dbm, group_ids, identity)
dbm.close_session()
import json
#with open('/code/backend/lost/api/annotask/test/annoTasks.json') as f:
# data = json.load(f)
#return data
return annotask_list
示例5: get
# 需要导入模块: import flask_jwt_extended [as 别名]
# 或者: from flask_jwt_extended import get_jwt_identity [as 别名]
def get(self):
dbm = access.DBMan(LOST_CONFIG)
identity = get_jwt_identity()
user = dbm.get_user_by_id(identity)
if not user.has_role(roles.DESIGNER):
dbm.close_session()
return "You are not authorized.", 401
else:
users = dbm.get_users()
for us in users:
for g in us.groups:
if g.is_user_default:
us.groups.remove(g)
dbm.close_session()
ulist = {'users':users}
return ulist
示例6: patch
# 需要导入模块: import flask_jwt_extended [as 别名]
# 或者: from flask_jwt_extended import get_jwt_identity [as 别名]
def patch(self):
args = update_user_parser.parse_args()
dbm = access.DBMan(LOST_CONFIG)
identity = get_jwt_identity()
user = dbm.get_user_by_id(identity)
if user:
user.email = args.get('email')
user.first_name = args.get('first_name')
user.last_name = args.get('last_name')
if args.get('password'):
user.set_password(args.get('password'))
dbm.save_obj(user)
dbm.close_session()
return 'success', 200
else:
dbm.close_session()
return "No user found.", 405
示例7: post
# 需要导入模块: import flask_jwt_extended [as 别名]
# 或者: from flask_jwt_extended import get_jwt_identity [as 别名]
def post(self):
dbm = access.DBMan(LOST_CONFIG)
identity = get_jwt_identity()
user = dbm.get_user_by_id(identity)
expires = datetime.timedelta(minutes=LOST_CONFIG.session_timeout)
expires_refresh = datetime.timedelta(minutes=LOST_CONFIG.session_timeout + 2)
if FLASK_DEBUG:
expires = datetime.timedelta(days=365)
expires_refresh = datetime.timedelta(days=366)
if user:
access_token = create_access_token(identity=user.idx, fresh=True, expires_delta=expires)
refresh_token = create_refresh_token(user.idx, expires_delta=expires_refresh)
ret = {
'token': access_token,
'refresh_token': refresh_token
}
dbm.close_session()
return ret, 200
dbm.close_session()
return {'message': 'Invalid user'}, 401
示例8: get
# 需要导入模块: import flask_jwt_extended [as 别名]
# 或者: from flask_jwt_extended import get_jwt_identity [as 别名]
def get(self):
dbm = access.DBMan(LOST_CONFIG)
identity = get_jwt_identity()
user = dbm.get_user_by_id(identity)
if not user.has_role(roles.ANNOTATOR):
dbm.close_session()
return "You need to be {} in order to perform this request.".format(roles.ANNOTATOR), 401
else:
last_sia_image_id = sia.get_last_image_id(dbm, identity)
if last_sia_image_id:
re = sia.get_next(dbm, identity, last_sia_image_id, DATA_URL)
else:
re = sia.get_next(dbm, identity, -1, DATA_URL)
dbm.close_session()
return re
示例9: patch
# 需要导入模块: import flask_jwt_extended [as 别名]
# 或者: from flask_jwt_extended import get_jwt_identity [as 别名]
def patch(self):
args = update_label_parser.parse_args()
dbm = access.DBMan(LOST_CONFIG)
identity = get_jwt_identity()
user = dbm.get_user_by_id(identity)
if not user.has_role(roles.DESIGNER):
dbm.close_session()
return "You are not authorized.", 401
else:
label = dbm.get_label_leaf(int(args.get('id')))
label.name = args.get('name')
label.description = args.get('description')
label.abbreviation = args.get('abbreviation')
label.external_id = args.get('external_id')
dbm.save_obj(label)
dbm.close_session()
return 'success'
示例10: post
# 需要导入模块: import flask_jwt_extended [as 别名]
# 或者: from flask_jwt_extended import get_jwt_identity [as 别名]
def post(self):
args = create_label_parser.parse_args()
dbm = access.DBMan(LOST_CONFIG)
identity = get_jwt_identity()
user = dbm.get_user_by_id(identity)
if not user.has_role(roles.DESIGNER):
dbm.close_session()
return "You are not authorized.", 401
else:
label = model.LabelLeaf(name=args.get('name'),abbreviation=args.get('abbreviation'), \
description=args.get('description'),external_id=args.get('external_id'),
is_root=args.get('is_root'))
if args.get('parent_leaf_id'):
label.parent_leaf_id = args.get('parent_leaf_id'),
dbm.save_obj(label)
dbm.close_session()
return "success"
示例11: put
# 需要导入模块: import flask_jwt_extended [as 别名]
# 或者: from flask_jwt_extended import get_jwt_identity [as 别名]
def put(self, post_id=None):
if not post_id:
abort(400)
post = Post.query.get(post_id)
if not post:
abort(404)
args = post_put_parser.parse_args(strict=True)
if get_jwt_identity() != post.user_id:
abort(403)
if args['title']:
post.title = args['title']
if args['text']:
post.text = args['text']
if args['tags']:
print("Tags %s" % args['tags'])
add_tags_to_post(post, args['tags'])
db.session.merge(post)
db.session.commit()
return {'id': post.id}, 201
开发者ID:PacktPublishing,项目名称:Mastering-Flask-Web-Development-Second-Edition,代码行数:22,代码来源:controllers.py
示例12: delete
# 需要导入模块: import flask_jwt_extended [as 别名]
# 或者: from flask_jwt_extended import get_jwt_identity [as 别名]
def delete(id):
try:
current_user_id = get_jwt_identity()
# User is not allowed to delete his own account
assert id != current_user_id, R['delete']['self']
# Fetch the user and destroy
user_to_destroy = User.get(id)
user_to_destroy.destroy()
except AssertionError as error_message:
content, status = {'msg': str(error_message)}, 403
except NoResultFound:
content, status = {'msg': R['not_found']}, 404
except Exception as e:
content, status = {'msg': G['internal_error'] + str(e)}, 500
else:
content, status = {'msg': R['delete']['success']}, 200
finally:
return content, status
示例13: spawn
# 需要导入模块: import flask_jwt_extended [as 别名]
# 或者: from flask_jwt_extended import get_jwt_identity [as 别名]
def spawn(id: TaskId) -> Tuple[Content, HttpStatusCode]:
try:
task = Task.get(id)
assert task.user_id == get_jwt_identity(), 'Not an owner'
except NoResultFound as e:
log.error(e)
content, status = {'msg': T['not_found']}, 404
except AssertionError:
content, status = {'msg': G['unpriviliged']}, 403
else:
content, status = business_spawn(id)
finally:
return content, status
# GET /tasks/{id}/terminate
示例14: resolve_me
# 需要导入模块: import flask_jwt_extended [as 别名]
# 或者: from flask_jwt_extended import get_jwt_identity [as 别名]
def resolve_me(self, info):
id = get_jwt_identity()
user = UserModel.query.filter_by(id=id).scalar()
if user:
return user
else:
raise GraphQLError("User is not found.")
示例15: get_current_user
# 需要导入模块: import flask_jwt_extended [as 别名]
# 或者: from flask_jwt_extended import get_jwt_identity [as 别名]
def get_current_user():
"""
Return person from its auth token (the one that does the request) as a
dictionary.
"""
return get_person_by_email(get_jwt_identity())