Exemplo n.º 1
0
def index():
    myForm = LoginForm()
    if myForm.validate_on_submit():
        if session['recaptcha'].lower() == myForm.recaptcha.data.lower():
            user = User(myForm.username.data, myForm.password.data)
            session['username'] = myForm.username.data
            if (user.isExisted()):
                return redirect(url_for('home'))
            else:
                flash(u'出错啦,登录失败,请检查用户名和密码是否正确!')
        else:
            flash(u'Hi, 验证码错误, 请重输!')
    return render_template('index.html', form=myForm)
Exemplo n.º 2
0
def register():
    regForm = registerForm()
    if regForm.validate_on_submit():
        if session['recaptcha'].lower() == regForm.recaptcha.data.lower():
            session['username'] = regForm.username.data
            query_obj = User(regForm.username.data, regForm.password.data)
            if (query_obj.isExisted()):
                flash(u'此用户名已经被使用,请重新注册!')
                del query_obj
                return render_template('register.html', form=regForm)
            else:
                user = User(regForm.username.data, regForm.password.data)
                user.add()
                flash(u'恭喜您,注册成功,您现在可以登录!')
                return redirect(url_for('index'))
        else:
            flash(u'Hi, 验证码错误, 请重输!')
    return render_template('register.html', form=regForm)