Ejemplo n.º 1
0
def get_user_data(token):
    for i, user in enumerate(LOGGED_IN_USERS):
        if token == user.token:
            user = database_handler.get_user(user.email)
            user[0]['password'] = ""
            return user[0]
    return False
Ejemplo n.º 2
0
def sign_up():
    data = request.get_json()
    email = data['email']
    password = data['password']
    first_name = data['first_name']
    family_name = data['family_name']
    gender = data['gender']
    country = data['country']
    city = data['city']

    if email and password and first_name and family_name and gender and country and city and len(
            password) > 7:
        # 1. Check if user exist
        user = database_handler.get_user(email)
        if not user:
            result = database_handler.save_user(email, password, first_name,
                                                family_name, gender, country,
                                                city)
            if result:
                user = create_sign_in_token(email)
                data = {'success': 'true', 'message': 'Successfully logged in'}
                response = app.response_class(
                    response=json.dumps(data),
                    status=201,
                    mimetype='application/json',
                    headers={'Authorization': user.token})
                return response
        else:
            return app.response_class(status=403)  # user exists

    return app.response_class(status=401)
Ejemplo n.º 3
0
def sign_in():
    data = request.get_json()
    email = data['email']
    password = data['password']
    # TODO: check if user is signed in
    if email and password:
        # 1. Get user information
        user = database_handler.get_user(email)
        if user:
            if password == user[0]['password']:
                for index, user in enumerate(LOGGED_IN_USERS):
                    if email == user.email:
                        response = app.response_class(
                            status=200,
                            mimetype='application/json',
                            headers={'Authorization': user.token})
                        return response

                user = create_sign_in_token(email)
                response = app.response_class(
                    status=200,
                    mimetype='application/json',
                    headers={'Authorization': user.token})
                return response
    return app.response_class(status=401)
Ejemplo n.º 4
0
def get_user_data_by_email():
    data = request.get_json()
    token = request.headers.get("Authorization")
    email = data['email']

    if get_user_data(token):
        result = database_handler.get_user(email)
        if result:
            result[0]['password'] = ""
            response = app.response_class(response=json.dumps(result[0]),
                                          status=200,
                                          mimetype='application/json')
            return response
        else:
            return app.response_class(status=500)  # no such user
    return app.response_class(status=401)