Beispiel #1
0
def user_change_password():
    data = request.get_json()
    old_pass = data['old']
    new_pass = data['new']

    if 'Authorization' in request.headers:
        a_token = request.headers.get('Authorization')

    if (not database_helper.user_logged_in(a_token)):
        return create_response(False, 'You are not logged in')
    elif (len(new_pass) < 8):
        return create_response(False, 'Too short password')
    elif (len(new_pass) > 30):
        return create_response(False, 'Too long password')

    stored_pass = (database_helper.get_user_password(
        database_helper.token_to_email(a_token)))
    if (stored_pass != old_pass):
        return create_response(False, 'Wrong password')
    else:
        email = database_helper.token_to_email(a_token)
        result = database_helper.set_user_password(new_pass, email)
        if (result):
            return create_response(True, 'Password changed')
    return create_response(False, 'Could not change password')
Beispiel #2
0
def user_logged_in():
    data = request.get_json()

    if 'Authorization' in request.headers:
        a_token = request.headers.get('Authorization')

    if database_helper.user_logged_in(a_token):
        return create_response(True, 'User is logged in')
    return create_response(False, 'User is not logged in')
Beispiel #3
0
def get_user_data_by_token():
    #data = request.get_json()

    if 'Authorization' in request.headers:
        a_token = request.headers.get('Authorization')

    email = database_helper.token_to_email(a_token)

    if (not database_helper.user_logged_in(a_token)):
        return create_response(False, 'You are not logged in')
    elif (database_helper.user_exists(email) == False):
        return create_response(False, 'No such user')

    result = database_helper.get_user_data(email)
    return create_response(True, "User data retrieved", result)
Beispiel #4
0
def user_get_messages_token():
    data = request.get_json()

    if 'Authorization' in request.headers:
        a_token = request.headers.get('Authorization')

    email = database_helper.token_to_email(a_token)
    print(email)

    if (not database_helper.user_logged_in(a_token)):
        return create_response(False, 'You are not logged in')
    elif (not database_helper.user_exists(email)):
        return create_response(False, "No such user")
    else:
        data = database_helper.get_messages_by_email(a_token, email)
        if (data is not False):
            return create_response(True, "User messages retrieved", data)
    return create_response(False, "Something went wrong")
Beispiel #5
0
def get_user_data_by_email():
    data = request.get_json()
    email = data['email']

    if 'Authorization' in request.headers:
        a_token = request.headers.get('Authorization')

    if (not database_helper.user_logged_in(a_token)):
        return create_response(False, 'You are not logged in')
    elif (database_helper.user_exists(email) == False):
        return create_response(False, 'No such user')

    database_helper.add_view(email)
    result = database_helper.get_user_data(email)
    #print(pageviews[email])
    #pageviews[email] = pageviews[email] + 1

    return create_response(True, "User data retrieved", result)
Beispiel #6
0
def api():
    if request.environ.get('wsgi.websocket'):
        ws = request.environ['wsgi.websocket']
        while True:
            message = ws.receive()
            loadMessage = json.loads(message)
            email = database_helper.token_to_email(loadMessage['token'])
            print("status", message)
            print(database_helper.user_logged_in(message))
            if (email != False):  #titta så rätt mail för token existerar
                users[email] = ws
                #använd users för att sedan jämföra innan database.login-grejen

            print("hfeofwjw")
            print(users[email])
            #else:
            #    print("OMEGALUL")
    return
Beispiel #7
0
def user_post_message():
    data = request.get_json()
    message = data['message']
    email = data['email']

    if 'Authorization' in request.headers:
        a_token = request.headers.get('Authorization')

    sender = database_helper.token_to_email(a_token)

    if (not database_helper.user_logged_in(a_token)):
        return create_response(False, 'You are not logged in')
    elif (not database_helper.user_exists(email)):
        return create_response(False, "No such user")
    else:
        result = database_helper.post_message(email, sender, message)
        if (result):
            return create_response(True, "Message posted")
    return create_response(False, "Something went wrong")