Example #1
0
def login():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        user = authenticate(username, password)
        if not user:
            flash('用户名或密码错误')
        else:
            session['username'] = user.username
            session['id'] = user.id
            return redirect(request.form.get('next_url'))

    return render_template('login.html')
Example #2
0
 def login(self):
     if request.method == "POST":
         username = request.form['username']
         password = request.form['password']
         user = authenticate(username, password)
         if user:
             session['username'] = user.username
             session['id'] = user.id
             session['auth_info'] = dict(permissions=user.permissions,
                                         is_super=user.is_super)
             return redirect(url_for('admin.index'))
         else:
             flash('请输入正确的用户名和密码')
     return self.render('admin/login.html')