def reset_password(token): form = ResetPasswordForm(request.form) reset_user_id = PasswordResetToken.get_user_id_by_token(token) if not reset_user_id: abort(500) if request.method == 'POST' and form.validate(): password = form.password.data user = User.select_user_by_id(reset_user_id) with db.session.begin(subtransactions=True): user.save_new_password(password) PasswordResetToken.delete_token(token) db.session.commit() flash('パスワードを更新しました。') return redirect(url_for('app.login')) return render_template('reset_password.html', form=form)
def forgot_password(): form = ForgotPasswordForm(request.form) if request.method == 'POST' and form.validate(): email = form.email.data user = User.select_user_by_email(email) if user: with db.session.begin(subtransactions=True): token = PasswordResetToken.publish_token(user) db.session.commit() reset_url = f'http://127.0.0.1:5000/reset_password/{token}' print(reset_url) flash('パスワード再登録用のURLを発行しました。') else: flash('存在しないユーザです') return render_template('forgot_password.html', form=form)
def forgot_password(): form = ForgotPasswordForm(request.form) if request.method == 'POST' and form.validate(): email = form.email.data user = User.select_user_by_email(email) if user: with db.session.begin(subtransactions=True): token = PasswordResetToken.publish_token(user) db.session.commit() reset_url = f'http://127.0.0.1:5000/reset_password/{token}' print(reset_url) flash('Created url to update new password') else: flash('This user does not exsist.') return render_template('forgot_password.html', form=form)
def register(): form = RegisterForm(request.form) if request.method == 'POST' and form.validate(): user = User(username=form.username.data, email=form.email.data) with db.session.begin(subtransactions=True): user.create_new_user() db.session.commit() token = '' with db.session.begin(subtransactions=True): token = PasswordResetToken.publish_token(user) db.session.commit() # メールに飛ばすほうがいい print(f'パスワード設定用URL: http://127.0.0.1:5000/reset_password/{token}') flash('パスワード設定用のURLをお送りしました。ご確認ください') return redirect(url_for('app.login')) return render_template('register.html', form=form)
def register(): form = RegisterForm(request.form) if request.method == 'POST' and form.validate(): user = User(username=form.username.data, email=form.email.data) with db.session.begin(subtransactions=True): user.create_new_user() db.session.commit() token = '' with db.session.begin(subtransactions=True): token = PasswordResetToken.publish_token(user) db.session.commit() print( f'Password setting URL: http://127.0.0.1:5000/reset_password/{token}' ) flash('We sent you a password setting URL. Please check it.') return redirect(url_for('app.login')) return render_template('register.html', form=form)
def reset_password(token): form = RegisterPasswordForm(request.form) reset_user_id = PasswordResetToken.get_user_id_by_token(token) if not reset_user_id: abort(500) if request.method == 'POST' and form.validate: