Пример #1
0
def verify_reset_password_token(token):
  if token is None:
    raise InvalidUsage.unknown_error()
  user = get_user_from_token(token)
  if user is not None:
    auth = AuthModel.create(identity=user)
    return TokenizedUser(user, auth)
  raise InvalidUsage.user_not_found()
Пример #2
0
def delete_session(id):
    session = Session.first(id=id)
    if session is None:
        raise InvalidUsage.session_not_found()
    try:
        session.delete(id)
    except IntegrityError:
        db.session.rollback()
        raise InvalidUsage.unknown_error()
    return jsonify(message='Session has been deleted')
Пример #3
0
def reset_password(password):
  user = current_user
  try:
    user.password = password
    db.session.commit()
  except IntegrityError:
    db.session.rollback()
    raise InvalidUsage.unknown_error()
  return jsonify({
    'message': f'Password has been reset for {user.username}'
  })
Пример #4
0
def save_session(words, chars, accuracy):
    user = current_user
    try:
        session = Session.create(words=words,
                                 chars=chars,
                                 accuracy=accuracy,
                                 user_id=user.id)
    except IntegrityError:
        db.session.rollback()
        raise InvalidUsage.unknown_error()
    return session