def validate_username(self, username): u = User.find_user(username.data) if u is not None: raise ValidationError('Username already exists!') u = User.find_user_request(username.data) if u is not None: raise ValidationError('Username already requested registration!')
def disable_user(username): if current_user.admin and current_user.enabled: user_request = User.find_user(username) if user_request is not None: user_request.disable() flash('user disabled') else: flash('user does not exists') return redirect(url_for('authentication.admin')) else: return redirect(url_for('videoapp.index'))
def login(): if current_user.is_authenticated: return redirect(url_for('videoapp.videolist')) form = LoginForm() if form.validate_on_submit(): user = User.find_user(form.username.data) if user is None or not user.check_password( form.password.data) or not user.enabled: flash('Incorrect user or password') return redirect(url_for('videoapp.videolist')) login_user(user, form.remember_me.data) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('videoapp.index') return redirect(next_page) return render_template('authentication/login.html', title='Login', form=form)