Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
login or login_decorator issue
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  12 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
mapapage  
View profile  
 More options Aug 8 2012, 4:15 am
From: mapapage <mapap...@gmail.com>
Date: Wed, 8 Aug 2012 01:15:12 -0700 (PDT)
Local: Wed, Aug 8 2012 4:15 am
Subject: login or login_decorator issue

I wrote a somehow custom login that works when the user inserts his
credentials. He is simply redirected to a page with url:

url(r'^(?P<user_id>\d+)/$', 'auth.views.main', name='main'),

Now that I try to add @login_decorators but I'm facing problems.
For example, I have the view def main(request,user_id): where the
redirected template after the login listens.
When I add @login_required(login_url='/login/') to that main, when the user
tries to login nothing happens, I remain to the login page and in the
terminal I get:
 "GET /1000/ HTTP/1.1" 302 0
 "GET /login/?next=/1000/ HTTP/1.1" 200 6201

What happens?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anton Baklanov  
View profile  
 More options Aug 8 2012, 6:01 am
From: Anton Baklanov <antonbakla...@gmail.com>
Date: Wed, 8 Aug 2012 13:01:40 +0300
Local: Wed, Aug 8 2012 6:01 am
Subject: Re: login or login_decorator issue

On Wed, Aug 8, 2012 at 11:15 AM, mapapage <mapap...@gmail.com> wrote:
> I wrote a somehow custom login that works when the user inserts his
> credentials.

can give us more details on how did you implement login?

--
Regards,
Anton Baklanov

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mapapage  
View profile  
 More options Aug 8 2012, 6:17 am
From: mapapage <mapap...@gmail.com>
Date: Wed, 8 Aug 2012 03:17:35 -0700 (PDT)
Local: Wed, Aug 8 2012 6:17 am
Subject: Re: login or login_decorator issue

 for the login I do (username must be the id field(pk) of an 'owners' table
and password is a  field of the same table):

def login_user(request):
    c = {}
    c.update(csrf(request))
    state = ""

    if request.POST:
        password = request.POST.get('password')
        id = request.POST.get('id')
        try:
            user = Owners.objects.get(id = id)
            if user:
                if user.simple_check_password(password):
                    url = reverse('main', kwargs={ 'user_id': user.id })
                    return HttpResponseRedirect(url)
                else:
                    state = 'Incorrect username or password'
            else:
                state = 'Incorrect username or password'
    except Exception as e:
            state = 'Incorrect username or password'
    print state
 return render_to_response('index.html', locals(), context_instance=
RequestContext(request))

and I also define:

def set_password(self, raw_password):
        self.password = make_password(raw_password)

    def check_password(self, raw_password):
        """
        Returns a boolean of whether the raw_password was correct. Handles
        hashing formats behind the scenes.
        """
        def setter(raw_password):
            self.set_password(raw_password)
            self.save()
        return check_password(raw_password, self.password, setter=None)

    def simple_check_password(self,raw_password):

        return raw_password == self.password

and at least it seems to me that it works, I mean the user logs in to the
main.html page.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jian Chang  
View profile  
 More options Aug 8 2012, 6:37 am
From: Jian Chang <changjia...@gmail.com>
Date: Wed, 8 Aug 2012 18:37:34 +0800
Local: Wed, Aug 8 2012 6:37 am
Subject: Re: login or login_decorator issue

what's your  '@login_required(login_url='/login/')'?
seems like the decorator leads to the redirection.

2012/8/8 mapapage <mapap...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anton Baklanov  
View profile  
 More options Aug 8 2012, 7:29 am
From: Anton Baklanov <antonbakla...@gmail.com>
Date: Wed, 8 Aug 2012 14:29:12 +0300
Local: Wed, Aug 8 2012 7:29 am
Subject: Re: login or login_decorator issue

1) i can't see in your code where you are creating some kind of session and
set some cookies to save auth state between requests.
2) is it login_required from django.contrib.auth? if yes - use login from
django.conrib.auth or create your own decorator to check user auth.

anyway - django provides ready for use user auth mechanism and maybe it's
better to use it https://docs.djangoproject.com/en/dev/topics/auth/

--
Regards,
Anton Baklanov

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "回复: login or login_decorator issue" by Pengfei Xue
Pengfei Xue  
View profile  
 More options Aug 8 2012, 7:02 am
From: Pengfei Xue <peng...@gmail.com>
Date: Wed, 8 Aug 2012 19:02:15 +0800
Local: Wed, Aug 8 2012 7:02 am
Subject: 回复: login or login_decorator issue

I think what you need is a new auth backend which return a user object  

