def login(): form = LoginForm(request.form) if request.method == 'GET': return render_template("login.html", form=form) elif request.method == 'POST': form_is_valid = form.validate_on_submit() if form_is_valid: username = form.username.data password = form.password.data registered_user = User.query.\ filter_by(username=username).first() remember_me = False if 'remember_me' in request.form: remember_me = True if registered_user is not None and \ bcrypt.check_password_hash( registered_user.password, password): login_user(registered_user, remember=remember_me) flash('Login successful') return redirect(request.args.get('next') or url_for('index')) else: flash('Username or password is invalid', 'error') return render_template('login.html', form=form) else: return render_template('login.html', form=form)
def signin(): if current_user.is_authenticated: return redirect(url_for('index')) sform = SigninForm() try: if sform.validate_on_submit(): user = Users.query.filter_by(username=sform.username.data).first() if user: if bcrypt.check_password_hash(user.password, sform.password.data): login_user(user, remember=sform.remember.data) flash('Your have successfully logged in', 'success') return redirect(url_for('index')) else: flash('Invalid Password! Please try again', 'danger') return redirect(url_for('signin')) else: flash('Invalid Username! Please try again...', 'danger') return redirect(url_for('signin')) except: flash( 'Oops! Something wrong with the Database.Please try again after some time.' ) return redirect(url_for('signin')) return render_template('user/signin.html', form=sform)
def login(): if current_user.is_authenticated: return redirect(url_for('home')) form = LoginForm() if form.validate_on_submit(): user = Users.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['messages'] #next_page = request.args.get("next") print("*************") print(next_page) session['logged_in'] = True return redirect( next_page) if next_page == "/predict" else redirect( url_for('home')) #flash('Login successful.', 'success') #if next_page=="/predict": # return redirect(next_page) #else: # redirect(url_for('home')) else: flash('Login Unsuccessful. Please check email and password', 'danger') return redirect(url_for('auth.redirected')) return render_template('login.html', title='Login', form=form)
def verify(username, password): user = User.query.filter_by(email=username).first() if not user: return False g.user = user # g is a Flask object for view functions to access return bcrypt.check_password_hash(user.password, password)
def test_create_user_success(self): """ Is user successfully created? """ is_password_hashed = bcrypt.check_password_hash( self.u2.password, 'password') self.assertEqual(self.u2.username, 'username') self.assertEqual(self.u2.email, 'email') self.assertTrue(is_password_hashed) self.assertEqual(len(User.query.all()), 2)
def authenticate(cls, email, password): """Need to authenticate the person who he/she claims is/Also needed for edit user's info""" user = cls.query.filter_by(email=email).first() if user: is_auth = bcrypt.check_password_hash(user.password, password) if is_auth: return user return False
def after_login(nickname, password): user = User.query.filter_by(nickname = nickname).first() if user is not None and bcrypt.check_password_hash(user.password, password): remember_me = False if 'remember_me' in session: remember_me = session['remember_me'] session.pop('remember_me', None) login_user(user, remember = remember_me) else: flash('Invalid login. Try again.') return redirect(url_for('login')) return redirect(request.args.get('next') or url_for('index'))
def login(): if request.method == 'POST': email = request.form['email'] password = request.form['password'] user = User.query.filter_by(email=email).first() if user: if bcrypt.check_password_hash(user.password, password): login_user(user) flash('Logged in successfully.') return redirect(url_for('departments')) flash('Credentials dont match') return redirect(url_for('register')) return render_template('login.html')
def login(): error = None form = LoginForm(request.form) if request.method == 'POST': if form.validate_on_submit(): user = User.query.filter_by(name=request.form['username']).first() if (user is not None and bcrypt.check_password_hash(user.password, request.form['password'])): login_user(user) flash( request.form['username'] + ' were logged in.') return redirect(url_for('home.home')) else: error = 'Invalid Credentials. Please try again.' return render_template('login.html', form = form, error=error)
def login(): if request.method == 'POST': name = request.form['name'] password = request.form['password'] user = User.query.filter_by(name=name).first() if user: if bcrypt.check_password_hash(user.password, password): login_user(user) flash(f"hello {user.name}") return redirect(url_for('users')) return redirect(url_for('login')) flash('Credentials dont match') return redirect(url_for('registration')) return render_template('login.html')
def login(): error = None form = LoginForm(request.form) if request.method == 'POST': if form.validate_on_submit(): email = form.email.data password = form.password.data user = User.query.filter_by(email=email).first() if user is not None and bcrypt.check_password_hash( user.password, request.form['password']): login_user(user) flash('Login successful!') return redirect(url_for('index')) else: error = 'Invalid username or password. Please try again.' return render_template('login.html', form=form, error=error)
def login(): loginError = None login = LoginForm() ##LOGIN if login.validate_on_submit(): users = User.query.filter_by(username=login.username.data).first() print users if users: if bcrypt.check_password_hash(users.password, login.password.data): login_user(users) flash("You were logged in") return redirect(url_for("index")) else: loginError = "Incorrect User and Password" app.logger.warning("Incorrect passwword for username (%s)", login.username.data) return render_template( "login.html", form1=RegistrationForm(), form2=login, loginError=loginError, registerError=None )
def login(): error = None status_code = 200 form = LoginForm(request.form) if request.method == 'POST': if form.validate(): user = User.query.filter_by(name=request.form['name']).first() if user is not None and bcrypt.check_password_hash( user.password, request.form['password']): session['logged_in'] = True session['user_id'] = user.id session['name'] = user.name flash('Welcome!') return redirect(url_for('dashboard')) else: error = 'Invalid username or password.' else: error = 'Both fields are required.' return render_template('forms/login.html', form=form, error=error), status_code
def profile(): """Update profile for current user.""" if not g.user: flash('Access unauthorized.', 'danger') return redirect('/') form = UpdateForm(obj=g.user) if form.validate_on_submit(): #Verify that it's the current user making edits if bcrypt.check_password_hash(g.user.password, form.password.data): g.user.bio = form.bio.data g.user.image_url = form.image_url.data g.user.header_image_url = form.header_image_url.data g.user.email = form.email.data g.user.location = form.location.data db.session.commit() return redirect(f'/users/{g.user.id}') else: flash('Incorrect password', 'danger') return redirect('/') else: return render_template('users/edit.html', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('home')) form = LoginForm() if form.validate_on_submit(): user = Users.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) session['logged_in'] = True if "predict" in session: if session['predict'] == True: return redirect('/predict') return render_template('index.html') #flash('Login successful.', 'success') else: flash('Login Unsuccessful. Please check email and password', 'danger') return redirect(url_for('auth.redirected')) return render_template('login.html', title='Login', form=form)
def check_hash(self, password): return bcrypt.check_password_hash(self.password, password)