Пример #1
0
def login():
    next = request.values.get('next', '/')
    form = LoginForm()
    form.next.data = next
    if form.validate_on_submit():
        session['user_id'] = unicode(form.user.pk)
        flash(u'Login successfully', 'success')
        return redirect(next)
    return render_template('accounts/login.html', form=form)
Пример #2
0
def login():
    next = request.values.get('next', '/')
    form = LoginForm()
    form.next.data = next
    if form.validate_on_submit():
        session['user_id'] = unicode(form.user.pk)
        flash(u'Login successfully', 'success')
        return redirect(next)
    return render_template('accounts/login.html', form=form)
Пример #3
0
def login():
    """ 用户登录 """
    form = LoginForm()
    if form.validate_on_submit():
        user_obj = form.login()
        if user_obj is None:
            flash('账号或密码错误', 'danger')
        else:
            flash('{},欢迎回来'.format(user_obj.username), 'success')
            return redirect(url_for('index'))
    return render_template('login.html', form=form)
Пример #4
0
def login():
    next = request.values.get('next', '/')
    form = LoginForm()
    form.next.data = next
    if form.validate_on_submit():
        session['user_id'] = unicode(form.user.pk)
        flash(u'Login successfully', 'success')

        g.user = User.objects.get(pk=session['user_id'])
        sha1 = hashlib.sha1()
        sha1.update(g.user.email.encode('utf8'))
        g.hash = sha1.hexdigest()
        return redirect(next)
    return render_template('accounts/login.html', form=form)
Пример #5
0
def login():
    """ 登录页面 """
    form = LoginForm()
    next_url = request.values.get('next', url_for('qa.index'))
    if form.validate_on_submit():
        user = form.do_login()
        if user:
            # 4. 跳转到首页
            flash('{}, 欢迎回来'.format(user.nickname), 'success')
            return redirect(next_url)
        else:
            flash('登录失败,请稍后重试', 'danger')
    # else:
    #     print(form.errors)
    return render_template('login.html', form=form, next_url=next_url)
Пример #6
0
def login():
    form = LoginForm()
    next_url = request.values.get('next', url_for('qa.index'))
    if form.validate_on_submit():
        user = form.do_login()
        if user:
            # 4 跳转到首页
            flash('{}欢迎回来'.format(user.nickname), 'success')
            return redirect(next_url)
        else:
            flash('登陆失败', 'danger')

    # else:
    #     print(form.errors)
    #     print(form.username.data)
    #     print(form.password.data)
    return render_template('login.html', form=form, next_url=next_url)