我们从Python开源项目中,提取了以下27个代码示例,用于说明如何使用flask.ext.login.current_user.password()。
def register(): form = RegisterForm() if form.validate_on_submit(): user = User(email=form.email.data, username=form.username.data, password=form.password.data) db.session.add(user) db.session.commit() token = user.generate_confirmation_token() send_mail(user.email, '????', 'auth/email/confirm', user=user, token=token) flash('?????????') return redirect(url_for('auth.login')) return render_template('auth/register.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) db.session.commit() flash('???????') return redirect(url_for('main.index')) else: flash('???????????') form.old_password.data = '' form.password.data = '' form.password2.data = '' return render_template('auth/change_password.html', form=form) # ????????
def reset_password(token): if current_user.is_authenticated: return redirect('main.index') form = ResetPasswordForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user is None: flash('????!??????') form.email.data = '' return redirect(url_for('auth.reset_password')) else: if user.reset_password(token, form.password.data): flash('?????????????') else: flash('?????????????') return redirect(url_for('auth.request_reset_password')) return redirect(url_for('auth.login')) return render_template('auth/reset_password.html', form=form) # ??????
def password_reset_request(): if not current_user.is_anonymous: return redirect(url_for('main.index')) form = PasswordResetRequestForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user: token = user.generate_reset_token() send_email(user.email, 'Reset Your Password', 'auth/email/reset_password', user=user, token=token, next=request.args.get('next')) flash('An email with instructions to reset your password has been ' 'sent to you.') return redirect(url_for('auth.login')) return render_template('auth/reset_password.html', form=form)
def password_reset_request(): if not current_user.is_anonymous: return redirect(url_for('main.index')) form = PasswordResetRequestForm() if form.validate_on_submit(): user = User.query.filter_by(email = form.email.data).first() if user: token = user.generate_reset_token() send_email(user.email, 'Reset Your Password', 'auth/email/reset_password', user = user, token = token, next = request.args.get('next')) flash('An email with instructions to reset your password has been ' 'send to you.') return redirect(url_for('auth.login')) return render_template('auth/reset_password.html', form = form)
def password_reset(token): if not current_user.is_anonymous: return redirect(url_for('main.index')) form = ResetpwdForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user is None: return redirect('main.index') if user.reset_password(token, form.password.data): flash('??????.') return redirect(url_for('auth.login')) else: return redirect(url_for('main.index')) return render_template('auth/reset_password.html', form=form) #??????
def changeEmail(): form = ChangeEmailForm() if form.validate_on_submit(): if current_user.verify_password(form.password.data): new_email = form.email.data token = current_user.generate_change_email_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 login(): login_form = LoginForm() if login_form.validate_on_submit(): the_user = User.query.filter(User.email.ilike(login_form.email.data)).first() if the_user is not None and the_user.verify_password(login_form.password.data): login_user(the_user, login_form.remember_me.data) flash(u'????! ??? %s!' % the_user.name, 'success') return redirect(request.args.get('next') or url_for('main.index')) flash(u'??????????!', 'danger') return render_template("login.html", form=login_form, title=u"??")
def register(): form = RegistrationForm() if form.validate_on_submit(): the_user = User(email=form.email.data, name=form.name.data, password=form.password.data) db.session.add(the_user) db.session.commit() flash(u'????! ??? %s!' % form.name.data, 'success') login_user(the_user) return redirect(request.args.get('next') or url_for('main.index')) return render_template('register.html', form=form, title=u"?????")
def change_password(): form = ChangePasswordForm() if form.validate_on_submit(): current_user.password = form.new_password.data db.session.add(current_user) db.session.commit() flash(u'??????!', 'info') return redirect(url_for('user.detail', user_id=current_user.id)) return render_template('user_edit.html', form=form, user=current_user, title=u"????")
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) flash('????!') return redirect(request.args.get('next') or url_for('main.index')) flash('?????????') return render_template('auth/login.html', form=form) # ????
def change_email(): form = ChangeEmailForm() if form.validate_on_submit(): if current_user.verify_password(form.password.data): token = current_user.generate_change_email_token(form.email.data) send_mail(form.email.data, '??????', 'auth/email/change_email_confirm', user=current_user, token=token) flash('????????????????????????') else: flash('??????????!') return render_template('auth/change_email.html', form=form) # ????
def generate_pass(length=21): password = [] while len(password) < length: key = choice(char_set.keys()) a_char = urandom(1) if a_char in char_set[key]: if check_prev_char(password, char_set[key]): continue else: password.append(a_char) return ''.join(password)
def check_prev_char(password, current_char_set): index = len(password) if index == 0: return False else: prev_char = password[index - 1] if prev_char in current_char_set: return True else: return False
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 register(): form = RegistrationForm() if form.validate_on_submit(): user = User(email=form.email.data, username=form.username.data, password=form.password.data) db.session.add(user) db.session.commit() token = user.generate_confirmation_token() send_email(user.email,'Confirm Your Account','auth/email/confirm',user=user,token=token) flash('A confirmation email has been sent to you by email.') return redirect(url_for('main.index')) return render_template('auth/register.html',form=form)
def oauth_callback(provider): if not current_user.is_anonymous: return redirect(url_for('main.index')) oauth = OAuthSignIn.get_provider(provider) social_id, username, email = oauth.callback() if social_id is None: flash('Authentication failed.') return redirect(url_for('main.index')) user = User.query.filter_by(social_id=social_id).first() if not user: user = User(social_id=social_id, username=username, email=email,password=generate_pass(),confirmed=True) db.session.add(user) db.session.commit() login_user(user, True) return redirect(url_for('main.index'))
def password_reset(token): if not current_user.is_anonymous: return redirect(url_for('main.index')) form = PasswordResetForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user is None: return redirect(url_for('main.index')) if user.reset_password(token, form.password.data): flash('Your password has been updated.') return redirect(url_for('auth.login')) else: return redirect(url_for('main.index')) return render_template('auth/reset_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 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 register(): form = RegistrationForm() if form.validate_on_submit(): user = User(email = form.email.data, username = form.username.data, password = form.password.data) db.session.add(user) db.session.commit() token = user.generate_confirmation_token() send_email(user.email, 'Confirm Your Account', 'auth/email/confirm', user = user, token = token) flash('A confirmation email has been sent to you by email.') return redirect(url_for('main.index')) return render_template('auth/register.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 password has been updated.') return redirect(url_for('main.index')) else: flash('Invalid password.') return render_template('auth/change_password.html', form = form)
def password_reset(token): if not current_user.is_anonymous: return redirect(url_for('main.index')) form = PasswordResetForm() if form.validate_on_submit(): user = User.query.filter_by(email = form.email.data).first() if user is None: return redirect(url_for('main.index')) if user.reset_password(token, form.password.data): flash('Your password has been updated.') return redirect(url_for('auth.login')) else: return redirect(url_for('main.index')) return render_template('auth/reset_password.html', form = form)
def password(): form = PasswordForm() if form.validate_on_submit(): if not current_user.verify_password(form.old_password.data): form.old_password.errors.append("??????") return render_template("setting/password.html", form=form) flash("??????") current_user.password = current_user.generate_password_hash(form.password.data) return render_template("setting/password.html", form=form) return render_template("setting/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('main.index')) #??????????????? flash('????????.') return render_template('auth/login.html', form=form) #????
def register(): form = RegistrationForm() if form.validate_on_submit(): user = User(email=form.email.data, username=form.username.data, \ password=form.password.data) db.session.add(user) db.session.commit() #????????? token = user.generate_confirmation_token() #???????? #?????? send_email(user.email, 'Confirm Your Account', 'auth/email/confirm', user=user, token=token) flash('????????????.') return redirect(url_for('main.index')) return render_template('auth/register.html', form=form) #??????????
def changepwd(): form = ChangepwdForm() if form.validate_on_submit(): if current_user.verify_password(form.old_password.data): #????????????? current_user.password = form.new_password.data db.session.add(current_user) #???? flash('??????????') return redirect(url_for('main.index')) #?????? else: flash('?????') return render_template('auth/changepwd.html', form=form) #??????