def login(): if current_user.is_authenticated: current_app.logger.info( "User is authenticated. Redirect to main page.") return redirect(url_for("main.index")) form = LoginForm() if form.validate_on_submit(): current_app.logger.info( "POST Request hit at /login and form has been validated") current_app.logger.info("Checking password...") user = User.query.filter_by(username=form.username.data).first() if user is not None and bcrypt.check_password_hash( user.password, form.password.data): current_app.logger.info("Logging in user...") login_user(user) current_app.logger.info("User logged in") return redirect(url_for("users.account")) return render_template("login.html", title="Login", form=form)
def authenticate(username, password): """ Authentication function used by flask jwt to authorize validity of user credentials while login :param username: :param password: :return: """ user = User.query.filter_by(username=username).first() if user and bcrypt.check_password_hash(user.password, password): return user
def validate_password(self, password): """login combination check for loginform""" email_username = self.email_username.data password = password.data user_check = user_query(email_username, return_user=False) if not user_check: raise ValidationError('Invalid email/username and password combination. Please try again.') user = user_query(email_username, return_user=True) if user and bcrypt.check_password_hash(user.password, password): pass else: raise ValidationError('Invalid email/username and password combination. Please try again.')
def login(): if current_user.is_authenticated: return redirect(url_for('main.index')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() print(user) if user is not None and bcrypt.check_password_hash(user.password, form.password.data): login_user(user) return redirect(url_for('users.account')) return render_template('login.html', form=form)
def user_login(): if request.method == 'POST': data = request.json # check if email password is empty string if not data.get('email') or not data.get('password'): return jsonify({ 'message': 'email password cannot be empty, ', 'success': False }), vf.res_code['BAD_REQ'] # check if user exists check_user = mongo.db.users.find_one({'email': data.get('email')}) if not check_user: return jsonify({ 'message': 'user not found', 'success': False }), vf.res_code['UNAUTH'] # check if password matches password_match = bcrypt.check_password_hash(check_user['password'], data.get('password')) if not password_match: return jsonify({ 'message': 'incorrect password', 'success': False }), vf.res_code['UNAUTH'] _id = check_user['_id'] # save last login detail timestamp = str(vf.get_timestamp()) mongo.db.users.update_one({'_id': check_user['_id']}, {'$set': { 'last_login': timestamp }}) token = create_access_token(identity=str(_id)) resp = make_response( jsonify({ 'message': 'user login', 'success': True, 'x-token': token }), vf.res_code['SUCCESS']) resp.headers['x-token'] = token return resp else: return jsonify({ 'message': 'bad request', 'success': False }), vf.res_code['BAD_REQ']
def login(): if current_user.is_authenticated: return redirect(url_for('home')) form = LoginForm() if form.validate_on_submit(): print("inside login") employee = Employee.query.filter_by(emp_id=form.emp_id.data).first() if employee and bcrypt.check_password_hash(employee.password, form.password.data): print("inside bcrypt") login_user(employee, remember=False) print("inside login user") return redirect(url_for('home')) return render_template("login.html", form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('home')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data.lower()).first() if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) next_page = request.args.get('next') return redirect(next_page) if next_page else redirect(url_for('home')) else: flash('Login Unsuccessful. Please check email and password', 'danger') return render_template('login.html', title='Login', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('main.index')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() if user is not None and user.confirmed == True and \ bcrypt.check_password_hash(user.password, form.password.data) and form.otp.data == pyotp.TOTP(user.otp_secret).now(): login_user(user) return redirect(url_for('main.index', username=form.username.data)) return render_template('login.html', form=form)
def login(): form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) next_page = request.args.get('next') return redirect(next_page) if next_page else redirect( url_for('home')) else: flash('Please check your information!', 'danger') return render_template("login.html", title='Login', form=form)
def login(): form = LoginForm() #if all the fields are filled and submitted if form.validate_on_submit(): #search for the user in database user = User.query.filter_by(email=form.email.data).first() #if the the decrypt password is same as the form submitted password,login;else not if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) #If there is a next page request, redirect to next page next_page = request.args.get('next') return redirect(next_page) if next_page else redirect(url_for('main.home')) else: flash('Login Unsuccessful. Please check username and password', 'danger') return render_template('login.html', title='Login', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('accueillants.liste_accueillants')) form = LoginForm() if form.validate_on_submit(): coordo = Coordinateur.query.filter_by(email=form.email.data).first() if coordo and bcrypt.check_password_hash(coordo.password, form.password.data): login_user(coordo, remember=form.remember.data) next_page = request.args.get('next') return redirect(next_page) if next_page else redirect( url_for('accueillants.liste_accueillants')) else: flash('Login Unsuccessfull, check email and password.', 'danger') return render_template('login.html', title='Login', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('features.index')) form = LoginForm() if form.validate_on_submit(): user = User.objects(username=form.username.data).first() if user is not None and bcrypt.check_password_hash( user.password, form.password.data): login_user(user) return redirect(url_for('users.account')) else: flash('Login failed. Check your username and/or password') return redirect(url_for('users.login')) return render_template('login.html', title='Login', form=form)
def login(): if request.method == "POST": session.clear() form = request.form data = profiledb.find_one({"username": form["username"]}) if data and bcrypt.check_password_hash(data["password"], form["password"]): session.clear() update = updatedb.find_one() updatedb.update_one({"_id": update["_id"]}, {"$set": {"postId": None}}) session["userId"] = str(data["_id"]) session["wall_update"] = "" profiledb.update_one({"_id": ObjectId(session["userId"])}, {"$set": {"post_update": False}}) return redirect(url_for('profile', id=session["userId"])) else: return render_template('login.html', msg="Username or Password incorrect") return render_template("login.html", msg="")
def login(): if current_user.is_authenticated: flash('You are already logged in', 'success') return redirect(url_for('home')) form = LoginFrom() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) next_page = request.args.get('next') return redirect(next_page) if next_page else redirect( url_for('index')) else: flash("Login unsuccessful", "danger") return render_template(template_name_or_list='login.html', form=form, title="Login")
def login(): if current_user.is_authenticated: return redirect(url_for('main_bp.home')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) # this pushes the user to the page they were trying to click on # before getting force redirected to the login page next_page = request.args.get('next') return redirect(next_page) if next_page else redirect( url_for('main_bp.home')) else: flash('Login Unsuccessful. Please check username and password', 'danger') return render_template('login.html', title='Login', form=form)
def validate_old_password(self, old_password): if not bcrypt.check_password_hash(current_user.password, old_password.data): raise ValidationError('Current password is incorrect.')
def validate_old_password(self, old_password): """check that old password is equal to user password""" if not bcrypt.check_password_hash(current_user.password, old_password.data): raise ValidationError('Incorrect Password')
def get_by_credentials(cls, email, password): user = cls.query.filter_by(email=email).first() if user and bcrypt.check_password_hash(user.password, password): return user