示例#1
0
    def post_login(self):
        """ Handle logic post a user's login

        I want to create a login_handler that's redirected to after login. This
        would check

        - if user was logged in, if not then send back to login
        - if user is admin, go to job list
        - if user can add joblist then go to *
        - if user is read only go to job list that's trimmed down a bit

        On the post login page adjust the max age on the existing cookie to XX
        remember me timeframe
        """
        if auth.check(not_anonymous()):
            log.debug('checked auth')
        else:
            # login failed, redirect back to login
            log.debug('failed auth')
            redirect(url(controller="accounts",
                action="login",
                login_failed=True)
            )

        # expire this cookie into the future
        ck = request.cookies['authtkt']
        response.set_cookie('authtkt', ck,
                max_age=60 * 60 * 24 * 7,
                path='/'
        )

        redirect(url('/page/test'))
示例#2
0
    def post_login(self):
        """ Handle logic post a user's login

        I want to create a login_handler that's redirected to after login. This
        would check

        - if user was logged in, if not then send back to login
        - if user is admin, go to job list
        - if user can add joblist then go to *
        - if user is read only go to job list that's trimmed down a bit

        On the post login page adjust the max age on the existing cookie to XX
        remember me timeframe
        """
        if auth.check(not_anonymous()):
            log.debug('checked auth')
        else:
            # login failed, redirect back to login
            log.debug('failed auth')
            redirect(
                url(controller="accounts", action="login", login_failed=True))

        # expire this cookie into the future
        ck = request.cookies['authtkt']
        response.set_cookie('authtkt', ck, max_age=60 * 60 * 24 * 7, path='/')

        redirect(url('/page/test'))
示例#3
0
    def login(self):
        """This is where the login form should be rendered."""
        if auth.check(not_anonymous()):
            # if we're not anonymous then we're logged in and need to be
            # redirected
            log.debug('already logged in')
            redirect(url('/page/test'))

        # Without the login counter, we won't be able to tell if the user has
        # tried to log in with the wrong credentials
        if 'repoze.who.logins' in request.environ:
            login_counter = request.environ['repoze.who.logins']
        else:
            login_counter = 0

        if login_counter > 0:
            log.debug('Wrong Login credentials')
            #flash('Wrong credentials')
        tpl.login_counter = login_counter
        tpl.came_from = request.params.get('came_from') or url('/')

        if 'login_failed' in request.params:
            tpl.login_failed = True
        else:
            tpl.login_failed = False
        return render('/login.mako')
示例#4
0
    def login(self):
        """This is where the login form should be rendered."""
        if auth.check(not_anonymous()):
            # if we're not anonymous then we're logged in and need to be
            # redirected
            log.debug('already logged in')
            redirect(url('/page/test'))

        # Without the login counter, we won't be able to tell if the user has
        # tried to log in with the wrong credentials
        if 'repoze.who.logins' in request.environ:
            login_counter = request.environ['repoze.who.logins']
        else:
            login_counter = 0

        if login_counter > 0:
            log.debug('Wrong Login credentials')
            #flash('Wrong credentials')
        tpl.login_counter = login_counter
        tpl.came_from = request.params.get('came_from') or url('/')

        if 'login_failed' in request.params:
            tpl.login_failed = True
        else:
            tpl.login_failed = False
        return render('/login.mako')