我们从Python开源项目中,提取了以下25个代码示例,用于说明如何使用flask_login.current_user.verify_password()。
def login(): if not models.Users.query.all(): return redirect(url_for('user.signup', next=request.args.get('next'))) form = LoginForm() if form.validate_on_submit(): username = form.username.data password = form.password.data me = models.Users.query.filter_by(username=username).one_or_none() if me is not None and me.verify_password(password): login_user(me, form.remember_me.data) flash('Logged in successfully.') current_app.logger.info('A successful login attempt (%s)', username) return redirect(request.args.get('next') or url_for('home.index')) flash('Invalid usename or password.') current_app.logger.warning('A warning login attempt (%s)', username) return render_template('user/login.html', form=form)
def login(): """Log in page. """ form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user is not None and user.verify_password(form.password.data): login_user(user, form.remember_me.data) if not user.confirmed: # account did not confirmed by admin cannot login flash('Your register request has not been confirmed by administrator yet.') return render_template('auth/login.html', form=form) return redirect(request.args.get('next') or url_for('.profile')) flash('Invalid username or password.') return render_template('auth/login.html', form=form)
def change_password(): """Change password when user knows his/her password. """ form = ChangePasswordForm() if form.validate_on_submit(): if current_user.verify_password(form.old_password.data): current_user.password = form.password.data db.session.add(current_user) flash('Your password has been updated.') return redirect(url_for('.profile')) else: flash('Invalid password.') return render_template("auth/change_password.html", form=form)
def login(): form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user is not None and user.verify_password(form.password.data): login_user(user, form.remember_me.data) return redirect(request.args.get('next') or url_for('user.index')) flash('????????') return render_template('auth/login.html', title = '??', form =form)
def change_password(): form = ChangePasswordForm() if form.validate_on_submit(): if current_user.verify_password(form.old_password.data): current_user.password = form.password.data db.session.add(current_user) flash('?????????') return redirect(url_for('user.index')) else: flash('??????') return render_template('auth/change_password.html', form=form, title='????')
def login(): form = LoginForm() if form.validate_on_submit(): user = orm.User.query.filter_by(email=form.email.data).first() if user is not None and user.verify_password(form.password.data): login_user(user, form.remember_me.data) return redirect(request.args.get('next') or url_for('view_rents')) flash(u'????????') elif request.method =='GET': logic.LoadBasePageInfo('??',form) return render_template('auth/login.html', form=form)
def change_password(): form = ChangePasswordForm() logic.LoadBasePageInfo('????', form) if form.validate_on_submit(): if current_user.verify_password(form.old_password.data): current_user.password = form.password.data orm.User.query.filter_by(id=current_user.id).update({'password_hash':current_user.password_hash}) orm.db.session.commit() flash('??????') return redirect(url_for('login')) else: flash('????') return render_template("auth/change_password.html", form=form)
def change_password(): form = ChangePasswordForm() if form.validate_on_submit(): if current_user.verify_password(form.old_password.data): current_user.password = form.password0.data db.session.add(current_user) db.session.commit() flash('Your password has been updated.') return redirect(url_for('home.index')) else: flash('Invalid password.') return render_template("user/change_password.html", form=form)
def change_email_request(): form = ChangeEmailForm() if form.validate_on_submit(): if current_user.verify_password(form.password.data): new_email = form.email.data token = current_user.generate_email_change_token(new_email) send_email(new_email, 'Confirm your email address', 'mail/user/change_email', user=current_user, token=token) flash('An email with instructions to confirm your new email ' 'address has been sent to you.') return redirect(url_for('home.index')) else: flash('Invalid password.') return render_template("user/change_email.html", form=form)
def login_register(): login_form = LoginForm() register_form = RegistrationForm() # ????????? if login_form.submit1.data and login_form.validate_on_submit(): user = User.query.filter_by(email=login_form.email.data).first() if user is not None and user.verify_password(login_form.password.data): login_user(user, login_form.remember_me.data) return redirect(url_for('main.index')) flash(constant.WRONG) # ????????? if register_form.submit2.data and register_form.validate_on_submit(): user = User(email=register_form.email.data, username=register_form.username.data, password=register_form.password.data, name=register_form.username.data) db.session.add(user) db.session.commit() try: token = user.generate_confirmation_token() send_email(user.email, 'Confirm Your Account', 'auth/email/confirm', user=user, token=token) flash(constant.SEND_EMIAL) except Exception as e: print e return redirect(url_for('auth.login_register')) return render_template('auth/login.html', form1=login_form, form2=register_form)
def profile(): """??????""" form = ChangeEmailForm() if form.validate_on_submit(): if current_user.verify_password(form.password.data): new_email = form.email.data token = current_user.generate_email_change_token(new_email) send_email(new_email, 'Confirm your email address', 'auth/email/change_email', user=current_user, token=token) flash(constant.SEND_EMIAL) return redirect(url_for('auth.profile')) else: flash(constant.WRONG_PWD) return render_template("email_settings.html", user=current_user, form=form, base64=base64)
def password(): """??????""" form = ChangepasswordForm() if form.validate_on_submit(): if current_user.verify_password(form.oldpassword.data): if current_user.change_password(form.password.data): flash(constant.UPDATE_SUCC) logout_user() return redirect(url_for('auth.login_register')) else: flash(constant.UPDATE_FAIL) else: flash(constant.WRONG_PWD) return render_template("password_settings.html", user=current_user, form=form, base64=base64)
def login(): form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user is not None and user.verify_password(form.password.data): login_user(user, form.remember_me.data) return redirect(request.args.get('next') or url_for('main.index')) flash('Invalid username or password.') return render_template('auth/login.html', form=form)
def change_password(): form = ChangePasswordForm() if form.validate_on_submit(): if current_user.verify_password(form.old_password.data): current_user.password = form.password.data db.session.add(current_user) flash('Your passoword has been update.') return redirect(url_for('main.index')) else: flash('Invalid password.') return render_template("auth/change_password.html", form=form)
def change_email_request(): form = ChangeEmailForm() if form.validate_on_submit(): if current_user.verify_password(form.password.data): new_email = form.email.data token = current_user.generate_email_change_token(new_email) send_email(new_email, 'Confirm your email address', 'auth/email/change_email', user=current_user, token=token) flash('An email with instructions to confirm your new email ' 'address has been sent to you.') else: flash('Invalid email or password.') return render_template('auth/change_email.html', form=form)
def login(): form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email = form.email.data).first() if user is not None and user.verify_password(form.password.data): login_user(user, form.remember_me.data) return redirect(request.args.get('next') or url_for('main.index')) flash('Invalid username or password.') return render_template('auth/login.html', form = form)
def change_password(): form = ChangePasswordForm() if form.validate_on_submit(): if current_user.verify_password(form.old_password.data): current_user.password = form.password.data db.session.add(current_user) flash('You password has been updated') return redirect(url_for('main.index')) else: flash('Invalid password') return render_template('auth/change_password.html', form = form)
def change_email_request(): form = ChangeEmailForm() if form.validate_on_submit(): if current_user.verify_password(form.password.data): new_email = form.email.data token = current_user.generate_email_change_token(new_email) send_email(new_email, 'Confirm your email address', 'auth/email/change_email', user = current_user, token = token) flash('An email with instructions to confirm your new email address has been sent to you') return redirect(url_for('main.index')) else: flash('Invalid email or password') return render_template('auth/change_email.html', form = form)
def update_password(): """????(?????)""" form = UpdatePasswordForm() if form.validate_on_submit(): if not current_user.verify_password(form.old_password.data): flash('your old password is not right! Please try again!') return redirect(url_for('.update_password')) if current_user.update_password(form.new_password.data): # ???????? logout_user() # ??????????? flash('you have changed your password, please login') return redirect(url_for('.login')) else: flash('failed to update your password, please try again') return render_template('auth/password/update.html', form = form)
def login(): form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user is not None and user.verify_password(form.password.data): login_user(user, form.remember_me.data) return redirect(request.args.get('next') or url_for('main.index')) flash(u'??????????') return render_template('auth/login.html', form=form)
def change_password(): form = ChangePasswordForm() if form.validate_on_submit(): if current_user.verify_password(form.old_password.data): current_user.password = form.password.data db.session.add(current_user) flash(u'??????') return redirect(url_for('main.index')) else: flash(u'??????') return render_template('auth/change_password.html', form=form)
def change_email_request(): form = ChangeEmailForm() if form.validate_on_submit(): if current_user.verify_password(form.password.data): new_email = form.email.data token = current_user.generate_email_change_token(new_email) send_email(new_email,'Confirm your email address', 'auth/email/change_email', user=current_user, token=token) flash(u'??????????????????????') return redirect(url_for('main.index')) else: flash(u'?????????') return render_template('auth/change_email.html', form=form)
def login(): form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user is not None and user.verify_password(form.password.data): #????????????? login_user(user,form.remember_me.data) return redirect(request.args.get('next') or url_for('main.index')) flash('Invalid username or password') return render_template('auth/login.html',form=form) #????
def modifityPassword(): form = ModifityPassword() if form.validate_on_submit(): if current_user.verify_password(form.oldPassword.data): current_user.password = form.newPassword.data db.session.add(current_user) flash('Change password is success!') return redirect(url_for('main.index')) else: flash('Invalid password') return render_template('auth/modifitypassword.html',form=form) #????