def login(): form = LoginForm(request.form) # FORM definition if request.method == 'GET': return render_template('login.html', form=form) if form.validate_on_submit(): # when form submits enter block user = User.query.filter_by(username=form.username.data).first() if user: if check_password_hash(user.password, form.password.data): session['user_id'] = user.id login_user(user, remember=form.remember.data) return redirect(url_for('settings')) else: flash("password incorrect") return redirect('/settings') else: flash("username not found") return redirect('/settings') else: flash(f"Form has errors: {form.errors}") return redirect('/login')
def login_to_account(): '''Log in page for users, validates email and password with database''' form = LoginForm() email = form.email.data pw = form.password.data if form.validate_on_submit(): user = crud.get_user_by_email(email) if user: user_pw, user_id = user.password, user.user_id if pw == user_pw: session['user'] = user_id return redirect(f'/account/{user_id}') else: flash('Incorrect password! Please try again.') else: flash( "Sorry, we don't recognize that email! Please create an account." ) return redirect('/create_account') # else: # return f'This is correct' # used for testing.py, when trying to test post method the form is not allowing to "validate" # so is just skipping over that if statement and returning login page return render_template('login.html', form=form)
def login(): """ """ form = LoginForm() session['mssg'] = "" if form.validate_on_submit(): user = Users.query.filter_by(username=form.username.data).first() if user: if check_password_hash(user.password, form.password.data): if (user.flag_active): login_user(user) elif (user.username is 'admin'): login_user(user) else: return render_template('activate.html', user=user.username), 200 return redirect(url_for('projects')) else: session['mssg'] = "Invalid Username or Password" return render_template('login.html', subtitle="Login", form=form, mssg=session['mssg']) else: session['mssg'] = "Invalid Username or Password" return render_template('login.html', subtitle="Login", form=form, mssg=session['mssg']) return render_template('login.html', subtitle="Login", form=form, mssg=session['mssg']), 200
def login(): form = LoginForm() if form.validate_on_submit(): # get user object and validate print form.email.data user = ds.find_user(email=form.email.data) if bcrypt.check_password_hash(user.password, form.password.data): login_user(user) session["logged_in"] = True return redirect(request.args.get("next") or "/") return render_template("login.html", form=form)
def login(): """ Validating entered user info with the DB""" login_form = LoginForm() user = User.query.filter_by(username=login_form.username.data).first() if login_form.validate_on_submit(): if user: if user.password == login_form.password.data: login_user(user) return redirect('/searchpage') else: flash("Sorry, the information you entered is incorrect") return redirect('/')
def login(): form = LoginForm(request.form) #request Wt-from named loginForm if request.method == 'POST' and form.validate_on_submit( ): #validate form using validators defined in model.py existing_user = User.query.filter_by( username=form.username.data).first() #get username from db if existing_user: #if exists check password else raise warning if existing_user.password == form.password.data: session['logged_in'] = True return redirect(url_for('home')) return 'Invalid Password.' else: return 'Invalid Username.' return render_template('login.html', form=form)
def testing(): form = LoginForm() email = form.email.data pw = form.password.data if form.validate_on_submit(): user = crud.get_user_by_email(email) if user: user_pw, user_id = crud.get_user_info(email) if pw == user_pw: session['user'] = user_id return redirect(f'/account/{user_id}') else: flash('Incorrect password! Please try again.') else: flash('Please create an account.') return redirect('/create_account') return render_template('test.html', form=form)