Exemple #1
0
def handle_logout():
    if loggedin():
        session.pop('user_name', None)
    else:
        return error_page(env, 'Not logged in')

    return redirect_client('main_view_page')
def handle_logout():
    if loggedin():
        session.pop('user_name', None)
    else:
        return error_page(env, 'Not logged in')

    return redirect_client('main_view_page')
Exemple #3
0
def handle_login():
    print 'Handle das login'
    #tmpl = jinjaenv.get_template('loginform.html')
    _login_fail = lambda: pyro_render_template('loginform.html',
                                               loginfail=True)
    print 'Request method:', request.method

    if request.method == 'POST':
        if 'user' not in request.form or 'pass' not in request.form:
            return _login_fail()

        user = request.form['user']
        passwd = request.form['pass']

        #        pass = hashlib.sha256(pass).hexdigest()
        u = lookup_user(user)
        if u is None:
            return _login_fail()

        if u.password == passwd:
            print 'Login succes.'
            session['user_name'] = user

            # Redirect user to original page, or if not possible
            # to the main page.
            redir_url = session.pop('login_redirect_url', None)
            if redir_url:
                print 'Redirecting to:', redir_url
                return redirect_client_prg(url=redir_url)

            return redirect_client_prg('main_view_page')

        else:
            return _login_fail()

    # Not logged in?
    # Render login page, and store
    # current URL in beaker session.
    if not loggedin():
        print 'Not logged in, storing session data:', request.base_url
        session['login_redirect_url'] = request.base_url

        return pyro_render_template('loginform.html')

    # User already loggedin, redirect to main page.
    else:
        return redirect_client('main_view_page')
def handle_login():
    print 'Handle das login'
    #tmpl = jinjaenv.get_template('loginform.html')
    _login_fail = lambda: pyro_render_template('loginform.html', loginfail=True)
    print 'Request method:', request.method

    if request.method == 'POST':
        if 'user' not in request.form or 'pass' not in request.form:
            return _login_fail()

        user = request.form['user']
        passwd = request.form['pass']

#        pass = hashlib.sha256(pass).hexdigest()
        u = lookup_user(user)
        if u is None:
            return _login_fail()

        if u.password == passwd:
            print 'Login succes.'
            session['user_name'] = user

            # Redirect user to original page, or if not possible
            # to the main page.
            redir_url = session.pop('login_redirect_url', None)
            if redir_url:
                print 'Redirecting to:', redir_url
                return redirect_client_prg(url=redir_url)

            return redirect_client_prg('main_view_page')

        else:
            return _login_fail()

    # Not logged in?
    # Render login page, and store
    # current URL in beaker session.
    if not loggedin():
        print 'Not logged in, storing session data:', request.base_url
        session['login_redirect_url'] = request.base_url

        return pyro_render_template('loginform.html')

    # User already loggedin, redirect to main page.
    else:
        return redirect_client('main_view_page')