Login Required Middleware

2012-07-30 Thread Blaxton
Hi

I am trying to use login required middleware in a project
and followed every step mentioned on following url ,
but its just not working.

http://djangosnippets.org/snippets/1179/

placed the above middleware in myproject/middleware.py

added following lines to settings.py
LOGIN_URL = '/'
MIDDLEWARE_CLASSES = (

'myproject.middleware.LoginRequiredMiddleware'
)

django.core.context_processors.auth is changed to
django.contrib.auth.context_processors.auth

and it is in global_settings.py.

but still it wont forward the anonymouse users to login page which is '/'

Thanks

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



AW: login-required

2011-02-14 Thread Szabo, Patrick (LNG-VIE)
I've already read those papers, but it still helped...it works now ;-)
Thanks a lot !

Kind regards


. . . . . . . . . . . . . . . . . . . . . . . . . .
Patrick Szabo
 XSLT-Entwickler 
LexisNexis
Marxergasse 25, 1030 Wien

mailto:patrick.sz...@lexisnexis.at
Tel.: +43 (1) 534 52 - 1573 
Fax: +43 (1) 534 52 - 146 


-Ursprüngliche Nachricht-

Von: django-users@googlegroups.com [mailto:django-users@googlegroups.com] Im 
Auftrag von Martin Melin
Gesendet: Montag, 14. Februar 2011 09:45
An: django-users@googlegroups.com
Betreff: Re: login-required

On Mon, Feb 14, 2011 at 9:40 AM, Szabo, Patrick (LNG-VIE)
<patrick.sz...@lexisnexis.at> wrote:
> Hi,
>
> I've tried using the @login_required decorator to limit acces to a
> certain view.
> This worked fine.
> Unfortunately in the template that you are redirected to if the login
> was succesfull I don't have acces to any information like username oder
> alike.
>
> How do I realize that ?!
>

I'm assuming your question is how you can access the logged-in user's
information in subsequent views and templates. If I've misunderstood
your question please let me know.

You need to make sure that you have the Session and Authentication
middlewares installed. Have a look at this link:

http://docs.djangoproject.com/en/dev/topics/auth/#authentication-in-web-requests

Best regards,
Martin Melin

> For the login template i used the example shown in the documentation.
>
> My template looks like this:
>
> {% extends "main/base_site.html" %}
> {% block content %}
>  TEST 
> ...
> {% firstof request.user.id %}
> ...
> {% endblock %}
>
> Kind regards
>
> . . . . . . . . . . . . . . . . . . . . . . . . . .
> Patrick Szabo
>  XSLT-Entwickler
> LexisNexis
> Marxergasse 25, 1030 Wien
>
> mailto:patrick.sz...@lexisnexis.at
> Tel.: +43 (1) 534 52 - 1573
> Fax: +43 (1) 534 52 - 146

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: login-required

2011-02-14 Thread Martin Melin
On Mon, Feb 14, 2011 at 9:40 AM, Szabo, Patrick (LNG-VIE)
 wrote:
> Hi,
>
> I've tried using the @login_required decorator to limit acces to a
> certain view.
> This worked fine.
> Unfortunately in the template that you are redirected to if the login
> was succesfull I don't have acces to any information like username oder
> alike.
>
> How do I realize that ?!
>

I'm assuming your question is how you can access the logged-in user's
information in subsequent views and templates. If I've misunderstood
your question please let me know.

You need to make sure that you have the Session and Authentication
middlewares installed. Have a look at this link:

http://docs.djangoproject.com/en/dev/topics/auth/#authentication-in-web-requests

Best regards,
Martin Melin

> For the login template i used the example shown in the documentation.
>
> My template looks like this:
>
> {% extends "main/base_site.html" %}
> {% block content %}
>  TEST 
> ...
> {% firstof request.user.id %}
> ...
> {% endblock %}
>
> Kind regards
>
> . . . . . . . . . . . . . . . . . . . . . . . . . .
> Patrick Szabo
>  XSLT-Entwickler
> LexisNexis
> Marxergasse 25, 1030 Wien
>
> mailto:patrick.sz...@lexisnexis.at
> Tel.: +43 (1) 534 52 - 1573
> Fax: +43 (1) 534 52 - 146

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



login-required

2011-02-14 Thread Szabo, Patrick (LNG-VIE)
Hi, 

I've tried using the @login_required decorator to limit acces to a
certain view.
This worked fine.
Unfortunately in the template that you are redirected to if the login
was succesfull I don't have acces to any information like username oder
alike.

How do I realize that ?!

For the login template i used the example shown in the documentation.

My template looks like this:

{% extends "main/base_site.html" %}
{% block content %}
 TEST 
...
{% firstof request.user.id %}
...
{% endblock %}

Kind regards

. . . . . . . . . . . . . . . . . . . . . . . . . .
Patrick Szabo
 XSLT-Entwickler 
LexisNexis
Marxergasse 25, 1030 Wien

mailto:patrick.sz...@lexisnexis.at
Tel.: +43 (1) 534 52 - 1573 
Fax: +43 (1) 534 52 - 146 





-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: login required

2009-09-09 Thread Jeff Green
I would think you could just extend the User model to store the registered
users and then check if the user is registered which would then redirect to
the survey page.

On Tue, Sep 8, 2009 at 11:30 PM, putih  wrote:

>
> hii,
>
> need your help on this matter :-
>
> 1. how to restrict user for certain page. for example :-
>
> non-register user have to register first before they can join a
> survey. after register, they login and redirect to the survey page.
> (not main page.)
>
> anyone, please advise me on this problem. seriously i didn't have any
> ideas on this matter..
>
> thanks
> >
>

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: login required

2009-09-08 Thread putih

