예제 #1
0
    def post_logout(self, came_from=lurl('/')):
        """
        Redirect the user to the initially requested page on logout and say
        goodbye as well.

        """
        flash('Ciawa asd!')
        return HTTPFound(location=came_from)
예제 #2
0
파일: root.py 프로젝트: puria/ksweb
 def post_login(self, came_from=lurl("/")):
     if not request.identity:
         login_counter = request.environ.get("repoze.who.logins", 0) + 1
         redirect("/login",
                  params=dict(came_from=came_from, __logins=login_counter))
     userid = request.identity["repoze.who.userid"]
     flash(_("Welcome back, %s!") % userid)
     return HTTPFound(location=came_from)
예제 #3
0
 def post_login(self, came_from=lurl('/')):
     if not request.identity:
         login_counter = request.environ.get('repoze.who.logins', 0) + 1
         redirect('/login',
                  params=dict(came_from=came_from, __logins=login_counter))
     userid = request.identity['repoze.who.userid']
     flash(_('Welcome back, %s!') % userid)
     return HTTPFound(location=came_from)
예제 #4
0
    def post_logout(self, came_from=lurl('/')):
        """
        Redirect the user to the initially requested page on logout and say
        goodbye as well.

        """
        flash(_('We hope to see you soon!'))
        return HTTPFound(location=came_from)
 def subscribe(self,
               came_from=lurl('/mailinglist'),
               ml_username=None,
               ml_fullname=None):
     """subscribe(came_from=tg.lurl('/mailinglist'), ml_username=None, ml_fullname=None)"""
     try:
         app_globals.mmadmin.mymail_subscribe(ml_username, ml_fullname)
         flash("Successfully subscribed to mailing list")
     except Exception as e:
         flash("An error occurred: {}".format(e), 'error')
     return HTTPFound(location=came_from)
예제 #6
0
def test_HTTPFound_without_location():
    exc = HTTPFound(add_slash=True)
 
    def _fake_start_response(*args, **kw):
        pass

    resp = exc({'PATH_INFO':'/here',
                'wsgi.url_scheme': 'HTTP',
                'REQUEST_METHOD': 'GET',
                'SERVER_NAME': 'localhost',
                'SERVER_PORT': '80'}, _fake_start_response)
    assert b'resource was found at http://localhost:80/here/' in resp[0]
예제 #7
0
def test_lurl_as_HTTPFound_location():
    create_request('/')
    exc = HTTPFound(location=lurl('/lurl'))

    def _fake_start_response(*args, **kw):
        pass

    resp = exc({'PATH_INFO':'/',
                'wsgi.url_scheme': 'HTTP',
                'REQUEST_METHOD': 'GET',
                'SERVER_NAME': 'localhost',
                'SERVER_PORT': '80'}, _fake_start_response)
    assert b'resource was found at http://localhost:80/lurl' in resp[0]
예제 #8
0
 def post_login(self, came_from=lurl('/'), *args, **kwargs):
     """
     Redirect the user to the initially requested page on successful
     authentication or redirect her back to the login page if login failed.
     """
     if not request.identity:
         login_counter = request.environ.get('repoze.who.logins', 0) + 1
         redirect('/login',
                  params=dict(came_from=came_from, __logins=login_counter))
     user = request.user
     flash(_('Welcome back, %s!') % user.display_name)
     # Do not use tg.redirect with tg.url as it will add the mountpoint
     # of the application twice.
     return HTTPFound(location=str(came_from))
예제 #9
0
    def post_login(self, came_from=lurl('/')):
        """
        Redirect the user to the initially requested page on successful
        authentication or redirect her back to the login page if login failed.

        """

        if not request.identity:
            redirect('/index', params=dict(came_from=came_from))

        model.History.add_record(request.identity['repoze.who.userid'], None,
                                 "Вход в аккаунт")

        return HTTPFound(location=came_from)
예제 #10
0
def redirect(*args, **kwargs):
    """Generate an HTTP redirect.

    The function raises an exception internally,
    which is handled by the framework. The URL may be either absolute (e.g.
    http://example.com or /myfile.html) or relative. Relative URLs are
    automatically converted to absolute URLs. Parameters may be specified,
    which are appended to the URL. This causes an external redirect via the
    browser; if the request is POST, the browser will issue GET for the
    second request.
    """

    new_url = url(*args, **kwargs)
    found = HTTPFound(location=new_url).exception
    raise found
