def mods_login(): if g.user is not None and g.user.is_authenticated(): return redirect(url_for('index')) form = LoginForm(request.form) if request.method == 'POST' and form.validate(): login_user(mods.get_by_name(form.username.data), remember=form.remember_me.data) flash("Logged in successfully.") return redirect(request.args.get("next") or url_for('index')) return render_template('mods_login.jinja2', form=form)
def validate_username(form, field): if len(field.data) > 20: raise ValidationError(u'Username too long!') if mods.get_by_name(field.data) != None: raise ValidationError(u'Login is taken.')
def validate_user(form, field): if mods.get_by_name(field.data) == None: raise ValidationError(u'User does not exist')
def load_user(userid): return mods.get_by_name(userid)