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/

On Wed, Aug 8, 2012 at 1:37 PM, Jian Chang <[email protected]> wrote:

> what's your  '@login_required(login_url='/login/')'?
> seems like the decorator leads to the redirection.
>
> 2012/8/8 mapapage <[email protected]>
>
>>  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 received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/django-users/-/oPmX_2NBchQJ.
>>
>> To post to this group, send email to [email protected].
>> 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.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to [email protected].
> 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.
>



-- 
Regards,
Anton Baklanov

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
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.

Reply via email to