Esempio n. 1
0
 def process_request(self, request):
     if not request.path.startswith('/api/') and settings.FORCE_SSL_LOGIN and request.method == 'GET':
         is_secure = request.META.get('SERVER_PORT') == '443'
         need_secure = any(request.path.startswith(reverse(p)) for p in self.SECURE_PREFIXES)
         if is_secure ^ need_secure:
             secure_url = make_absolute_url(request.build_absolute_uri(), secure=need_secure)
             return HttpResponseRedirect(secure_url)
Esempio n. 2
0
def new_user_registered_url(request, next):
    is_oauth = getattr(request, 'is_oauth', True)
    if not is_oauth:
        profile = request.unique_user.id and request.unique_user.get_profile()
        if profile and profile.has_recommendations():
            next = reverse('main_page')
        else:
            next = reverse('rate_films')
    return make_absolute_url(next or '/')
Esempio n. 3
0
 def _check(request, *args, **kw):
     if request.user.is_authenticated() and not 'ajax' in request.GET:
         profile = request.user.get_profile()
         url = abs_reverse('edit_location') + '?' + urlencode({'next':make_absolute_url(request.path_info)})
         if not profile.has_location():
             messages.add_message(request, messages.WARNING, _("Your location is not set. Change it <a href='%s'>here</a>.") % url)
         elif profile.location_changed(request.geo):
             messages.add_message(request, messages.INFO, _("Your location may be inaccurate. Check <a href='%s'>settings</a>.") % url)
     return view(request, *args, **kw) 
Esempio n. 4
0
def login(request):
    reason = None
    next = request.REQUEST.get('next', '')

    if request.method == "POST":
        openidform = OpenIDForm(request.POST)
        def openid_failure(request,message):
          return direct_to_template(request, "account/login.html", {
            "form": LoginForm(),
            "openidform": openidform,
            "openid_message":message,
            "reason": reason,
          })

        def if_not_user_url(request):
          return HttpResponseRedirect(reverse('acct_login'))

        if request.POST.has_key('openid_url'):
            redirect_to = '/openid/complete/'
            if next:
                logger.info("NEXT: %s", next)
                redirect_to += '?' + urlencode({'next':next})
            return openid_consumer_views.begin(request,on_failure=openid_failure,sreg = 'email,nickname',redirect_to=redirect_to, if_not_user_url=if_not_user_url)
          
        form = LoginForm(request.POST)
        redirect_to = None
        if form.login(request):	                
            return HttpResponseRedirect(make_absolute_url(next or '/'))
    else:        
        # http://jira.filmaster.org/browse/FLM-420
        full_next = FULL_DOMAIN + next
        if next == full_url("LOGOUT") or full_next == full_url("LOGOUT"):
            next = ""
        reason = request.GET.get('reason')
            
        form = LoginForm(
            initial = {
                'next': next,
                'reason': reason,
        })

        openidform = OpenIDForm(
            initial = {
                'next': next,
                'reason': reason,
        })
        
    return direct_to_template(request, "account/login.html", {
        "next": next,
        "form": form,
        "openidform": openidform,
        "reason": reason, 
    })
Esempio n. 5
0
 def process_request(self, request):
     if not request.path.startswith(
             '/api/'
     ) and settings.FORCE_SSL_LOGIN and request.method == 'GET':
         is_secure = request.META.get('SERVER_PORT') == '443'
         need_secure = any(
             request.path.startswith(reverse(p))
             for p in self.SECURE_PREFIXES)
         if is_secure ^ need_secure:
             secure_url = make_absolute_url(request.build_absolute_uri(),
                                            secure=need_secure)
             return HttpResponseRedirect(secure_url)
Esempio n. 6
0
 def _check(request, *args, **kw):
     if request.user.is_authenticated() and not 'ajax' in request.GET:
         profile = request.user.get_profile()
         url = abs_reverse('edit_location') + '?' + urlencode(
             {'next': make_absolute_url(request.path_info)})
         if not profile.has_location():
             messages.add_message(
                 request, messages.WARNING,
                 _("Your location is not set. Change it <a href='%s'>here</a>."
                   ) % url)
         elif profile.location_changed(request.geo):
             messages.add_message(
                 request, messages.INFO,
                 _("Your location may be inaccurate. Check <a href='%s'>settings</a>."
                   ) % url)
     return view(request, *args, **kw)
