Example #1
0
    def logged_in(self):
        # redirect if needed
        came_from = request.params.get('came_from', '')
        if h.url_is_local(came_from):
            return h.redirect_to(str(came_from))

        if c.user:
            context = None
            data_dict = {'id': c.user}

            user_dict = get_action('user_show')(context, data_dict)

            h.flash_success(_("%s is now logged in") %
                            user_dict['display_name'])
            return self.me()
        else:
            err = _('Login failed. Bad username or password.')
            if g.openid_enabled:
                err += _(' (Or if using OpenID, it hasn\'t been associated '
                         'with a user account.)')
            if h.asbool(config.get('ckan.legacy_templates', 'false')):
                h.flash_error(err)
                h.redirect_to(controller='user',
                              action='login', came_from=came_from)
            else:
                return self.login(error=err)
Example #2
0
def check_link(url):
    try:
        if not h.url_is_local(url):
            requests.head(url, timeout=2).raise_for_status()
    except Exception:
        return False
    return True
Example #3
0
    def logged_in(self):
        # redirect if needed
        came_from = request.params.get('came_from', '')
        if h.url_is_local(came_from):
            return h.redirect_to(str(came_from))

        if c.user:
            context = None
            data_dict = {'id': c.user}

            user_dict = get_action('user_show')(context, data_dict)

            return self.me()
        else:
            err = _('Login failed. Bad username or password.')
            if g.openid_enabled:
                err += _(' (Or if using OpenID, it hasn\'t been associated '
                         'with a user account.)')
            if h.asbool(config.get('ckan.legacy_templates', 'false')):
                h.flash_error(err)
                h.redirect_to(controller='user',
                              action='login',
                              came_from=came_from)
            else:
                return self.login(error=err)
Example #4
0
 def logged_out(self):
     # redirect if needed
     print "hahahahah"
     came_from = request.params.get('came_from', '')
     if h.url_is_local(came_from):
         return h.redirect_to(str(came_from))
     h.redirect_to(controller='user', action='logged_out_page')
    def logged_in(self):
        # redirect if needed
        came_from = request.params.get('came_from', '')

        if c.user:
            context = None
            data_dict = {'id': c.user}

            user_dict = get_action('user_show')(context, data_dict)

            user_ref = c.userobj.get_reference_preferred_for_uri()

            if h.url_is_local(came_from) and came_from != '/':
                return h.redirect_to(str(came_from))

            h.redirect_to(locale=None, controller='user', action='dashboard_datasets',
                      id=user_ref)
        else:
            err = _('Login failed. Wrong email or password.')
            if h.asbool(config.get('ckan.legacy_templates', 'false')):
                h.flash_error(err)
                h.redirect_to(controller='user',
                              action='login', came_from=came_from)
            else:
                return self.login(error=err)
Example #6
0
    def logged_in(self):
        # redirect if needed
        came_from = request.params.get('came_from', '')
        #FIXME uggly fix
        # did this change for /euodp path, the uggly fix is still to be fixed
        if '/user/logged_in' not in came_from and h.url_is_local(came_from):
            return h.redirect_to(str(came_from))
        if c.user:
            context = None
            data_dict = {'id': c.user}

            user_dict = get_action('user_show')(context, data_dict)

            h.flash_success(
                _("%s is now logged in") % user_dict['display_name'])
            return self.me()
        else:
            err = _('Login failed. Bad username or password.')
            if g.openid_enabled:
                err += _(' (Or if using OpenID, it hasn\'t been associated '
                         'with a user account.)')
            if h.asbool(config.get('ckan.legacy_templates', 'false')):
                log.error('[DB] logged_in not c.user' + came_from)
                h.flash_error(err)
                h.redirect_to(controller='user',
                              action='login',
                              came_from=came_from)
            else:
                return self.login(error=err)
Example #7
0
    def redirect(self):
        ''' redirect to the url parameter. '''
        url = base.request.params.get('url')
        if not url:
            base.abort(400, _('Missing Value') + ': url')

        if h.url_is_local(url) and '\r' not in url and '\n' not in url:
            return base.redirect(url)
        else:
            base.abort(403, _('Redirecting to external site is not allowed.'))
Example #8
0
    def redirect(self):
        ''' redirect to the url parameter. '''
        url = base.request.params.get('url')
        if not url:
            base.abort(400, _('Missing Value') + ': url')

        if h.url_is_local(url):
            return h.redirect_to(url)
        else:
            base.abort(403, _('Redirecting to external site is not allowed.'))
 def submit_terms(self):
     ua = UserAgreement()
     came_from = request.params.get('came_from', h.url('/'))
     if not came_from:
         base.abort(400, _('Missing Value') + ': url')
     if h.url_is_local(came_from):
         ua.insert_new_agreement()
         response.set_cookie('wprdc_user_terms', 'true')
         return base.redirect(came_from)
     else:
         base.abort(403, _('Redirecting to external site is not allowed.'))
Example #10
0
def logged_in():
    # redirect if needed
    came_from = request.params.get(u'came_from', u'')   

    if h.url_is_local(came_from) == False:
        return login(None)
    if g.user:
        return me()
    else:
        error = _(u'Login failed. Bad username or password.')
        return login(error)
Example #11
0
def logged_in():
    # redirect if needed
    came_from = request.params.get(u'came_from', u'')
    if h.url_is_local(came_from):
        return h.redirect_to(str(came_from))

    if g.user:
        return me()
    else:
        err = _(u'Login failed. Bad username or password.')
        h.flash_error(err)
        return login()
