Example #1
0
def sign_out():
    token = request.headers["Authorization"]
    if database_helper.get_email_from_token(token):
        database_helper.sign_out(token)
        return {"success": True, "message": "Successfully signed out."}, 200
    else:
        return {"success": False, "message": "You are not signed in."}, 404
Example #2
0
def sign_out():
    token = request.headers.get('token')
    print(token)
    status = database_helper.sign_out(token)
    if (status["success"]):
        return jsonify({"success": True, "message": "Successfully signed out."})
    else:
        return jsonify({"success": False, "message": "You are not signed in."})
Example #3
0
def sign_out():
    token1 = request.form.get('token')
    tokreset = 'null'
    signed = dh.sign_out(tokreset,token1)
    if signed == "signout":
        return json.dumps({"success": "true", "message":"Successfully signed out."})
    else:
        return json.dumps({"success": "false", "message":"You are not signed in."})
def sign_out():
    data = request.get_json()
    token = request.headers.get('token')
    if token and database_helper.check_token(token):
        result = database_helper.sign_out(token)
        if result == True:
            return json.dumps({"success": "true","message":"Successfully signed out."}), 200
        else:
            return json.dumps({"success": "false", "message": "Something went wrong!"}), 500
    else:
        return json.dumps({"success": "false", "message": "Something went wrong!"}), 400
def sign_out():
    data = request.get_json()
    token = data['token']
    succesful_sign_out = database_helper.sign_out(token)
    if succesful_sign_out:
        return jsonify({'success': True, 'message': "Succesfully signed out"})
    else:
        return jsonify({
            'success':
            False,
            'message':
            "Something went wrong when trying to sign out"
        })
Example #6
0
def sign_out():
    token1 = request.form.get('token')
    tokreset = 'null'
    signed = dh.sign_out(tokreset, token1)
    if signed == "signout":
        return json.dumps({
            "success": "true",
            "message": "Successfully signed out."
        })
    else:
        return json.dumps({
            "success": "false",
            "message": "You are not signed in."
        })
Example #7
0
def sign_out():
    token = request.headers.get('Token')
    if token is not None:
        result = database_helper.sign_out(token)
        if result:
            return json.dumps({
                "success": "true",
                "message": "Token deleted!"
            }), 200
        else:
            return json.dumps({
                "success": "false",
                "message": "Something went wrong!"
            }), 500
    else:
        return '', 400
Example #8
0
def sign_out():
    print('Sign out')
    token = request.args.get('token', '')

    logged = database_helper.user_logged_by_token(token=token)

    if logged:
        email = database_helper.get_user_by_token(token)
        del id_socket[str(email)]
        out = database_helper.sign_out(token=token)
        if out:
            send_notification()
            return json.dumps({'success' : True, 'message': 'User unlogged'})
        else:
            return json.dumps({'success' : False, 'message': 'Failed to unlogged user'})
    else:
        return json.dumps({'success' : True, 'message': 'User already logged out or nonexistent'})
Example #9
0
def sign_out():
    token = request.headers.get('token')
    print("This is the token we're sending: ", token)
    email = database_helper.getEmailByToken(token)
    status = database_helper.sign_out(token)

    if (email in WebSocketDictionary.keys()):
        WebSocketDictionary[email].close()
        del WebSocketDictionary[email]

    if (status["success"]):
        return jsonify({
            "success": True,
            "message": "Successfully signed out."
        })
    else:
        print(status["message"])
        return jsonify({"success": False, "message": "You are not signed in."})
Example #10
0
def sign_out(token=None):
    data = request.get_json()
    token = data['token']
    if token == None:
        return jsonify({'success': False, 'message': "You are not signed in."})
    url = data['url']
    public_key = data['publicKey']
    authentication_data = database_helper.get_email_logged_user_new(public_key)
    stored_token = authentication_data['token']
    equal_hashed_token = False
    ########################## Token verification ##########################
    # 1. Recreate the blob using the stored token
    blob = ""
    i = 0
    while i < len(url):
        blob = blob + url[i]
        i = i + 3
    blob = stored_token + blob
    # 2. Hash it
    hash = hashlib.sha256(blob.encode()).hexdigest()
    # 3. Compare the two hashes
    if token == hash:
        equal_hashed_token = True
        print("Equal hashes log_out")
    ########################################################################
    if equal_hashed_token:
        succesful_sign_out = database_helper.sign_out(stored_token)
        if succesful_sign_out:
            return jsonify({
                'success': True,
                'message': "Succesfully signed out"
            })
        else:
            return jsonify({
                'success':
                False,
                'message':
                "Something went wrong when trying to sign out"
            })
    else:
        return jsonify({
            'success': False,
            'message': "The hashes is not the same"
        })
Example #11
0
def sign_in(email,password):
    if request.method=='GET':

            #om email redan aer inloggad skall den redan_inloggade loggas ut
        #email=str(request.args.get('email'))
        # password=str(request.args.get('password'))
        check=database_helper.checkpass(email=email,password=password)
        if check==True:
            token=database_helper.sign_in(email=email,password=password)
            if token is not False:
                data = {}
                data['success'] = True
                data['data'] = token
                json_token = json.dumps(data)
                print(json_token)
                return json_token
            else:
                print('must log out previous')
                print(len(active_connections))
                if len(active_connections) > 0:
                    for ws in active_connections:
                        if ws[1]==str(email):
                            ws[0].send('signout')

                delete=database_helper.sign_out(email=email)
                print('logged out')
                if delete ==True:
                    token_=database_helper.sign_in(email=email,password=password)
                    print(token_)
                    if token_ is not False:
                        print('token made')
                        data = {}
                        data['success'] = True
                        data['data'] = token_
                        json_token = json.dumps(data)
                        return json_token
        else:
           data = {}
           data['success'] = False
           json_token = json.dumps(data)
           return json_token
Example #12
0
def sign_out():
    token1 = request.args.get('token')
    tokreset = 'null'
    dh.sign_out(tokreset,token1)
    return "You have now signed-out"
Example #13
0
def sign_out_active(email):
    ws_token = dh.get_user_token(email)
    if len(ws_token) > 1:
        dh.sign_out(ws_token[0][0])
        return ws_token[0]
    return None
Example #14
0
def sign_out(token):
    dh.sign_out(token)
    return json.dumps({"message": "You have been signed out"}), 200