Esempio n. 1
0
def refresh():
  current_user = get_jwt_identity()
  if not User.exists(current_user["email"]):
      return ERROR_USER_NOT_EXISTS.get_response()
  access_token = create_access_token(identity=dict(email=current_user["email"]))
  TokenBlacklist.add_token_to_database(access_token, app.config["JWT_IDENTITY_CLAIM"])
  return {"access_token": access_token}
Esempio n. 2
0
def verify_email(**kwargs):
  email = kwargs["email"]
  if not User.exists(email):
    return ERROR_USER_NOT_EXISTS.get_response()

  u = User.get_info(email)
  if u.token != kwargs["token"]:
    return ERROR_SIGNUP_VERIFICATION.get_response()
  else:
    u.confirmed = True
    db.session.commit()
    return SUCCESS_VERIFICATION.get_response()
Esempio n. 3
0
def signup(**kwargs):
  email = kwargs.get('email', None)
  password = kwargs.get('password', None)
  if User.exists(email):
    return ERROR_USER_EMAIL_EXISTS.get_response()
  user_info = User(**kwargs)
  db.session.add(user_info)
  db.session.commit()
  try:
    email_sender.sendmail(user_info.email, SignupCheck(user_info))
  except Exception as e:
    return ERROR_SEND_MAIL.get_response()

  return SUCCESS_SIGNUP.get_response()
Esempio n. 4
0
def signin(**kwargs):
  email = kwargs.get('email', None)
  password = kwargs.get('password', None)
  if not email:
    return ERROR_NULL_EMAIL.get_response()
  if not password:
    return ERROR_NULL_PASSWORD.get_response()
  if not User.exists(email):
    return ERROR_USER_EMAIL_NOT_EXISTS.get_response()
  u = User.get_info(email)
  if not u.verify_password(password):
    return ERROR_VERIFY_EMAIL_PASSWORD.get_response()
  if not u.confirmed:
    return ERROR_NOT_VALIDATED_ACCOUNT.get_response()
  return u.to_dict()