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('index')) 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('home')) form = LoginForm() if form.validate_on_submit(): user = User.quetry.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) return 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('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 render_login_page(): if current_user.is_authenticated: next_page = request.args.get('next') if next_page: print("nextpage", flush=True) return redirect(next_page) elif current_user.usertype == "admin": print("admin", flush=True) return redirect("/admin") elif current_user.usertype == "petowner": print("current", flush=True) return redirect("/owner") elif current_user.usertype == "caretaker": print("caret", flush=True) return redirect("/caretaker") else: print("nothing mtaches", flush=True) return redirect("/profile") form = LoginForm() if form.validate_on_submit(): print("submited", flush=True) user = Users.query.filter_by(contact=form.contact.data).first() if user and bcrypt.check_password_hash(user.password, form.password.data): print("found", flush=True) login_user(user, remember=True) next_page = request.args.get('next') if next_page: print("nextpage", flush=True) return redirect(next_page) elif current_user.usertype == "admin": print("admin", flush=True) return redirect("/admin") elif current_user.usertype == "petowner": print("current", flush=True) return redirect("/owner") elif current_user.usertype == "caretaker": print("caret", flush=True) return redirect("/caretaker") else: print("nothing matches", flush=True) return redirect("/profile") else: print("not found", flush=False) flash('Login unsuccessful. Please check your contact and password', 'danger') return render_template("realLogin.html", form=form)
def login(): form = LoginForm() if form.validate_on_submit(): #對帳密 user = User.query.filter_by(name=form.name.data).first() try: if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user) next_page = request.args.get('next') return redirect(next_page) if next_page else redirect( url_for('main.home')) else: flash('Please check your account and password.', 'warning') except: flash('Please check your account and password.', 'warning') return render_template('login.html', title='Login', form=form)
def change_user_info(): passwordform = ResetPasswordForm() if passwordform.validate_on_submit(): if bcrypt.check_password_hash(current_user.password, passwordform.original_password.data): hashed_password = bcrypt.generate_password_hash( passwordform.password.data).decode('utf-8') current_user.password = hashed_password db.session.commit() flash('Reset password successful!', 'success') return redirect(url_for('main.home')) else: return redirect(url_for('main.home')) flash('Current password is not correct', 'warning') form = LoginForm() name = current_user.name user = User.query.filter_by(name=name).first() return render_template('/changeuserinfo.html', user_info=user, form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('home')) forml = LoginForm() if forml.validate_on_submit(): user = User.query.filter_by(email=forml.email.data).first() if user and bcrypt.check_password_hash(user.password, forml.password.data): login_user(user, remember=forml.remember.data) next_page = request.args.get('next') flash('You are Successfully Logged In', 'success') return redirect(next_page) if next_page else redirect(url_for('home')) else: flash('Login Unsuccessful. Please check email and password', 'danger') else : return redirect(url_for('home')) return redirect(url_for('home'))
def login(): """ this is the view for siginig in a user """ # if the current user is authenticated then redirect to the home page. if current_user.is_authenticated: return redirect(url_for('home')) form = LoginForm() # validating the data from the form with the data from the database. 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) next_page = request.args.get('next') return redirect(next_page) if next_page else redirect( url_for('home')) else: flash('Login Unsuccessful', 'danger') return render_template('login.html', form=form)
def render_login_page(): if current_user.is_authenticated: next_page = request.args.get('next') if next_page: return redirect(next_page) elif current_user.usertype == "admin": return redirect("/admin") elif current_user.usertype == "petowner": return redirect("/owner") elif current_user.usertype == "caretaker": return redirect("/caretaker") else: return redirect("/profile") form = LoginForm() if form.validate_on_submit(): # Don't change. This ORM is linked to how user is verified as login and possess certain roles # This is required by other libraries such as login_manager user = Users.query.filter_by(contact=form.contact.data).first() if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=True) next_page = request.args.get('next') if next_page: return redirect(next_page) elif current_user.usertype == "admin": return redirect("/admin") elif current_user.usertype == "petowner": return redirect("/owner") elif current_user.usertype == "caretaker": return redirect("/caretaker") else: return redirect("/profile") else: flash('Login unsuccessful. Please check your contact and password', 'danger') return render_template("realLogin.html", form=form)
def check_password_hash(self, password): if bcrypt.check_password_hash(pw_hash=self.password, password=password): return True else: return False