Beispiel #1
0
def sign_out():
    email = dh.email_from_token(request.get_json()['token'])
    if web_socket.get(email[0]):
        del web_socket[email[0]]
    message = sh.sign_out(request.get_json()['token'])
    update_charts("all", "users_online")
    return message
Beispiel #2
0
def get_user_messages_by_token(token):
    email = dh.email_from_token(token)
    messages = dh.get_messages(email[0])
    return json.dumps({
        "message": "Messages to the user",
        "data": messages
    }), 200
Beispiel #3
0
def change_password(token, old_pwd, new_pwd):
    email = dh.email_from_token(token)
    old_password = dh.get_pwd(email)
    if old_password[0] != old_pwd:
        return json.dumps({"message": "Old Password incorrect"}), 501
    dh.change_password(new_pwd, email[0])
    return json.dumps({"message": "Password changed"}), 200
Beispiel #4
0
def change_picture(token, img_type, picture):
    email_from = dh.email_from_token(token)
    picture_src = dh.change_picture(email_from[0], img_type, picture)
    return json.dumps({
        "message": "Profile picture changed",
        "data": picture_src
    }), 200
Beispiel #5
0
def get_user_data_by_email(email, token):
    token_email = dh.email_from_token(token)
    if token_email[0] is None:
        return json.dumps({"message": "User not logged in"}), 501
    if dh.user_exists(email) is None:
        return json.dumps({"message": "No such user"}), 501
    user_data = dh.get_user_data(email, True)
    return json.dumps({"message": "User data", "data": user_data}), 200
Beispiel #6
0
def sign_out():
    body = json.loads(request.data.decode("utf-8"))
    token = body['token']
    user = database_helper.email_from_token(token)
    database_helper.signout(token)
    del active_users[user['email']]
    _send_active_users()
    return _return_json_message(True, "Successfully signed out")
Beispiel #7
0
def get_messages_by_email():
    body = json.loads(request.data.decode("utf-8"))
    token = body['token']
    user = database_helper.email_from_token(token)
    if user == None:
        return _return_json_message(False, "User not signed in")
    result = database_helper.get_messages(body['email'])
    return _return_json_message(True, "Successfully found messages", result)
Beispiel #8
0
def get_user_data_by_token():
    body = json.loads(request.data.decode("utf-8"))
    token = body['token']
    user = database_helper.email_from_token(token)
    result = database_helper.find_user(user['email'])
    if result != None:
        return _return_json_message(True, "Successfully found user", result)
    else:
        return _return_json_message(False, "No such user")
Beispiel #9
0
def get_profile_picture(token):
    email_from = dh.email_from_token(token)
    picture_src = dh.get_profile_picture(email_from)
    if picture_src:
        return json.dumps({
            "message": "Profile picture changed",
            "data": picture_src[0]
        }), 200
    return json.dumps({"message": "No profile picture found"}), 501
Beispiel #10
0
def post_message():
    body = json.loads(request.data.decode("utf-8"))
    token = body['token']
    user = database_helper.email_from_token(token)
    if user == None:
        return _return_json_message(False, "User not signed in")
    database_helper.post_message(user['email'], body['email'], body['message'])
    _send_total_posts()
    return _return_json_message(True, "Successfully posted message")
Beispiel #11
0
def get_user_messages_by_email(email, token):
    token_email = dh.email_from_token(token)
    if token_email[0] is None:
        return json.dumps({"message": "User not logged in"}), 501
    messages = dh.get_messages(email)
    return json.dumps({
        "message": "Messages to the user",
        "data": messages
    }), 200
Beispiel #12
0
def get_user_data_by_email():
    body = json.loads(request.data.decode("utf-8"))
    token = body['token']
    if database_helper.email_from_token(token) == None:
        return _return_json_message(False, "User not signed in")
    email = body['email']
    result = database_helper.find_user(email)
    if result != None:
        return _return_json_message(True, "Successfully found user", result)
    else:
        return _return_json_message(False, "No such user")
Beispiel #13
0
def change_password():
    body = json.loads(request.data.decode("utf-8"))
    token = body['token']
    old_password = _password_hasher(body['oldPassword'])
    new_password = _password_hasher(body['newPassword'])
    user = database_helper.email_from_token(token)
    result = database_helper.find_user_with_password(user['email'],
                                                     old_password)
    if result != None:
        database_helper.update_password(user['email'], new_password)
        return _return_json_message(True, "Successfully changed password")
    else:
        return _return_json_message(False, "No such user")
Beispiel #14
0
def websocket():
    if request.environ.get('wsgi.websocket'):
        socket = request.environ['wsgi.websocket']
        token = socket.receive()
        user = database_helper.email_from_token(token)
        if active_users.get(user['email']) != None:
            if active_users[user['email']]['token'] != token:
                _send_message(active_users[user['email']]['socket'],
                              {"data": "sign_out"})
        active_users[user['email']] = {}
        active_users[user['email']]['token'] = token
        active_users[user['email']]['socket'] = socket
        _send_active_users()
        _send_total_posts()
        while True:
            socket.receive()
Beispiel #15
0
def post_video_message(token, email_to, video_type, video):
    email_from = dh.email_from_token(token)
    dh.add_video_message(email_from[0], email_to, video_type, video)
    return json.dumps({"message": "Message posted successfully"}), 200
Beispiel #16
0
def get_chart_data(token):
    email_to = dh.email_from_token(token)
    chart_data = dh.get_chart_data(email_to)
    return json.dumps({"message": "Chart Data", "data": chart_data}), 200
Beispiel #17
0
def get_user_data_by_token(token):
    email = dh.email_from_token(token)
    if dh.user_exists(email[0]) is None:
        return json.dumps({"message": "No such user"}), 501
    user_data = dh.get_user_data(email[0], False)
    return json.dumps({"message": "User data", "data": user_data}), 200