本文整理汇总了Python中models.User.verify_auth_token方法的典型用法代码示例。如果您正苦于以下问题:Python User.verify_auth_token方法的具体用法?Python User.verify_auth_token怎么用?Python User.verify_auth_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User
的用法示例。
在下文中一共展示了User.verify_auth_token方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mutate
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import verify_auth_token [as 别名]
def mutate(self, info, userToken):
query = User.get_query(info)
if not userToken or not UserModel.verify_auth_token(userToken):
raise Exception('Your session has expired!')
id = UserModel.verify_auth_token(userToken)
user = query.filter(UserModel.id == id).first()
ok = True
return VerifyUserToken(User=user, token=userToken, ok=ok)
示例2: api_bookings
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import verify_auth_token [as 别名]
def api_bookings():
""" Creates the booking for user on selected hotel;
Returns the list of bookings for the user.
"""
if request.method == "POST":
errors = {}
if not request.json:
abort(400)
# Validate required fields.
for field in [
"hotel_id",
"check_in",
"check_out",
"room_preference",
"smoking_preference",
"credit_card_number",
"credit_card_name",
"credit_card_expiry",
]:
if not request.json.get(field):
errors[field] = "This field is required"
# Validate field value
if not ("hotel_id" not in errors and Hotel.query.filter_by(id=request.json["hotel_id"])):
errors["hotel_id"] = "No hotels found with the given id"
if not ("check_in" not in errors and validate_date(request.json["check_in"])):
errors["check_in"] = "Incorrect data format, should be YYYY-MM-DD"
if not ("check_out" not in errors and validate_date(request.json["check_out"])):
errors["check_out"] = "Incorrect data format, should be YYYY-MM-DD"
if not ("credit_card_expiry" not in errors and validate_date(request.json["credit_card_expiry"])):
errors["credit_card_expiry"] = "Incorrect data format, should be YYYY-MM-DD"
if not ("room_preference" not in errors and request.json["room_preference"] in ["1", "2", "3"]):
errors["room_preference"] = "Select a value between 1 to 3"
if not ("smoking_preference" not in errors and isinstance(request.json["smoking_preference"], bool)):
errors["smoking_preference"] = "Value should be either true or false"
if not ("credit_card_number" not in errors and validate_credit_card_number(request.json["credit_card_number"])):
errors["credit_card_number"] = "Invalid credit card number"
if errors:
return make_response(jsonify({"error": errors}), 400)
booking = Booking(
request.json["check_in"],
request.json["check_out"],
request.json["hotel_id"],
request.json["room_preference"],
request.json["smoking_preference"],
request.json["credit_card_number"],
request.json["credit_card_name"],
request.json["credit_card_expiry"],
request.json["user_id"],
)
booking.add(booking)
return make_response(jsonify({"booking_id": booking.id}), 201)
else:
token = request.headers["Authorization"]
user = User.verify_auth_token(token)
bookings = Booking.query.filter_by(user_id=user.id).all()
return json.dumps(Booking.serialize_list(bookings))
示例3: verify_password
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import verify_auth_token [as 别名]
def verify_password(username_or_token, password):
# first try to authenticate by token
if password == "facebook":
auth = fb.get_session(token=username_or_token)
resp = auth.get('/me')
if resp.status_code == 200:
fb_user = resp.json()
# user = User.query.filter_by(email=fb_user.get('email')).first()
birthday = fb_user['birthday'][6:10] + fb_user['birthday'][0:2] + fb_user['birthday'][3:5]
user = User.get_or_create(fb_user['email'], fb_user['name'], fb_user['id'], birthday)
else:
return False
else:
user = User.verify_auth_token(username_or_token)
if not user:
# try to authenticate with username/password
user = User.query.filter_by(email = username_or_token).first()
if not user:
return False
if user.password == None:
return False
if not user.verify_password(password):
return False
g.user = user
return True
示例4: profile
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import verify_auth_token [as 别名]
def profile(request, user_id):
was_limited = getattr(request, 'limited', False)
if was_limited:
return JsonResponse(
{
'status': 'you hit the rate limit!'
}
)
else:
token = request.GET.get('token')
user_id_login = User.verify_auth_token(token)
if user_id_login:
user = User.objects.filter(id=user_id).first()
return JsonResponse(
{
'object':
{
'username': user.username,
'picture': str(user.picture),
'email': user.email
}
}
)
else:
return HttpResponseForbidden('invalid token')
示例5: getUserWithToken
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import verify_auth_token [as 别名]
def getUserWithToken(session, token):
user_id = User.verify_auth_token(token)
if user_id:
user = getUserById(session, user_id)
return user
else:
return None
示例6: decorated
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import verify_auth_token [as 别名]
def decorated(*args, **kwargs):
token = request.headers.get("Authorization")
if token:
user = User.verify_auth_token(token)
if not user:
return make_response(jsonify({"error": "Unauthorized access"}), 403)
return f(*args, **kwargs)
return make_response(jsonify({"error": "Unauthorized access"}), 403)
示例7: verify_password
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import verify_auth_token [as 别名]
def verify_password(username_or_token, password):
user = User.verify_auth_token(username_or_token)
if not user:
user = User.query.filter_by(username = username_or_token).first()
if not user or not user.verify_password(password):
return False
g.user = user
return True
示例8: api_change_password
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import verify_auth_token [as 别名]
def api_change_password():
""" Changes the password of the user. """
password = request.json.get("password")
token = request.headers["Authorization"]
user = User.verify_auth_token(token)
user.password = generate_password_hash(password)
user.update()
return jsonify({"user": user.id})
示例9: proposals
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import verify_auth_token [as 别名]
def proposals(request):
was_limited = getattr(request, 'limited', False)
if was_limited:
return JsonResponse(
{
'status': 'you hit the rate limit!'
}
)
else:
token = get_token(request)
user_id_login = User.verify_auth_token(token)
if user_id_login:
if request.method == 'GET':
all_request = Request.objects.filter(user_id=user_id_login)
request_id = []
for r in all_request:
request_id.append(r.id)
all_proposal = Proposal.objects.filter(request_id in request_id)
data = []
for proposal in all_proposal:
item = {
'id': proposal.id,
'user_proposed_to': proposal.user_proposed_to,
'user-proposed_from': proposal.user_proposed_from,
'request_id': proposal.request_id.id,
'filled': proposal.filled
}
data.append(item)
return JsonResponse(
{
'objects': data
}
)
elif request.method == 'POST':
request_id = request.POST.get('request_id')
user_from = Request.objects.filter(id=request_id).first().user_id
user_to = user_id_login
if user_from == user_to:
return HttpResponseForbidden('the two users are same')
else:
proposal = Proposal(user_proposed_to=user_to, user_proposed_from=user_from, request_id=request_id)
proposal.save()
return JsonResponse(
{
'status': 'proposal created successfully',
'object':
{
'id': proposal.id,
'user_proposed_to': proposal.user_proposed_to,
'user-proposed_from': proposal.user_proposed_from,
'request_id': proposal.request_id.id,
'filled': proposal.filled
}
}
)
else:
return HttpResponseForbidden('invalid token')
示例10: verify_password
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import verify_auth_token [as 别名]
def verify_password(email_or_token, psw):
# verify email or token
user = User.verify_auth_token(email_or_token)
if not user:
user = User.objects(email=email_or_token).first()
if not user or not user.verify_password(psw):
return False
g.user = user
return True
示例11: verify_password
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import verify_auth_token [as 别名]
def verify_password(username_or_token, password):
# first try to authenticate by token
user = User.verify_auth_token(username_or_token, api.app.config["SECRET_KEY"])
if not user:
# try to authenticate with username/password
user = User.query.filter_by(username = username_or_token).first()
if not user or not user.verify_password(password, api.app.config["SECRET_KEY"]):
return False
g.user = user
return True
示例12: verify_password
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import verify_auth_token [as 别名]
def verify_password(username_or_token, password):
user_id = User.verify_auth_token(username_or_token)
if user_id:
user = session.query(User).filter_by(id=user_id).first()
else:
user = session.query(User).filter_by(username=username_or_token).first()
if not user:
return False
g.user = user
return True
示例13: verify_password
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import verify_auth_token [as 别名]
def verify_password(username_or_token, password):
# first try to authenticate by token
user = User.verify_auth_token(username_or_token)
if not user:
# try to authenticate with userd/password
user = User.query.filter_by(username=username_or_token).first()
if not user or not user.verify_password(password):
return False
g.user = user
return True
示例14: verify_password
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import verify_auth_token [as 别名]
def verify_password(username_or_token, password):
#Try to see if it's a token first
user_id = User.verify_auth_token(username_or_token)
if user_id:
user = session.query(User).filter_by(id = user_id).one()
else:
user = session.query(User).filter_by(username = username_or_token).first()
if not user or not user.verify_password(password):
return False
g.user = user
return True
示例15: verify_password
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import verify_auth_token [as 别名]
def verify_password(facebook_id_or_token, password):
from models import User
# first try to authenticate by token
user = User.verify_auth_token(facebook_id_or_token)
if not user:
# try to authenticate with username/password
user = User.query.filter_by(facebook_id=facebook_id_or_token).first()
if not user or not user.verify_password(password):
return False
g.user = user
return True