Ejemplo n.º 1
0
def sign_out():
    token = request.headers.get("token")
    if database_helper.get_loggedinuser(token) != None:
        email = database_helper.get_loggedinuser(token)['email']
        database_helper.delete_token(token)
        del activeSessions[email]
        return jsonify({"success": True, "msg": "User succesfully signed out"})
    else:
        return jsonify({"success": False, "msg": "User is not signed in"})
Ejemplo n.º 2
0
def change_password():
    data = request.get_json()
    token = request.headers.get("token")
    if database_helper.get_loggedinuser(token) != None:
        email = database_helper.get_loggedinuser(token)['email']
        if database_helper.get_user(email)['password'] == data['oldpassword']:
            database_helper.change_password(email, data['newpassword'])
            return jsonify({"success": True, "msg": "Password changed"})
        else:
            return jsonify({"success": False, "msg": "Wrong password"})
    else:
        return jsonify({"success": False, "msg": "User is not signed in"})
Ejemplo n.º 3
0
def post_message():
    data = request.get_json()
    token = request.headers.get("token")
    fromemail = database_helper.get_loggedinuser(token)['email']
    if database_helper.get_user(fromemail) != None:
        if data['toemail'] == None:
            data['toemail'] = fromemail
        if database_helper.get_user(data['toemail']) != None:
            database_helper.save_message(data['message'], fromemail,
                                         data['toemail'])
            return {"success": True, "msg": "Message posted"}
        else:
            return jsonify({
                "success": False,
                "msg": "Recipient user doesn't exist"
            })
    else:
        return jsonify({"success": False, "msg": "User is not signed in"})
Ejemplo n.º 4
0
def api():
    print(activeSessions)
    if request.environ.get('wsgi.websocket'):
        ws = request.environ['wsgi.websocket']
        token = ws.receive()
        email = database_helper.get_loggedinuser(token)['email']
        if email in activeSessions:
            #activeSessions[email].send(json.dumps("signout"))
            database_helper.delete_token(activeSessions[email])
            del activeSessions[email]
            activeSessions[email] = token
            print("active websocket replaced")
            print(activeSessions)
        else:
            activeSessions[email] = token
            print("new active websocket added")
            print(activeSessions)
        while True:
            message = ws.receive()
            print(message)
            ws.send(message)
        return ""
Ejemplo n.º 5
0
def get_user_messages_by_email(email):
    token = request.headers.get("token")
    if database_helper.get_loggedinuser(token) != None:
        if database_helper.get_user(email) != None:
            messages = database_helper.get_usermessages(email)
            if messages != None:
                result = [message for message in messages]
                return jsonify({
                    "success": True,
                    "msg": "User messages retrieved",
                    "data": result
                })
            else:
                return jsonify({
                    "success": True,
                    "msg": "User messages retrieved",
                    "data": None
                })
        else:
            return jsonify({"success": False, "msg": "User doesn't exist"})
    else:
        return jsonify({"success": False, "msg": "User is not signed in"})
Ejemplo n.º 6
0
def get_user_data_by_email(email):
    token = request.headers.get("token")
    if database_helper.get_loggedinuser(token) != None:
        if database_helper.get_user(email) != None:
            data = database_helper.get_user(email)
            result = {
                "email": data['email'],
                "firstname": data['firstname'],
                "familyname": data['familyname'],
                "gender": data['gender'],
                "city": data['city'],
                "country": data['country']
            }
            return {
                "success": True,
                "msg": "User data retrieved",
                "data": result
            }
        else:
            return jsonify({"success": False, "msg": "User doesn't exist"})
    else:
        return jsonify({"success": False, "msg": "User is not signed in"})
Ejemplo n.º 7
0
def get_user_messages_by_token():
    token = request.headers.get("token")
    email = database_helper.get_loggedinuser(token)['email']
    return get_user_messages_by_email(email)