def verify_reset_token(token): s = Serializer(current_app.config['SECRET_KEY']) try: user_id = s.loads(token)['user_id'] except: return None return session.query(User).get(user_id)
def validate_username(self, username): if username.data != current_user.username: user = session.query(User).filter_by( username=username.data).first() if user: raise ValidationError( 'That username is taken. Please choose a different one')
def reset_request(): if current_user.is_authenticated: return redirect(url_for('main.index')) form = RequestResetForm() if form.validate_on_submit(): user = session.query(User).filter_by(email=form.email.data).first() send_reset_email(user) flash('An email has been sent with instructions to reset the password', 'info') return redirect(url_for('users.login')) return render_template('reset_request.html', title="Reset Password", form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('users.login')) form = LoginForm() if form.validate_on_submit(): user = session.query(User).filter_by( username=form.username.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') flash('You have been logged in!', 'success') return render_template('welcome.html', title='Welcome', user=user) else: flash('Login Unsuccessful. Please check email and password', 'danger') return render_template('login.html', title='Login', form=form)
def load_user(user_id): return session.query(User).get(int(user_id))
def validate_email(self, email): user = session.query(User).filter_by(email=email.data).first() if user is None: raise ValidationError( 'There is no account with that email. You must register first.' )
def validate_email(self, email): if email.data != current_user.email: user = session.query(User).filter_by(email=email.data).first() if user: raise ValidationError( 'That email is taken. Please choose a different one')