예제 #1
0
파일: auth.py 프로젝트: hetznerZA/NIPAP
    def login(self):
        """ Show login form.
        """

        if request.method != 'POST':
            cfg = NipapConfig()
            try:
                c.welcome_message = cfg.get('www', 'welcome_message')
            except NoOptionError:
                pass

            return render('login.html')

        # Verify username and password.
        auth_fact = AuthFactory()
        auth = auth_fact.get_auth(request.params.get('username'), request.params.get('password'), 'nipap')
        if not auth.authenticate():
            c.error = 'Invalid username or password'
            return render('login.html')

        # Mark user as logged in
        session['user'] = auth.username
        session['full_name'] = auth.full_name
        session['current_vrfs'] = {}
        session.save()

        # Send user back to the page he originally wanted to get to
        if session.get('path_before_login'):
            redirect(session['path_before_login'])

        else:
            # if previous target is unknown just send the user to a welcome page
            redirect(url(controller='vrf', action='list'))
예제 #2
0
파일: auth.py 프로젝트: tobbez/NIPAP
    def login(self):
        """ Show login form.
        """

        if request.method != 'POST':
            cfg = NipapConfig()
            try:
                c.welcome_message = cfg.get('www', 'welcome_message')
            except NoOptionError:
                pass

            return render('login.html')

        # Verify username and password.
        auth_fact = AuthFactory()
        auth = auth_fact.get_auth(request.params.get('username'),
                                  request.params.get('password'), 'nipap')
        if not auth.authenticate():
            c.error = 'Invalid username or password'
            return render('login.html')

        # Mark user as logged in
        session['user'] = auth.username
        session['full_name'] = auth.full_name
        session['readonly'] = auth.readonly
        session['current_vrfs'] = {}
        session.save()

        # Send user back to the page he originally wanted to get to
        if session.get('path_before_login'):
            redirect(session['path_before_login'])

        else:
            # if previous target is unknown just send the user to a welcome page
            redirect(url(controller='prefix', action='list'))