Ejemplo n.º 1
0
def before_request():
    g.user = None
    if request.cookies.get('username') and request.cookies.get('cookiecode'):
        if account.valid_cookiecode(request.cookies.get('username'),request.cookies.get('cookiecode')):
            if not session.get('uid'):
                account.write_session(account.get_user_id(request.cookies.get('username')))
            g.user = models.User(request.cookies.get('username'),session.get('uid'))
        else:
            return redirect(url_for('logout'))
Ejemplo n.º 2
0
def login():
    if request.method == 'POST':
        loginform = forms.LoginForm(request.form)
        formvalidinfo = loginform.valid()
        if formvalidinfo.is_success:
            logininfo = account.account_login(loginform)
            if logininfo.is_success:
                g.user = models.User(loginform.username, account.get_user_id(loginform.username))
                resp = make_response(redirect(url_for('index')))
                account.write_cookie(resp,g.user.username)
                account.write_session(g.user.id)
                return resp
            else:
                flash(logininfo.message)
                print logininfo.message
        else:
            flash(formvalidinfo.message)
            print formvalidinfo.message
    return render_template('login.html')