def reset_password():
    response = model_user.reset_password(request.headers.get('key'))
    if response is None:
        _(400, 'No user associated with the provided key', stop=True)
    if response is False:
        _(500, 'Something wrong resetting the password', stop=True)
    return jsonify({'status': 200, 'password': response})
def activate():
    response = model_user.activate(request.headers.get('key'))
    if response is None:
        _(400, 'No user associated to the provided email', stop=True)
    if response is False:
        _(401, 'The provided key is invalid', stop=True)
    _(200, 'The email has ben activated', stop=True)
예제 #3
0
    def put():
        # parser.add_argument('uid', type=int)
        parser.add_argument('email', type=str)
        parser.add_argument('password', type=str)
        parser.add_argument('name', type=str)
        parser.add_argument('username', type=str)
        args = parser.parse_args()

        if args['username'] is None or args['password'] is None or args['name'] is None or args['email'] is None:
            return jsonify({'required_fields': ['username', 'password', 'name', 'email']})

        teste_cliente = User(args['name'], args['email'], args['username'])
        teste_cliente.hash_password(args['password'])
        db.session.add(teste_cliente)
        db.session.commit()
        return {'user': teste_cliente.id}
def logout():
    m_user = json.loads(authorize().data.decode('utf-8'))
    if m_user is None:
        _(401, 'No user associated to the provided parameters', stop=True)
    response = model_user.logout(m_user['id'])
    if response is False:
        _(500, 'Something wrong logging out the user', stop=True)
    _(200, 'The user has been logged out', stop=True)
예제 #5
0
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
def set_stripe_id():
    response = model_user.set_stripe_id(request.headers.get('email'),
                                        request.headers.get('token'),
                                        request.headers.get('stripe_id'))
    if response is None:
        _(401, 'The provided token is invalid or expired', stop=True)
    if response is False:
        _(401, 'stripe_id cannot be updated', stop=True)
    _(200, 'Stripe ID has been updated', stop=True)
def authenticate():
    response = model_user.authenticate(request.headers.get('email'),
                                       request.headers.get('password'))
    if response is None or response is False:
        _(401, 'Wrong login', stop=True)
    return jsonify({
        'status': 200,
        'expiration_time': response['expiration_time'],
        'token': response['token']
    })
def authorize():
    response = model_user.verify_auth_token(request.headers.get('email'),
                                            request.headers.get('token'))
    if response is False or response is None:
        _(401, 'The provided token is invalid or expired', stop=True)
    return jsonify({
        'status': 200,
        'id': response['id'],
        'email': response['email']
    })
def ott_generate():
    response = model_user.ott_generate(request.headers.get('email'),
                                       request.headers.get('token'))
    if response is None or response is False:
        _(401, 'The provided token is invalid or expired', stop=True)
    return jsonify({
        'status': 200,
        'expiration_time': response['expiration_time'],
        'token': response['token']
    })
예제 #10
0
 def insertUser(self, data):
     try:
         new_user = User(data['name'], data['birthday'], data['email'],
                         data['password'], data['status'])
         db.session.add(new_user)
         db.session.commit()
     except Exception as e:
         print(f'ERROR IN HELPER: {e}')
         return False
     return True
def update_email():
    m_user = json.loads(authorize().data.decode('utf-8'))
    response = model_user.update_email_by_id(m_user['id'],
                                             request.headers.get('new_email'))
    if response is None:
        _(400, 'No user associated to the provided parameters', stop=True)
    if response is False:
        _(500, 'Something wrong saving your data', stop=True)
    _(200,
      'The email has been updated and the account needs to be activated again',
      stop=True)
def token_refresh():
    response = model_user.refresh_token(request.headers.get('email'),
                                        request.headers.get('token'))
    if response is False:
        _(401, 'The provided token is invalid or expired', stop=True)
    if response is None:
        _(500, 'Something wrong refreshing the token', stop=True)
    return jsonify({
        'status': 200,
        'expiration_time': response['expiration_time'],
        'token': response['token']
    })
예제 #13
0
 def default():
     if request.headers.get('email') is None or not request.headers.get(
             'email'):
         _(412, 'The parameter email is required', stop=True)
     if request.headers.get('password') is None or not request.headers.get(
             'password'):
         _(412, 'The parameter password is required', stop=True)
     if model_user.user_exists_by_email(request.headers.get('email')):
         _(409, 'The provided email is invalid or unavailable', stop=True)
     if service_email_validate(request.headers.get('email')) is None:
         _(403, 'The required service email is unreachable', stop=True)
     if service_email_validate(request.headers.get('email')) is False:
         _(412, 'The provided email is invalid', stop=True)
     return f()
예제 #14
0
 def default():
     if request.headers.get('old_email') is None or not request.headers.get(
             'old_email'):
         _(412, 'The parameter old_email is required', stop=True)
     if service_email_validate(request.headers.get('old_email')) is None:
         _(403, 'The required service old_email is unreachable', stop=True)
     if service_email_validate(request.headers.get('old_email')) is False:
         _(412, 'The provided old_email is invalid', stop=True)
     if request.headers.get('new_email') is None or not request.headers.get(
             'new_email'):
         _(412, 'The parameter new_email is required', stop=True)
     if service_email_validate(request.headers.get('new_email')) is None:
         _(403, 'The required service new_email is unreachable', stop=True)
     if service_email_validate(request.headers.get('new_email')) is False:
         _(412, 'The provided new_email is invalid', stop=True)
     if model_user.find_by_email(request.headers.get('old_email')) is None:
         _(412, 'The provided new_email cannot be used', stop=True)
     return f()
def signup():
    response = model_user.signup(request.headers.get('email'),
                                 request.headers.get('password'))
    if response is False:
        _(500, 'Something wrong creating the account', stop=True)
    return jsonify({'status': 200, 'key': response})
def is_valid():
    response = model_user.is_valid(request.headers.get('email'))
    if response is False:
        _(400, 'No user associated to the provided parameters', stop=True)
    return jsonify({'status': 200, 'key': response})