ok thanks .. i have use this tutorial but i a lot of errors comes in..
mayb need to understand for python code first. btw, thanks again

On Sep 9, 1:08 am, "ristretto.rb"  wrote:
> Have you not had a peek in here yet?
>
> http://docs.djangoproject.com/en/dev/topics/auth/#topics-auth
>
> gene
>
> On Sep 9, 4:30 pm, putih  wrote:
>
> > hii,
>
> > need your help on this matter :-
>
> > 1. how to restrict user for certain page. for example :-
>
> > non-register user have to register first before they can join a
> > survey. after register, they login and redirect to the survey page.
> > (not main page.)
>
> > anyone, please advise me on this problem. seriously i didn't have any
> > ideas on this matter..
>
> > thanks
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: login required

2009-09-08 Thread ristretto.rb

Have you not had a peek in here yet?

http://docs.djangoproject.com/en/dev/topics/auth/#topics-auth

gene


On Sep 9, 4:30 pm, putih  wrote:
> hii,
>
> need your help on this matter :-
>
> 1. how to restrict user for certain page. for example :-
>
> non-register user have to register first before they can join a
> survey. after register, they login and redirect to the survey page.
> (not main page.)
>
> anyone, please advise me on this problem. seriously i didn't have any
> ideas on this matter..
>
> thanks
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



login required

2009-09-08 Thread putih

hii,

need your help on this matter :-

1. how to restrict user for certain page. for example :-

non-register user have to register first before they can join a
survey. after register, they login and redirect to the survey page.
(not main page.)

anyone, please advise me on this problem. seriously i didn't have any
ideas on this matter..

thanks
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Testing login required views

2008-05-21 Thread Adam Gomaa

On Tue, May 20, 2008 at 9:19 PM, Julien <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I have a site where pretty much all views (except for register, login
> and logout) require the user to log in. Now that the number of views
> has grown I'd like to test that I didn't forget to protect them with
> the login_required decorator.
>
> I'm looking for an automated way to do that. Is that achievable, and
> if so, how?
>
> I've started looking into unit testing but I'm struggling a bit and
> I'm not sure if that could do the trick. What I'd like to do is test
> all possible urls from the URLConf and spot those that are not
> redirected to the login page.
>
> Any hint?

Julien, I'd just use 'grep' for this:

grep -A 2 -R --include="*.py"  -E "^def .*\(req" ./

That'll show two lines above a view definition - so just look for any
that are missing @login_required.

Course, that's hardly portable...

Adam

>
> Thank you,
>
> Julien
> >

--~--~-~--~~~---~--~~
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: Testing login required views

2008-05-20 Thread Julien

In another thread [1] James Bennett suggested to use a middleware to
require login for all views. That is indeed a very simple and elegant
way. Here's the code I ended up with:

from django.contrib.auth.decorators import login_required
from django.conf import settings

public_paths = ['/accounts/register/',
'/accounts/login/',
'/accounts/logout/',]

class AuthRequiredMiddleware(object):
def process_view(self, request, view_func, view_args,
view_kwargs):
if request.path.startswith(settings.MEDIA_URL) or request.path
in public_paths:
return None
else:
return login_required(view_func)(request, *view_args,
**view_kwargs)


Cheers!

Julien


[1] 
http://groups.google.com/group/django-users/browse_thread/thread/2ab080ac86d9b820/b59196f5a0ecbd85#b59196f5a0ecbd85



On May 21, 11:19 am, Julien <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have a site where pretty much all views (except for register, login
> and logout) require the user to log in. Now that the number of views
> has grown I'd like to test that I didn't forget to protect them with
> the login_required decorator.
>
> I'm looking for an automated way to do that. Is that achievable, and
> if so, how?
>
> I've started looking into unit testing but I'm struggling a bit and
> I'm not sure if that could do the trick. What I'd like to do is test
> all possible urls from the URLConf and spot those that are not
> redirected to the login page.
>
> Any hint?
>
> Thank you,
>
> Julien
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Testing login required views

2008-05-20 Thread Julien

Hi,

I have a site where pretty much all views (except for register, login
and logout) require the user to log in. Now that the number of views
has grown I'd like to test that I didn't forget to protect them with
the login_required decorator.

I'm looking for an automated way to do that. Is that achievable, and
if so, how?

I've started looking into unit testing but I'm struggling a bit and
I'm not sure if that could do the trick. What I'd like to do is test
all possible urls from the URLConf and spot those that are not
redirected to the login page.

Any hint?

Thank you,

Julien
--~--~-~--~~~---~--~~
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: setting up login required pages massly

2007-07-19 Thread Nathan Ostgard

You can define a custom decorator instead, specifying a custom
login_url:

from django.contrib.auth.decorators import user_passes_test
my_login_decorator = user_passes_test(lambda u: u.is_authenticated(),
login_url='/my/login/url')

Then you can use:

@my_login_decorator
def someview(request):
  ...

On Jul 19, 8:39 pm, james_027 <[EMAIL PROTECTED]> wrote:
> hi,
>
> is there a stupidly fast way to make select but many pages to required
> login first? I am using 0.96 @login_required is cool, but 0.96 doesn't
> support LOGIN_URL in the settings.py yet.
>
> currently i am using something like this
>
> if not request.user.is_authenticated():
> return render_to_response('login.htm', {'from':request.path})
>
> for each view's function.
>
> thanks
> james


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



setting up login required pages massly

2007-07-19 Thread james_027

hi,

is there a stupidly fast way to make select but many pages to required
login first? I am using 0.96 @login_required is cool, but 0.96 doesn't
support LOGIN_URL in the settings.py yet.

currently i am using something like this

if not request.user.is_authenticated():
return render_to_response('login.htm', {'from':request.path})

for each view's function.

thanks
james


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---