예제 #1
0
def signin():
    email = request.form["email"]
    password = request.form["password"]
    data = database_helper.get_password(email)
    if data is None:
        return json.dumps({
            'success': False,
            'message': 'The email or password is incorrect'
        })

    if not bcrypt.check_password_hash(data, password):
        return json.dumps({
            'success': False,
            'message': 'The email or password is incorrect'
        })

    token = database_helper.get_token(email)
    if token is not None:
        database_helper.remove_token(token)
        if (token in wslist):
            try:
                wslist[token].send(
                    json.dumps({
                        'messageType': 'logout',
                        'message': "You just got logged out!"
                    }))
            except WebSocketError:
                pass
            wslist[token].close()
            wslist.pop(token)

    token = os.urandom(32)
    token = base64.b64encode(token).decode('utf-8)')
    database_helper.insert_token(email, token)
    # When someone logs in, we send a message to all logged in users to update their 'logged in users' count
    for user in wslist:
        send_message(
            wslist[user],
            json.dumps({
                'messageType':
                'loggedInStats',
                'message': [
                    database_helper.getLoggedInUsersCount(),
                    database_helper.getAllUserCount()
                ]
            }))
    return json.dumps({
        'success': True,
        'message': 'Successfully logged in',
        'data': token
    })
예제 #2
0
def sign_out():
    token = request.json["token"]
    if database_helper.find_inlogged(token) is not None:
        database_helper.remove_token(token)
        #not sure if it's correct to do json.dumps
        return json.dumps({
            "success": True,
            "message": "Successfully signed out."
        })
    else:
        return json.dumps({
            "success": False,
            "message": "You are not signed in."
        })
예제 #3
0
def signout():
    email = request.form["email"]
    time_stamp = request.form["time"]
    token = database_helper.get_token(email)
    blob = email

    if check_hash(blob, email, request.form["hash"], time_stamp):
        return json.dumps({
            'success':
            False,
            'message':
            'You are trying to hack a user. You should be ashamed of yourself!'
        })

    if token:
        database_helper.remove_token(token)
        if token in wslist:
            wslist.pop(token)

        # When someone logs out, we send a message to all logged in users to update their 'logged in users' count
        for user in wslist:
            send_message(
                wslist[user],
                json.dumps({
                    'messageType':
                    'loggedInStats',
                    'message': [
                        database_helper.getLoggedInUsersCount(),
                        database_helper.getAllUserCount()
                    ]
                }))
        return json.dumps({
            'success': True,
            'message': 'The user was logged out'
        })
    else:
        return json.dumps({
            'success': False,
            'message': 'User is not logged in'
        })
예제 #4
0
def sign_out():
    if request.method == 'POST' :
        token = request.form['token']
        print(database_helper.get_username_from_token(token))
        if database_helper.get_username_from_token(token) is False:
            answer = {"success" : "False", "message" : "No such user logged in" , "data": "" }
            return json.dumps(answer), 200
        else: 
            if database_helper.remove_token(token):
                answer = {"success" : "True", "message" : "Sucessfully signed out !" , "data": "" }
                return json.dumps(answer), 200
            else : 
                answer = {"success" : "False", "message" : "Unable to sign out !" , "data": "" }
                return json.dumps(answer), 200
예제 #5
0
def sign_out():
    if request.method == 'POST':
        token = request.form['token']
        i = 0
        for user in connection:
            if database_helper.get_email(token) == user[1]:
                del connection[i]
                print(connection)
            i = i + 1
        if database_helper.remove_token(token):
            return json.dumps({
                'success': True,
                'message': 'signed out successfully!'
            })
        return json.dumps({
            'success': False,
            'message': '''token doesn't exist'''
        })