Esempio n. 7
0
def signup(request):
    reason = None
    next = get_next(request)
    iframe = 'iframe' in request.GET
    template = "account/%ssignup.html" % (iframe and 'iframe_' or '')
    
    if request.method == "POST":
        openidform = OpenIDForm(request.POST)
        def openid_failure(request,message):
            return direct_to_template(request, template, {
                "form": SignupForm(request=request),
                "openidform": openidform,
                "openid_message":message,
                "next":next,
                "reason": reason,
            })

        def if_not_user_url(request):
            return HttpResponseRedirect(reverse('acct_login'))

        if request.POST.has_key('openid_url'):
            from urllib import urlencode
            return openid_consumer_views.begin(request,on_failure=openid_failure,sreg = 'email,nickname',redirect_to='/openid/complete/?%s'%urlencode({'next':next or '/'}), if_not_user_url=if_not_user_url)
            
        form = SignupForm(request.POST, request=request, prefix=iframe and 'ajax' or None)
        if form.is_valid():
            user = form.save()
            user = authenticate(username=user.username, password=form.cleaned_data['password1'])
            auth_login(request, user)
            if iframe:
                return HttpResponse('<script>top.location.href = "%s";</script>' % make_absolute_url(next or '/'))
            return new_user_registered_redirect(request, next or '/')
    else:
        form = SignupForm(request=request, prefix=iframe and 'ajax' or None)
    openidform = OpenIDForm(
        initial = {
            'next': next,
            'reason': reason,
    })
    return direct_to_template(request, template, {
        "form": form,
        "next": next,
        "openidform": openidform,
    })
Esempio n. 8
0
class ANode(template.Node):
    def __init__(self, view, args, kwargs, nodelist, match_prefix=False):
        self.view = view
        self.args = args
        self.kwargs = kwargs
        self.nodelist = nodelist
        if match_prefix:
            self.match_func = lambda a, b: a.startswith(b)
        else:
            self.match_func = lambda a, b: a == b

    def render(self, context):
        from django.utils.http import urlquote
        args = [arg.resolve(context) for arg in self.args]
        kwargs = dict([(smart_str(k, 'ascii'), v.resolve(context))
                       for k, v in self.kwargs.items()])

        try:
            path = reverse(self.view, args=args, kwargs=kwargs)
            qpath = urlquote(path)
        except NoReverseMatch, e:
            raise e

        request = context.get('request')
        if request and any(
                self.match_func(urlquote(p), path)
                for p in (request.path, request.path_info)):
            cls = ' class="selected"'
        else:
            cls = ''

        out = ['<a href="%s"%s>' % (make_absolute_url(path), cls)]
        out.append(self.nodelist.render(context))
        out.append('</a>')

        return ''.join(out)
Esempio n. 9
0
class URLNode(template.Node):
    def __init__(self,
                 view_name,
                 args,
                 kwargs,
                 asvar,
                 legacy_view_name=True,
                 absolute=True):
        self.view_name = view_name
        self.legacy_view_name = legacy_view_name
        self.args = args
        self.kwargs = kwargs
        self.asvar = asvar
        self.absolute = absolute

    def render(self, context):
        args = [arg.resolve(context) for arg in self.args]
        kwargs = dict([(smart_str(k, 'ascii'), v.resolve(context))
                       for k, v in self.kwargs.items()])

        view_name = self.view_name
        if not self.legacy_view_name:
            view_name = view_name.resolve(context)

        # Try to look up the URL twice: once given the view name, and again
        # relative to what we guess is the "main" app. If they both fail,
        # re-raise the NoReverseMatch unless we're using the
        # {% url ... as var %} construct in which cause return nothing.
        url = ''
        try:
            url = reverse(view_name,
                          args=args,
                          kwargs=kwargs,
                          current_app=context.current_app)
        except NoReverseMatch, e:
            if settings.SETTINGS_MODULE:
                project_name = settings.SETTINGS_MODULE.split('.')[0]
                try:
                    url = reverse(project_name + '.' + view_name,
                                  args=args,
                                  kwargs=kwargs,
                                  current_app=context.current_app)
                except NoReverseMatch:
                    if self.asvar is None:
                        # Re-raise the original exception, not the one with
                        # the path relative to the project. This makes a
                        # better error message.
                        raise e
            else:
                if self.asvar is None:
                    raise e

        if self.absolute:
            request = context.get('request')
            secure = request and request.META.get('SERVER_PORT') == '443'
            url = make_absolute_url(url, secure)

        if self.asvar:
            context[self.asvar] = url
            return ''
        else:
            return url
Esempio n. 10
0
 def get_absolute_url(self):
     return make_absolute_url(self.get_slug())
Esempio n. 11
0
 def get_object_url(self):
     assert self.object_slug
     return make_absolute_url(self.object_slug)
Esempio n. 12
0
 def get_absolute_url(self):
     slug = self.get_slug()
     if slug:
         return make_absolute_url(slug)
     return self.permalink
Esempio n. 13
0
 def get_object_url(self):
     assert self.object_slug
     return make_absolute_url(self.object_slug)
Esempio n. 14
0
 def get_absolute_url(self):
     slug = self.get_slug()
     if slug:
         return make_absolute_url(slug)
     return self.permalink