Re: Overwriting the login function
OK, I got it. You can't use the login_decorator to do what I'm trying to do. I"ve addded one simple line to the form, used the original auth/views.py and my original method of authentication and it all works fine. Misread the docs again. return HttpResponseRedirect('/accounts/login/?next=%s' % request.path) et voila On 08/08/07, Matt Davies <[EMAIL PROTECTED]> wrote: > > Ok, I'm now using the login_required decorator, much better > > one problem though, here's a snippet of a form > > http://pastie.caboo.se/85932 > > How do I check the IP prior to askign for a login check, and if the IP is > good, not ask for login? > > I'm stumped > > > > On 08/08/07, Matt Davies <[EMAIL PROTECTED]> wrote: > > > > Getting there. > > > > It's not setting the logged in as yes as it's not logging me in :-) > > > > This conditional in the login function in views > > > > if request.POST: > > > > is not getting a positive and it's falling through to the else which is > > setting errors to blank > > > > else: > > print 'balls' > > errors = {} > > request.session.set_test_cookie() > > return render_to_response(template_name, { > > 'form': oldforms.FormWrapper (manipulator, request.POST, > > errors), > > 'matts_back_to': redirect_to, > > > > 'site_name': Site.objects.get_current().name, > > }, context_instance=RequestContext(request)) > > > > which then throws me back to the page without logging me in at all, I > > can put any old rubbish into that form. > > I think I somehow need to make this part of the secured views do what I > > need, really not sure though. > > > > return HttpResponseRedirect("/accounts/login") > > > > > > > > > > On 08/08/07, Matt Davies <[EMAIL PROTECTED]> wrote: > > > > > > I've copied the /contrib/auth/views.py into my project and edited it > > > like so > > > > > > redirect_to = request.META["HTTP_REFERER"] > > > > > > return render_to_response(template_name, { > > > 'form': oldforms.FormWrapper (manipulator, request.POST, errors), > > > 'matts_back_to': redirect_to, > > > 'site_name': Site.objects.get_current().name, > > > > > > I've added in my login forms this as the action > > > > > > > > > > > > Now, when a user comes to a page that shows a view that has this in > > > the top > > > if request.user.is_authenticated(): > > > do all your stuff > > > else: > > > return HttpResponseRedirect("/accounts/login") > > > > > > If they're not logged in they get sent to directly to the login page, > > > they login and get sent back to the page they were trying to access > > > initially. > > > > > > This works fine, but for some reason the user is not being shown as > > > having logged in when they are returned to the initial page. If they try > > > to > > > access another secured page at that point, it asks them to login again, > > > and > > > also the login/logout button is showing as logged out. > > > > > > Anyone got any ideas why? > > > > > > If this is a really bad way to achieve what I want then please let me > > > know, it is a bit of a workaround I suppose. > > > > > > > > > > > > > > > > > > > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Overwriting the login function
Ok, I'm now using the login_required decorator, much better one problem though, here's a snippet of a form http://pastie.caboo.se/85932 How do I check the IP prior to askign for a login check, and if the IP is good, not ask for login? I'm stumped On 08/08/07, Matt Davies <[EMAIL PROTECTED]> wrote: > > Getting there. > > It's not setting the logged in as yes as it's not logging me in :-) > > This conditional in the login function in views > > if request.POST: > > is not getting a positive and it's falling through to the else which is > setting errors to blank > > else: > print 'balls' > errors = {} > request.session.set_test_cookie() > return render_to_response(template_name, { > 'form': oldforms.FormWrapper(manipulator, request.POST, errors), > 'matts_back_to': redirect_to, > > 'site_name': Site.objects.get_current().name, > }, context_instance=RequestContext(request)) > > which then throws me back to the page without logging me in at all, I can > put any old rubbish into that form. > I think I somehow need to make this part of the secured views do what I > need, really not sure though. > > return HttpResponseRedirect("/accounts/login") > > > > > On 08/08/07, Matt Davies <[EMAIL PROTECTED]> wrote: > > > > I've copied the /contrib/auth/views.py into my project and edited it > > like so > > > > redirect_to = request.META["HTTP_REFERER"] > > > > return render_to_response(template_name, { > > 'form': oldforms.FormWrapper (manipulator, request.POST, errors), > > 'matts_back_to': redirect_to, > > 'site_name': Site.objects.get_current().name, > > > > I've added in my login forms this as the action > > > > > > > > Now, when a user comes to a page that shows a view that has this in the > > top > > if request.user.is_authenticated(): > > do all your stuff > > else: > > return HttpResponseRedirect("/accounts/login") > > > > If they're not logged in they get sent to directly to the login page, > > they login and get sent back to the page they were trying to access > > initially. > > > > This works fine, but for some reason the user is not being shown as > > having logged in when they are returned to the initial page. If they try to > > access another secured page at that point, it asks them to login again, and > > also the login/logout button is showing as logged out. > > > > Anyone got any ideas why? > > > > If this is a really bad way to achieve what I want then please let me > > know, it is a bit of a workaround I suppose. > > > > > > > > > > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Overwriting the login function
Getting there. It's not setting the logged in as yes as it's not logging me in :-) This conditional in the login function in views if request.POST: is not getting a positive and it's falling through to the else which is setting errors to blank else: print 'balls' errors = {} request.session.set_test_cookie() return render_to_response(template_name, { 'form': oldforms.FormWrapper(manipulator, request.POST, errors), 'matts_back_to': redirect_to, 'site_name': Site.objects.get_current().name, }, context_instance=RequestContext(request)) which then throws me back to the page without logging me in at all, I can put any old rubbish into that form. I think I somehow need to make this part of the secured views do what I need, really not sure though. return HttpResponseRedirect("/accounts/login") On 08/08/07, Matt Davies <[EMAIL PROTECTED]> wrote: > > I've copied the /contrib/auth/views.py into my project and edited it like > so > > redirect_to = request.META["HTTP_REFERER"] > > return render_to_response(template_name, { > 'form': oldforms.FormWrapper (manipulator, request.POST, errors), > 'matts_back_to': redirect_to, > 'site_name': Site.objects.get_current().name, > > I've added in my login forms this as the action > > > > Now, when a user comes to a page that shows a view that has this in the > top > if request.user.is_authenticated(): > do all your stuff > else: > return HttpResponseRedirect("/accounts/login") > > If they're not logged in they get sent to directly to the login page, they > login and get sent back to the page they were trying to access initially. > > This works fine, but for some reason the user is not being shown as having > logged in when they are returned to the initial page. If they try to access > another secured page at that point, it asks them to login again, and also > the login/logout button is showing as logged out. > > Anyone got any ideas why? > > If this is a really bad way to achieve what I want then please let me > know, it is a bit of a workaround I suppose. > > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Overwriting the login function
I've copied the /contrib/auth/views.py into my project and edited it like so redirect_to = request.META["HTTP_REFERER"] return render_to_response(template_name, { 'form': oldforms.FormWrapper(manipulator, request.POST, errors), 'matts_back_to': redirect_to, 'site_name': Site.objects.get_current().name, I've added in my login forms this as the action Now, when a user comes to a page that shows a view that has this in the top if request.user.is_authenticated(): do all your stuff else: return HttpResponseRedirect("/accounts/login") If they're not logged in they get sent to directly to the login page, they login and get sent back to the page they were trying to access initially. This works fine, but for some reason the user is not being shown as having logged in when they are returned to the initial page. If they try to access another secured page at that point, it asks them to login again, and also the login/logout button is showing as logged out. Anyone got any ideas why? If this is a really bad way to achieve what I want then please let me know, it is a bit of a workaround I suppose. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---