Example #12
0
def internal_redirect():
    u''' Redirect to the url parameter.
    Only internal URLs are allowed'''

    url = request.form.get(u'url') or request.args.get(u'url')
    if not url:
        base.abort(400, _(u'Missing Value') + u': url')

    if h.url_is_local(url):
        return h.redirect_to(url)
    else:
        base.abort(403, _(u'Redirecting to external site is not allowed.'))
Example #13
0
def logged_in():
    # redirect if needed
    came_from = request.params.get(u'came_from', u'')
    if h.url_is_local(came_from):
        return h.redirect_to(str(came_from))

    if g.user:
        return me()
    else:
        err = _(u'Login failed. Bad username or password.')
        h.flash_error(err)
        return login()
Example #14
0
def logged_in_override():
    """
    Override default CKAN behaviour to only redirect user to `came_from` URL if they are logged in.
    Ref.: ckan/views/user.py > def logged_in()
    :return:
    """
    if g.user:
        came_from = request.params.get(u'came_from', None)
        return redirect_to(six.text_type(
            came_from)) if came_from and h.url_is_local(came_from) else me()
    else:
        h.flash_error(_(u'Login failed. Bad username or password.'))
        return login()
Example #15
0
File: user.py Project: tino097/ckan
def logout() -> Response:
    for item in plugins.PluginImplementations(plugins.IAuthenticator):
        response = item.logout()
        if response:
            return response
    user = current_user.name
    if not user:
        return h.redirect_to('user.login')

    came_from = request.args.get('came_from', '')
    logout_user()

    if h.url_is_local(came_from):
        return h.redirect_to(str(came_from))

    return h.redirect_to('user.logged_out_page')
Example #16
0
    def logged_in(self):
        # redirect if needed
        came_from = request.params.get('came_from', '')
        if h.url_is_local(came_from):
            return h.redirect_to(str(came_from))

        if c.user:
            context = None
            data_dict = {'id': c.user}
            user_dict = get_action('user_show')(context, data_dict)

            # IAuthenticator too buggy, doing this instead
            try:
                token = tokens.token_show(context, user_dict)
            except NotFound, e:
                token = {'valid': True}  # Until we figure out what to do with existing users
            except:
Example #17
0
    def logged_in(self):
        came_from = http_request.params.get('came_from', '')
        if h.url_is_local(came_from):
            return h.redirect_to(str(came_from))

        if c.user:
            context = None
            data_dict = {'id': c.user}

            user_dict = get_action('user_show')(context, data_dict)
            user_ref = c.userobj.get_reference_preferred_for_uri()
            return h.redirect_to('/')
        else:
            err = 'Login failed. Bad username or password.'
            if  h.asbool(config.get('ckan.legacy_templates', 'false')):
                h.flash_error(err)
                h.redirect_to(controller='user',
                              action='login', came_from=came_from)
            else:
                return self.login(error=err)
Example #18
0
    def logged_in(self):
        # redirect if needed
        came_from = request.params.get("came_from", "")
        if h.url_is_local(came_from):
            return h.redirect_to(str(came_from))

        if c.user:
            context = None
            data_dict = {"id": c.user}

            user_dict = get_action("user_show")(context, data_dict)

            return self.me()
        else:
            err = _("Login failed. Bad username or password.")
            if h.asbool(config.get("ckan.legacy_templates", "false")):
                h.flash_error(err)
                h.redirect_to(controller="user", action="login", came_from=came_from)
            else:
                return self.login(error=err)
Example #19
0
File: user.py Project: ITMGR/ckan
    def logged_in(self):
        # redirect if needed
        came_from = request.params.get('came_from', '')
        if h.url_is_local(came_from):
            return h.redirect_to(str(came_from))

        if c.user:
            context = None
            data_dict = {'id': c.user}

            user_dict = get_action('user_show')(context, data_dict)

            return self.me()
        else:
            err = _('Login failed. Bad username or password.')
            if asbool(config.get('ckan.legacy_templates', 'false')):
                h.flash_error(err)
                h.redirect_to(controller='user',
                              action='login', came_from=came_from)
            else:
                return self.login(error=err)
Example #20
0
def logged_out():
    # redirect if needed
    came_from = request.params.get(u'came_from', u'')
    if h.url_is_local(came_from):
        return h.redirect_to(str(came_from))
    return h.redirect_to(u'user.logged_out_page')
Example #21
0
File: user.py Project: ITMGR/ckan
 def logged_out(self):
     # redirect if needed
     came_from = request.params.get('came_from', '')
     if h.url_is_local(came_from):
         return h.redirect_to(str(came_from))
     h.redirect_to(controller='user', action='logged_out_page')
Example #22
0
 def logged_out(self):
     # redirect if needed
     came_from = request.params.get("came_from", "")
     if h.url_is_local(came_from):
         return h.redirect_to(str(came_from))
     h.redirect_to(controller="user", action="logged_out_page")
Example #23
0
def logged_out():
    # redirect if needed
    came_from = request.params.get(u'came_from', u'')
    if h.url_is_local(came_from):
        return h.redirect_to(str(came_from))
    return h.redirect_to(u'user.logged_out_page')
Example #24
0
 def logged_out(self):
     # redirect if needed
     came_from = request.params.get('came_from', '')
     if h.url_is_local(came_from):
         return h.redirect_to(str(came_from), __ckan_no_root=True)
     h.redirect_to(controller='user', action='logged_out_page')
Example #25
0
File: user.py Project: tino097/ckan
def next_page_or_default(target: Optional[str]) -> Response:
    if target and h.url_is_local(target):
        return h.redirect_to(target)
    return me()