예제 #11
0
 def challenge(self, environ, status, app_headers, forget_headers):
     """
     Provide ``IChallenger`` interface.
     """
     challenger = environ.get('repoze.who.challenge')
     if challenger != 'glogin':
         return None
     request = Request(environ)
     self.flow.redirect_uri = f"{request.application_url}/post_login"
     auth_url, state = self.flow.authorization_url()
     headers = [
         ('Location', auth_url),
         *forget_headers,
         *((h, v) for h, v in app_headers if h.lower() == 'set-cookie'),
     ]
     return HTTPFound(headers=headers)
예제 #12
0
파일: auth.py 프로젝트: edwargix/algobowl-1
 def challenge(self, environ, status, app_headers, forget_headers):
     """
     Provide ``IChallenger`` interface.
     """
     request = Request(environ)
     return_url = tg.url(
         request.application_url + '/post_login',
         {'came_from': request.path_qs})
     headers = [
         ('Location',
             '{}?{}'.format(
                 self.mpapi_sso,
                 urlencode({'return': return_url}))),
         *forget_headers,
         *((h, v) for h, v in app_headers if h.lower() == 'set-cookie')]
     return HTTPFound(headers=headers)
예제 #13
0
    def create_from_parameters(self):
        """Create box from given parameters."""

        num_of_copies = int(request.POST['num-of-copies'])
        box_name = request.POST['box-name']
        vagrantfile = request.POST['vagrantfile-text']

        for _ in range(num_of_copies):
            box_id = BoxEngine.create_box_from_parameters(
                box_name, request.identity['repoze.who.userid'],
                str(vagrantfile))

            model.History.add_record(
                request.identity['repoze.who.userid'], box_id,
                "Создание виртуальной среды #" + str(box_id))

        return HTTPFound(location='/box/list/')
예제 #14
0
    def authenticate(self, environ, identity):
        login = identity['login']
        user = self.sa_auth.dbsession.query(
            self.sa_auth.user_class).filter_by(user_name=login).first()

        if not user:
            # Was it a valid MultiPass login? If so, register an account.
            if auth(login, identity['password']):
                info = uidinfo(login)
                user = User(user_id=info["uidNumber"],
                            user_name=login,
                            display_name="{} {}".format(
                                info["first"], info["sn"]))
                self.sa_auth.dbsession.add(user)
                self.sa_auth.dbsession.flush()
                transaction.commit()
            else:
                login = None
        elif not user.validate_password(identity['password']):
            login = None

        if login is None:
            try:
                from urllib.parse import parse_qs, urlencode
            except ImportError:
                from urlparse import parse_qs
                from urllib import urlencode
            from tg.exceptions import HTTPFound

            params = parse_qs(environ['QUERY_STRING'])
            params.pop('password',
                       None)  # Remove password in case it was there
            if user is None:
                params['failure'] = 'user-not-found'
            else:
                params['login'] = identity['login']
                params['failure'] = 'invalid-password'

            # When authentication fails send user to login page.
            environ['repoze.who.application'] = HTTPFound(
                location=environ['SCRIPT_NAME'] +
                '?'.join(('/login', urlencode(params, True))))

        return login
예제 #15
0
    def authenticate(self, environ, identity):
        login = identity['login']
        password = identity['password']
        server = environ['webob._parsed_post_vars'][0]['server']

        user = self.sa_auth.dbsession.query(
            self.sa_auth.user_class).filter_by(user_name=login).first()

        if not user:
            self._add_manager(login, password, server)
        ## elif not user.validate_password(identity['password']):
        else:
            self._update_manager(login, password, server)

        user = self.sa_auth.dbsession.query(
            self.sa_auth.user_class).filter_by(user_name=login).first()

        if login is None:
            try:
                from urllib.parse import parse_qs, urlencode
            except ImportError:
                from urlparse import parse_qs
                from urllib import urlencode
            from tg.exceptions import HTTPFound

            params = parse_qs(environ['QUERY_STRING'])
            params.pop('password',
                       None)  # Remove password in case it was there
            if user is None:
                params['failure'] = 'user-not-found'
            else:
                params['login'] = identity['login']
                params['failure'] = 'invalid-password'

            # When authentication fails send user to login page.
            environ['repoze.who.application'] = HTTPFound(
                location=environ['SCRIPT_NAME'] +
                '?'.join(('/login', urlencode(params, True))))
        return login
예제 #16
0
    def authenticate(self, environ, identity):
        login = identity['login']
        activated = model.User.is_activated(login)
        user = self.sa_auth.dbsession.query(
            self.sa_auth.user_class).filter_by(user_name=login).first()

        if not user:
            login = None
        if not activated:
            login = None
        elif not user.validate_password(identity['password']):
            login = None

        if login is None:
            try:
                from urllib.parse import parse_qs, urlencode
            except ImportError:
                from urlparse import parse_qs
                from urllib import urlencode
            from tg.exceptions import HTTPFound

            params = parse_qs(environ['QUERY_STRING'])
            params.pop('password',
                       None)  # Remove password in case it was there
            if user is None:
                params['failure'] = 'user-not-found'
            elif not activated:
                params['login'] = identity['login']
                params['failure'] = 'user-not-verified'
            else:
                params['login'] = identity['login']
                params['failure'] = 'invalid-password'

            # When authentication fails send user to login page.
            environ['repoze.who.application'] = HTTPFound(
                location=environ['SCRIPT_NAME'] +
                '?'.join(('/login', urlencode(params, True))))

        return login
예제 #17
0
    def authenticate(self, environ, identity):
        login = identity['login']
        # user = self.sa_auth.dbsession.query(self.sa_auth.user_class).filter_by(
        #     user_name=login).first()
        user = self.sa_auth.dbsession.query(self.sa_auth.user_class).filter(
            or_(self.sa_auth.user_class.user_name == login,
                self.sa_auth.user_class.email_address == login)).first()

        if not user:
            login = None
        elif not user.validate_password(identity['password']):
            login = None

        if login is None:
            try:
                from urllib.parse import parse_qs, urlencode
            except ImportError:
                from urlparse import parse_qs
                from urllib import urlencode
            from tg.exceptions import HTTPFound

            params = parse_qs(environ['QUERY_STRING'])
            params.pop('password',
                       None)  # Remove password in case it was there
            if user is None:
                params['failure'] = 'user-not-found'
            else:
                params['login'] = identity['login']
                params['failure'] = 'invalid-password'

            # When authentication fails send user to login page.
            environ['repoze.who.application'] = HTTPFound(
                location=environ['SCRIPT_NAME'] +
                '?'.join(('/login', urlencode(params, True))))
        # returning the username anyways since identity['repoze.who.userid']
        # will be set by repoze.who.api._authenticate to this returned value
        loginuser = user.user_name
        return loginuser
예제 #18
0
    def post_login(self, came_from=lurl('/')):
        """
        Redirect the user to the initially requested page on successful
        authentication or redirect her back to the login page if login failed.

        """
        if not request.identity:
            login_counter = request.environ.get('repoze.who.logins', 0) + 1
            redirect('/login',
                     params=dict(came_from=came_from, __logins=login_counter))
        userid = request.identity['repoze.who.userid']
        try:
            self.data.fetch_user_data()
        except AssertionError as ae:
            log.error("Failed to fetch server data: %s" % ae)
            redirect('/logout_handler')
        except Exception as e:
            log.error("Failed to fetch server data: %s" % e)
            redirect('/logout_handler',
                     params=dict(output="Failed to fetch server data: %s" % e))

        # Do not use tg.redirect with tg.url as it will add the mountpoint
        # of the application twice.
        return HTTPFound(location=came_from)
예제 #19
0
파일: root.py 프로젝트: zhou8827/blockmrs
 def portal(self):
     """Redirect the user to their portal."""
     return HTTPFound(location=lurl('/p/'))
예제 #20
0
    def post_logout(self, came_from=lurl('/')):
        """Redirect the user to the initially requested page on logout"""

        return HTTPFound(location=came_from)
예제 #21
0
def plug_redirect(pluggable_name, path, params=None):
    url = plug_url(pluggable_name, path, params)
    raise HTTPFound(location=url)
예제 #22
0
파일: root.py 프로젝트: eteamin/onlineluxe
 def post_logout(self, came_from=lurl('/')):
     return HTTPFound(location=came_from)
예제 #23
0
 def post_logout(self, came_from=lurl('/')):
     flash(_('We hope to see you soon!'))
     return HTTPFound(location=came_from)
예제 #24
0
 def logout(self):
     who_api = get_api(tg.request.environ)
     headers = who_api.logout()
     return HTTPFound(headers=headers)