Re: Having trouble authenticating/validating

2009-06-02 Thread Karen Tracey
On Tue, Jun 2, 2009 at 9:42 AM, gsnyder2007  wrote:

>
> Had the same issue and the info below allowed me to resolve the issue,
> i.e. is_valid() is now returning True on a valid username/password
> combination. Seemed to me that the key was setting the test cookie and
> assigning the POST data into the 'data' variable. The former makes
> sense to me. The latter does not. I wonder if anyone out there can
> explain why.
>

AuthenticationForm adds a 'request' (keyword or first positional) parameter
to the standard Form arguments:

http://code.djangoproject.com/browser/django/tags/releases/1.0/django/contrib/auth/forms.py#L54

So if you are instantiating an AuthenticationForm without passing in
'request' you need to specify what's normally simply the first positional
Form argument by keyword (which is 'data'), because if you pass it as simply
first positional it will be assigned to 'request'.

Not sure if that explains what does not make sense to you?

(Both the details of AuthenticationForm and the fact that the first
positional argument to the base Form class has the keyword 'data' could
probably use a bit more explicit documentation, unless I'm missing where
these things are currently covered...I couldn't find them in a brief
search.)

Karen

--~--~-~--~~~---~--~~
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: Having trouble authenticating/validating

2009-06-02 Thread gsnyder2007

Had the same issue and the info below allowed me to resolve the issue,
i.e. is_valid() is now returning True on a valid username/password
combination. Seemed to me that the key was setting the test cookie and
assigning the POST data into the 'data' variable. The former makes
sense to me. The latter does not. I wonder if anyone out there can
explain why.

On May 12, 1:28 pm, adrian  wrote:
> Figured it out by looking at how the admin view using
> AuthenticationForm:
>
> In POST:
>
> loginForm = AuthenticationForm(data=request.POST)
>
> note the use of data= which I have not seen before
>
> in GET:
>
>  loginForm = AuthenticationForm(request)
>         request.session.set_test_cookie()
>
> note the passing of request to the form which is also unusual

--~--~-~--~~~---~--~~
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: Having trouble authenticating/validating

2009-05-12 Thread adrian


Figured it out by looking at how the admin view using
AuthenticationForm:

In POST:

loginForm = AuthenticationForm(data=request.POST)

note the use of data= which I have not seen before

in GET:

 loginForm = AuthenticationForm(request)
request.session.set_test_cookie()

note the passing of request to the form which is also unusual
--~--~-~--~~~---~--~~
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: Having trouble authenticating/validating

2009-05-12 Thread adrian

For the record, I am seeing the same problem.  request.POST contains
the correct values for
username and password, yet is_valid returns false and the form does
not include any error messages.

I haven't gotten to the bottom of it yet but AuthenticationForm is not
calling the clean() method.
And I have set the test cookie.