--  
Sincerely,
Pengfei Xue
已使用 Sparrow (http://www.sparrowmailapp.com/?sig)

已使用 Sparrow (http://www.sparrowmailapp.com/?sig)  

在 2012年8月8日星期三,下午6:17,mapapage 写道:I


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mapapage  
View profile  
 More options Aug 9 2012, 2:33 am
From: mapapage <mapap...@gmail.com>
Date: Wed, 8 Aug 2012 23:33:47 -0700 (PDT)
Local: Thurs, Aug 9 2012 2:33 am
Subject: Re: 回复: login or login_decorator issue

> I wrote this custom authentication backend:

from django.contrib.auth.models import User, check_password
from auth.models import Owners
class AuthBackend(object):

    def authenticate(self, username=None, password=None):

        try:
            user = Owners.objects.get(id=username)
            #if user.check_password(password):
            if user.password == password:
                return user
        except User.DoesNotExist:
            return None

    def get_user(self, user_id):
        """ Get a User object from the user_id. """
        try:
            return User.objects.get(pk=user_id)
        except User.DoesNotExist:
            return None

but still the decorator doesn't work..even if a user is not logged in he
can access another's page just by modifying the
 url(r'^(?P<user_id>\d+)/$', 'auth.views.main', name='main'),(putting his
id)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pengfei Xue  
View profile  
 More options Aug 9 2012, 3:27 am
From: Pengfei Xue <peng...@gmail.com>
Date: Thu, 9 Aug 2012 15:27:29 +0800
Local: Thurs, Aug 9 2012 3:27 am
Subject: 回复: login or login_decorator issue

--  
Sincerely,
Pengfei Xue
已使用 Sparrow (http://www.sparrowmailapp.com/?sig)

已使用 Sparrow (http://www.sparrowmailapp.com/?sig)  

在 2012年8月9日星期四,下午2:33,mapapage 写道:

> > I wrote this custom authentication backend:

> from django.contrib.auth.models import User, check_password
> from auth.models import Owners
> class AuthBackend(object):

>     def authenticate(self, username=None, password=None):

>         try:
>             user = Owners.objects.get(id=username)

what's your definition for user, that's your user model  

>             #if user.check_password(password):
>             if user.password == password:  

you should user user.check_password instead of simple string comparison,  user.password is a encrypted string other than plain text
>                 return user
>         except User.DoesNotExist:
>             return None  

>     def get_user(self, user_id):
>         """ Get a User object from the user_id. """
>         try:
>             return User.objects.get(pk=user_id)
>         except User.DoesNotExist:
>             return None

> but still the decorator doesn't work..even if a user is not logged in he can access another's page just by modifying the  url(r'^(?P<user_id>\d+)/$', 'auth.views.main', name='main'),(putting his id)

have you followed the django's documentation about how to use the login_requried decorator? have you installed the required app in setting ?  


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mapapage  
View profile  
 More options Aug 9 2012, 3:39 am
From: mapapage <mapap...@gmail.com>
Date: Thu, 9 Aug 2012 00:39:07 -0700 (PDT)
Local: Thurs, Aug 9 2012 3:39 am
Subject: Re: 回复: login or login_decorator issue

>  I'm working with a legacy database so I should use another model (Owners)
> instead of the default Djangoconstrib.auth.models.User for authentication.

That's why I wrote my own and custom authentication backend.

> My model has an id field (id = models.DecimalField(...)) that is used for
> username and a field for password(password = models.CharField(...))

 What's more, the password that is stored in the Owners.password is not an
encrypted string but plain text and when I use if
user.check_password(password): I get
Unknown password hashing algorithm '123'. Did you specify it in the
PASSWORD_HASHERS setting?  That seems to be some kind of bug<https://code.djangoproject.com/ticket/18182#comment:8>
.
If I didn't misunderstood sth, I don't know what to do and therefore I'm
asking for a guideline..

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mapapage  
View profile  
 More options Aug 9 2012, 3:39 am
From: mapapage <mapap...@gmail.com>
Date: Thu, 9 Aug 2012 00:39:34 -0700 (PDT)
Local: Thurs, Aug 9 2012 3:39 am
Subject: Re: 回复: login or login_decorator issue


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pengfei Xue  
View profile  
 More options Aug 9 2012, 3:49 am
From: Pengfei Xue <peng...@gmail.com>
Date: Thu, 9 Aug 2012 15:49:02 +0800
Local: Thurs, Aug 9 2012 3:49 am
Subject: 回复: login or login_decorator issue

http://www.djangobook.com/en/2.0/chapter14/  

take a quick look at this article, i think it will help you out  

--  
Sincerely,
Pengfei Xue
已使用 Sparrow (http://www.sparrowmailapp.com/?sig)

已使用 Sparrow (http://www.sparrowmailapp.com/?sig)  

在 2012年8月9日星期四,下午3:39,mapapage 写道:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mapapage  
View profile  
 More options Aug 9 2012, 4:10 am
From: mapapage <mapap...@gmail.com>
Date: Thu, 9 Aug 2012 01:10:27 -0700 (PDT)
Local: Thurs, Aug 9 2012 4:10 am
Subject: Re: 回复: login or login_decorator issue

I saw it but I think that this isn't what I need for what I wanna do. I
shouldn't use django's authentication module. I should make my own backend
work.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »