Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#2332 closed enhancement (fixed)

[patch] is_loggedin method for User and AnonymousUser models.

Reported by: SmileyChris Owned by: adrian
Component: Contrib apps Version:
Severity: normal Keywords: auth user
Cc: gary.wilson@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

This is_loggedin method replaces the is_anonymous method.

Discussion from the django-developers group follows (see thread).

Templates treat non-existing variables as False; therefore; a
request.user somehow failing to get assigned would result in the
template treating the user as they are authenticated (is_anonymous
evaluates False). An is_loggedin would be a more secure option because
if request.user failed to get assigned, the template would treat the
user as anonymous.

I would much rather mistakenly treat an authenticated user as anonymous
than mistakenly treat an anonymous user as authenticated.

Attachments (4)

is_loggedin.patch (8.8 KB) - added by SmileyChris 9 years ago.
is_loggedin implementation - also replaces all is_anonymous references with negative is_loggedin
is_logged_in.diff (13.3 KB) - added by Gary Wilson <gary.wilson@…> 9 years ago.
is_logged_in implementation with doc changes and deprecation warnings in is_anonymous
is_authenticated.diff (13.5 KB) - added by Gary Wilson <gary.wilson@…> 9 years ago.
is_authenticated implementation with doc changes and NO deprecation warnings in is_anonymous
is_authenticated.2.diff (13.5 KB) - added by Gary Wilson <gary.wilson@…> 9 years ago.
is_authenticated implementation with doc changes and NO deprecation warnings in is_anonymous, slight change in documentation wording

Download all attachments as: .zip

Change History (8)

Changed 9 years ago by SmileyChris

is_loggedin implementation - also replaces all is_anonymous references with negative is_loggedin

comment:1 Changed 9 years ago by mtredinnick

I don't like the name. Either is_authenticated or is_logged_in seem better.

Although using "login" as a single word verb is becoming common and even acceptable in some style guides (when I rule the universe, there are going to be changes made, let me tell you), I don't think we should encourage "loggedin" to be its past tense. :-) That can be fixed when we apply this.

There are some docs changes required as well that are not in this patch.

Changed 9 years ago by Gary Wilson <gary.wilson@…>

is_logged_in implementation with doc changes and deprecation warnings in is_anonymous

comment:2 Changed 9 years ago by Gary Wilson <gary.wilson@…>

  • Cc gary.wilson@… added

Changed 9 years ago by Gary Wilson <gary.wilson@…>

is_authenticated implementation with doc changes and NO deprecation warnings in is_anonymous

Changed 9 years ago by Gary Wilson <gary.wilson@…>

is_authenticated implementation with doc changes and NO deprecation warnings in is_anonymous, slight change in documentation wording

comment:3 Changed 9 years ago by Gary Wilson <gary.wilson@…>

  • Summary changed from is_loggedin method for User and AnonymousUser models. to [patch] is_loggedin method for User and AnonymousUser models.

comment:4 Changed 9 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(In [3360]) Fixed #2332 -- Introduced is_authenticated() method on User and AnonymousUser classes. Recommended its use over is_anonymous in the docs. Changed internal Django use to match this recommendation. Thanks to SmileyChris and Gary Wilson for the patch.

Note: See TracTickets for help on using tickets.
Back to Top