On Mar 26, 11:39 am, Karen Tracey  wrote:
> On Thu, Mar 26, 2009 at 12:26 PM, Adam Yee  wrote:
>
> > {{ error }}
> > 
> > {{ form.as_p }}
> > 
> > 
>
> form.as_p ought to be showing the errors on the form.  So I'm puzzled by how
> is_valid could be returning False but no errors are being displayed.
>
>
>
> > Guessing is sometimes all one can do after analyzing to their limit.
> > Or they can be lazy without any personal effort and post to a group
> > like this one (which I don't recommend).  I spent as much time allowed
> > figuring out what I could, then came to you.  I strive to lessen the
> > amount of guessing I do and develop the skills needed to figure out
> > problems...but that takes time.
>
> > I've been reading up on validating since I feel the problem lies in
> > the is_valid part.  Again, I understand this is a guess, I just need
> > to direction in figuring out the problem.  I'm not merely looking for
> > the quick and easy solution.
>
> > What I do know is that rendering a template is a separate action from
> > validating.  Validation should take place before rendering.  If I
> > can't validate properly, it won't show in the template properly,
> > right?  Thanks Karen.
>
> It's perfectly OK to render in a template a form that returns False from
> is_valid, that is normally what is done to point out the validation errors
> in the submitted data.  is_valid returning False doesn't make the form
> invalid for displaying, it just means there is something in the submitted
> data that is not passing validation.  In your case what I'd be doing at this
> point is probably stepping through the form cleaning code in a debugger to
> figure out what is going on.
>
> Karen
--~--~-~--~~~---~--~~
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: Having trouble authenticating/validating

2009-03-26 Thread Karen Tracey
On Thu, Mar 26, 2009 at 12:26 PM, Adam Yee  wrote:

>
> {{ error }}
> 
> {{ form.as_p }}
> 
> 
>

form.as_p ought to be showing the errors on the form.  So I'm puzzled by how
is_valid could be returning False but no errors are being displayed.


> Guessing is sometimes all one can do after analyzing to their limit.
> Or they can be lazy without any personal effort and post to a group
> like this one (which I don't recommend).  I spent as much time allowed
> figuring out what I could, then came to you.  I strive to lessen the
> amount of guessing I do and develop the skills needed to figure out
> problems...but that takes time.
>
> I've been reading up on validating since I feel the problem lies in
> the is_valid part.  Again, I understand this is a guess, I just need
> to direction in figuring out the problem.  I'm not merely looking for
> the quick and easy solution.
>
> What I do know is that rendering a template is a separate action from
> validating.  Validation should take place before rendering.  If I
> can't validate properly, it won't show in the template properly,
> right?  Thanks Karen.
>

It's perfectly OK to render in a template a form that returns False from
is_valid, that is normally what is done to point out the validation errors
in the submitted data.  is_valid returning False doesn't make the form
invalid for displaying, it just means there is something in the submitted
data that is not passing validation.  In your case what I'd be doing at this
point is probably stepping through the form cleaning code in a debugger to
figure out what is going on.

Karen

--~--~-~--~~~---~--~~
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: Having trouble authenticating/validating

2009-03-26 Thread Adam Yee

On Mar 25, 6:27 pm, Karen Tracey  wrote:
> On Tue, Mar 24, 2009 at 2:11 PM, Adam Yee  wrote:
> > So, I now pass the bound form, but still no validation error messages
> > show up.  More importantly, is_valid is still returning false even
> > when I try logging in as a super user.  I also removed checking for
> > is_active since the AuthenticationForm's clean should take care of
> > that and raise the correct validation error if the user isn't active.
> > Now with the error() func removed:
>
> How are you rendering the form in the template?  If is_valid returns false
> then there should be errors noted in the errors dictionary, if you are not
> seeing these it sounds like youare rendering the form in some way that
> bypasses outputting the form errors.  Fixing that would be a step towards
> figuring out what is causing the problem, since you'd know specifically what
> is wrong instead of trying to guess what might be going wrong.
>
> Karen

{{ error }}

{{ form.as_p }}



Guessing is sometimes all one can do after analyzing to their limit.
Or they can be lazy without any personal effort and post to a group
like this one (which I don't recommend).  I spent as much time allowed
figuring out what I could, then came to you.  I strive to lessen the
amount of guessing I do and develop the skills needed to figure out
problems...but that takes time.

I've been reading up on validating since I feel the problem lies in
the is_valid part.  Again, I understand this is a guess, I just need
to direction in figuring out the problem.  I'm not merely looking for
the quick and easy solution.

What I do know is that rendering a template is a separate action from
validating.  Validation should take place before rendering.  If I
can't validate properly, it won't show in the template properly,
right?  Thanks Karen.
--~--~-~--~~~---~--~~
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: Having trouble authenticating/validating

2009-03-25 Thread Karen Tracey
On Tue, Mar 24, 2009 at 2:11 PM, Adam Yee  wrote:

> So, I now pass the bound form, but still no validation error messages
> show up.  More importantly, is_valid is still returning false even
> when I try logging in as a super user.  I also removed checking for
> is_active since the AuthenticationForm's clean should take care of
> that and raise the correct validation error if the user isn't active.
> Now with the error() func removed:
>

How are you rendering the form in the template?  If is_valid returns false
then there should be errors noted in the errors dictionary, if you are not
seeing these it sounds like youare rendering the form in some way that
bypasses outputting the form errors.  Fixing that would be a step towards
figuring out what is causing the problem, since you'd know specifically what
is wrong instead of trying to guess what might be going wrong.

Karen

--~--~-~--~~~---~--~~
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: Having trouble authenticating/validating

2009-03-25 Thread Adam Yee

On Mar 23, 8:30 pm, Karen Tracey  wrote:
> On Mon, Mar 23, 2009 at 4:45 PM, Adam Yee  wrote:
>
> > I'm using Django's builtin AuthenticationForm
>
> > Here's my login view:http://dpaste.com/18110/
>
> > Form submittal (not empty or empty fields) takes me back to the login
> > page with 'Did not login'.  My debugging print statement isn't showing
> > up in the terminal, so is_valid is somehow returning false.
>
> > If I submit with empty fields, I don't get the default 'This field is
> > required' type of error messages that I would expect.  I'm not sure
> > how clean() is working with the AuthenticationForm...  Am I validating
> > correctly? Or is something happening in the authentication process?
> > Thanks.
>
> Your error() function is creating a brand-new blank AuthenticationForm that
> is passed in the context to the template, so the specific error message
> associated with whatever caused is_valid() to fail (which has been added to
> the original form's error_list) is being thrown away.  If instead you pass
> back the form you called is_valid() on, then the template would be able to
> report the specific error that is causing the validation failure.
>
> Karen

Do I need to set a test cookie in the view before using
AuthenticationForm()?  I'm new to sessions and cookies.  Anyone out
there use this builtin form, AuthenticationForm()?
--~--~-~--~~~---~--~~
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: Having trouble authenticating/validating

2009-03-24 Thread Adam Yee



On Mar 23, 8:30 pm, Karen Tracey  wrote:
> On Mon, Mar 23, 2009 at 4:45 PM, Adam Yee  wrote:
>
> > I'm using Django's builtin AuthenticationForm
>
> > Here's my login view:http://dpaste.com/18110/
>
> > Form submittal (not empty or empty fields) takes me back to the login
> > page with 'Did not login'.  My debugging print statement isn't showing
> > up in the terminal, so is_valid is somehow returning false.
>
> > If I submit with empty fields, I don't get the default 'This field is
> > required' type of error messages that I would expect.  I'm not sure
> > how clean() is working with the AuthenticationForm...  Am I validating
> > correctly? Or is something happening in the authentication process?
> > Thanks.
>
> Your error() function is creating a brand-new blank AuthenticationForm that
> is passed in the context to the template, so the specific error message
> associated with whatever caused is_valid() to fail (which has been added to
> the original form's error_list) is being thrown away.  If instead you pass
> back the form you called is_valid() on, then the template would be able to
> report the specific error that is causing the validation failure.
>
> Karen

Thanks Karen for that tip.  The brand-new unbound form is removed.

So, I now pass the bound form, but still no validation error messages
show up.  More importantly, is_valid is still returning false even
when I try logging in as a super user.  I also removed checking for
is_active since the AuthenticationForm's clean should take care of
that and raise the correct validation error if the user isn't active.
Now with the error() func removed:

def stl_login(request):
if request.method == "POST":
form = AuthenticationForm(request.POST)
if form.is_valid(): # authenticate() should get called here from
form's clean()
print 'form is valid'
user = form.get_user()
print request.user
login(request, user)
return HttpResponseRedirect(reverse
('stlhome.views.stl_user_home'))
return render_to_response('stl_home.html', {
'script_name': request.META['SCRIPT_NAME'],
'form': form,
'error': 'Did not login'}
)
--~--~-~--~~~---~--~~
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: Having trouble authenticating/validating

2009-03-23 Thread Karen Tracey
On Mon, Mar 23, 2009 at 4:45 PM, Adam Yee  wrote:

>
> I'm using Django's builtin AuthenticationForm
>
> Here's my login view: http://dpaste.com/18110/
>
> Form submittal (not empty or empty fields) takes me back to the login
> page with 'Did not login'.  My debugging print statement isn't showing
> up in the terminal, so is_valid is somehow returning false.
>
> If I submit with empty fields, I don't get the default 'This field is
> required' type of error messages that I would expect.  I'm not sure
> how clean() is working with the AuthenticationForm...  Am I validating
> correctly? Or is something happening in the authentication process?
> Thanks.
>
>
Your error() function is creating a brand-new blank AuthenticationForm that
is passed in the context to the template, so the specific error message
associated with whatever caused is_valid() to fail (which has been added to
the original form's error_list) is being thrown away.  If instead you pass
back the form you called is_valid() on, then the template would be able to
report the specific error that is causing the validation failure.

Karen

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



Having trouble authenticating/validating

2009-03-23 Thread Adam Yee

I'm using Django's builtin AuthenticationForm

Here's my login view: http://dpaste.com/18110/

Form submittal (not empty or empty fields) takes me back to the login
page with 'Did not login'.  My debugging print statement isn't showing
up in the terminal, so is_valid is somehow returning false.

If I submit with empty fields, I don't get the default 'This field is
required' type of error messages that I would expect.  I'm not sure
how clean() is working with the AuthenticationForm...  Am I validating
correctly? Or is something happening in the authentication process?
Thanks.


# django.contrib.auth.forms.py
# AuthenticationForm's clean()
...
def clean(self):
username = self.cleaned_data.get('username')
password = self.cleaned_data.get('password')

if username and password:
self.user_cache = authenticate(username=username,
password=password)
if self.user_cache is None:
raise forms.ValidationError(_("Please enter a correct
username and password. Note that both fields are case-sensitive."))
elif not self.user_cache.is_active:
raise forms.ValidationError(_("This account is
inactive."))

# TODO: determine whether this should move to its own method.
if self.request:
if not self.request.session.test_cookie_worked():
raise forms.ValidationError(_("Your Web browser
doesn't appear to have cookies enabled. Cookies are required for
logging in."))

return self.cleaned_data
...
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---