def sign_in(): """Sign in Gets email and password from JSON form and searches for user in database If user exists, log in user """ data = request.get_json() email = data['email'] pwd = data['pwd'] hashed_password = database_helper.get_hashed_password(email) #print('hashed password from helper: ', hashed_password) correct_password = bcrypt.check_password_hash(hashed_password, pwd) if not (database_helper.find_user_pwd(email, hashed_password)): res = jsonify({'success': False, 'message': 'Wrong email or password'}) return res token = database_helper.login_user(email) if (token and correct_password): res = jsonify({ 'success': True, 'message': 'Signed in!', 'token': token }) push_websocket_active_users() push_websocket_total_posts() return res else: res = jsonify({'success': False, 'message': 'Something went wrong!'}) return res
def sign_in(): data = request.get_json() if (database_helper.find_user( data['email'], data['password'])): #verify with database password, userToken = secrets.token_hex(12) #CREATE TOKEN if database_helper.login_user(data['email'], userToken): return jsonify(success="true", message="Login checks out B)", token=userToken) #SAVE TOKEN else: return jsonify(success=False, message="couldnt add a user with that email") else: return 'wrong credentials', 400
def signin(): req = request.get_json(force=True) email = req['email'] password = req['password'] # See if user exists in database if database_helper.find_user(email, password): token = uuid.uuid4().hex # Add user to logged in users if database_helper.login_user(email, token): # Send stats to all users send_stats(True) return jsonify(success=True, message="Login successful!", data=token) else: # Shouldn't happen return jsonify(success=False, message="Failed to login user!") else: return jsonify(success=False, message="Username or password incorrect!")
def signin(): email = request.form['email'] password = request.form['password'] # See if user exists in database if database_helper.find_user(email, password): token = uuid.uuid4().hex # Add user to logged in users if database_helper.login_user(email, token): return jsonify(success="true", message="Login successful!", data=token) else: # Shouldn't happen return jsonify(success=False, message="Failed to login user!") else: return jsonify(success=False, message="Username or password incorrect!")
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)
def sign_in(): """Sign in Gets email and password from JSON form and searches for user in database If user exists, log in user """ data = request.get_json() email = data['email'] pwd = data['pwd'] if not (database_helper.find_user(email, pwd)): res = jsonify({'success': False, 'message': 'Wrong email or password'}) return res token = database_helper.login_user(email) if(token): res = jsonify( {'success': True, 'message': 'Signed in!', 'token': token}) return res else: res = jsonify({'success': False, 'message': 'Something went wrong!'}) return res