def login(): # Check if there is a user logged-in already if current_user.is_authenticated: abort(400, 'You Are Logged-In Already!') req = request.get_json() if not req: abort(400, 'Please Provide an Email and Password') email = req.get('email') password = req.get('password') try: # Try to log the user in as current user validate_current_user(email=email, passw=password) except Exception as e: print(e) abort(422, e) return jsonify({ 'user': f'User "{email}" Logged-In Successfully!', 'current_user': current_user.display(), 'success': True })
def login(): # Check if there is a user Logged-in already if current_user.is_authenticated: abort(400, 'You Are Logged-in Already!') req = request.get_json() # If request is empty (None) if not req: abort(400, 'Please Provide a Username/Email and Password') cred = req.get('usernameOrEmail') password = req.get('password') # If user doesn't provide any of the previous credentials if not cred or not password: abort(400, 'Username/Email and Password Fields Must be Filled!') try: validate_current_user(cred=cred, passw=password) except Exception as e: print(e) abort(422, e) return jsonify({ 'user': f'User {current_user.username} Logged-in Successfully!', 'current_user': current_user.display(), 'success': True })
def load_user_request(): if current_user.is_authenticated: current = current_user.display() else: current = None return jsonify({"current_user": current})
def load_current(): try: current = None if current_user.is_authenticated: current = current_user.display() return jsonify({'current_user': current, 'success': True}) except Exception as e: print(e) abort(500, 'Something Went Wrong in Our End!')
def login(): # Check if there is a user logged-in already if current_user.is_authenticated: abort(400, 'You Are Logged-In Already!') req = request.get_json() if not req: abort(400, 'Please Provide a Username or an Email and Password') cred = req.get('usernameOrEmail') password = req.get('password') try: validate_current_user(cred=cred, passw=password) except Exception as e: print(e) abort(422, e) return jsonify({ 'user': f'User {current_user.username} Logged-In Successfully!', 'current_user': current_user.display(), 'success': True })