def login(username, password):
"""
Authenticates a user.
"""
# Read in submitted username and password
validate(user_login_schema, {
"username": username,
"password": password
})
user = safe_fail(api.user.get_user, name=username)
if user is None:
raise WebException("Incorrect username.")
if user.get("disabled", False):
raise WebException("This account has been disabled.")
if not user["verified"]:
raise WebException("This account has not been verified yet.")
if confirm_password(password, user['password_hash']):
if not user["verified"]:
try:
api.email.send_user_verification_email(username)
raise WebException("This account is not verified. An additional email has been sent to {}.".format(user["email"]))
except InternalException as e:
raise WebException("You have hit the maximum number of verification emails. Please contact support.")
if debug_disable_general_login:
if session.get('debugaccount', False):
raise WebException("Correct credentials! But the game has not started yet...")
if user['uid'] is not None:
session['uid'] = user['uid']
session.permanent = True
else:
raise WebException("Login Error")
else:
raise WebException("Incorrect password")
评论列表
文章目录