Пример #1
0
def sign_out():
    token = get_param_or_default("token")
    if db.is_connected(token):
        db.logout_user(token)
        success(SUC_USER_LOGGED_OUT)
    else:
        err(ERR_USER_NOT_CONNECTED)
    return json.dumps(output)
Пример #2
0
def remove_user():
    token = get_param_or_default("token")
    if db.is_connected(token):
        email = db.get_email(token)[0]
        db.logout_user(token)
        db.remove_user(email)
        success(SUC_USER_DELETED)
    else:
        err(ERR_USER_NOT_CONNECTED)
    return json.dumps(output)
Пример #3
0
def sign_out():
	token = request.form["token"]
	
	if database_helper.logout_user(token) is None:
		return jsonify(success = True, message = "User successfully logged out")
	else:
		return jsonify(success = False, message = "User not logged in")
Пример #4
0
def sign_out():
    """Sign out
        Signs out currently logged in user
    """
    hashed_token = request.headers.get('token')

    data = request.get_json()
    email = data['email']
    token = database_helper.get_token_from_email(email)
    url = '/sign_out'

    server_hash = sha256((token[0] + email + url).encode('utf-8')).hexdigest()
    print('SIGNOUT: server_hash is:', server_hash, ' and hashed_token is: ',
          hashed_token)
    print('signing out token: ', token[0])
    user = database_helper.get_email_from_token(token[0])
    result = database_helper.logout_user(token[0])
    if (result == True) and server_hash == hashed_token:
        print('sockets before sign out ', sockets)
        print('user[0] before sign out ', user[0])
        print('sockets[user[0]] before sign out ', sockets[user[0]])
        print('deleting: ', sockets[user[0]])
        del sockets[user[0]]
        push_websocket_active_users()

        res = jsonify({'success': True, 'message': 'Signed out!'})
        return res
    else:
        res = jsonify({'success': False, 'message': 'Something went wrong!'})
        return res
Пример #5
0
def logout_user():
    data = request.get_json()
    email = data['email']

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

    ret = database_helper.logout_user(a_token, email)
    if (ret):
        return create_response(True, "User logged out")
    return create_response(False, "Could not log out user")
Пример #6
0
def sign_in():
    data = request.get_json()
    email = str(data['email'])
    passw = data['password']

    #print("-----------------------------")
    #print(email)    print("hejsan")
    #print(passw)
    token = database_helper.get_token(email)

    #if(email in users):
    #users[email].send("logout")
    #if(token is not None and email in users):
    #    users[email].send("logout")
    #ret = database_helper.logout_user(token, email)

    #print("users: ", users)
    if (email in users):
        #users[email].close()
        #database_helper.logout_user(token)
        database_helper.logout_user(token, email)
        print(json.dumps({'msg': "logout"}))
        users[email].send(json.dumps({"msg": "logout"}))
        print(json.dumps({'msg': "logout"}))
        #users[email].send("logout")
        del users[email]

    #generate token
    letters = 'abcdefghiklmnopqrstuvwwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
    token = ''

    for i in range(36):
        index = randint(0, len(letters) - 1)
        token += letters[index]

    #try to login user

    result = database_helper.login_user(email, passw, token)
    if (result):
        return create_response(True, 'Successfully signed in', token)
    return create_response(False, 'Wrong username or password', token)
Пример #7
0
def sign_out():
	token = request.form["token"]
	
	#print("LOG OUT")
	
	# Check if online
	if database_helper.is_user_online(token) != True:
		return jsonify(success = False, message = "You are not logged in")
	
	if database_helper.logout_user(token) is None:
		return jsonify(success = True, message = "User successfully logged out")
	else:
		return jsonify(success = False, message = "User not logged in")
Пример #8
0
def sign_out():
    token = request.form["token"]

    #print("LOG OUT")

    # Check if online
    if database_helper.is_user_online(token) != True:
        return jsonify(success=False, message="You are not logged in")

    if database_helper.logout_user(token) is None:
        return jsonify(success=True, message="User successfully logged out")
    else:
        return jsonify(success=False, message="User not logged in")
Пример #9
0
def sign_out():
    """Sign out
	Signs out currently logged in user
    """
    token = request.headers.get('token')
    print(token)
    result = database_helper.logout_user(token)

    if (result == True):
        res = jsonify({'success': True, 'message': 'Signed out!'})
        return res
    else:
        res = jsonify({'success': False, 'message': 'Something went wrong!'})
        return res