Changeset 5771
- Timestamp:
- 07/28/07 13:30:40 (1 year ago)
- Files:
-
- django/trunk/django/contrib/auth/models.py (modified) (4 diffs)
- django/trunk/django/contrib/auth/tests.py (added)
- django/trunk/docs/authentication.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/contrib/auth/models.py
r5609 r5771 7 7 import datetime 8 8 import urllib 9 10 UNUSABLE_PASSWORD = '!' # This will never be a valid hash 9 11 10 12 try: … … 84 86 85 87 class UserManager(models.Manager): 86 def create_user(self, username, email, password ):88 def create_user(self, username, email, password=None): 87 89 "Creates and saves a User with the given username, e-mail and password." 88 90 now = datetime.datetime.now() 89 91 user = self.model(None, username, '', '', email.strip().lower(), 'placeholder', False, True, False, now, now) 90 user.set_password(password) 92 if password: 93 user.set_password(password) 94 else: 95 user.set_unusable_password() 91 96 user.save() 92 97 return user … … 179 184 return is_correct 180 185 return check_password(raw_password, self.password) 186 187 def set_unusable_password(self): 188 # Sets a value that will never be a valid hash 189 self.password = UNUSABLE_PASSWORD 190 191 def has_usable_password(self): 192 return self.password != UNUSABLE_PASSWORD 181 193 182 194 def get_group_permissions(self): … … 269 281 270 282 class Message(models.Model): 271 """The message system is a lightweight way to queue messages for given users. A message is associated with a User instance (so it is only applicable for registered users). There's no concept of expiration or timestamps. Messages are created by the Django admin after successful actions. For example, "The poll Foo was created successfully." is a message. 283 """ 284 The message system is a lightweight way to queue messages for given users. A message is associated with a User instance (so it is only applicable for registered users). There's no concept of expiration or timestamps. Messages are created by the Django admin after successful actions. For example, "The poll Foo was created successfully." is a message. 272 285 """ 273 286 user = models.ForeignKey(User) django/trunk/docs/authentication.txt
r5571 r5771 115 115 password hashing in making the comparison.) 116 116 117 * ``set_unusable_password()`` -- Marks the user as having no password set. 118 This isn't the same as having a blank string for a password. 119 ``check_password()`` for this user will never return ``True``. Doesn't 120 save the ``User`` object. 121 122 You may need this if authentication for your application takes place 123 against an existing external source such as an LDAP directory. 124 125 * ``has_usable_password()`` -- Returns ``False`` if 126 ``set_unusable_password()`` has been called for this user. 127 117 128 * ``get_group_permissions()`` -- Returns a list of permission strings that 118 129 the user has, through his/her groups. … … 153 164 The ``User`` model has a custom manager that has the following helper functions: 154 165 155 * ``create_user(username, email, password)`` -- Creates, saves and returns 156 a ``User``. The ``username``, ``email`` and ``password`` are set as 157 given, and the ``User`` gets ``is_active=True``. 166 * ``create_user(username, email, password=None)`` -- Creates, saves and 167 returns a ``User``. The ``username``, ``email`` and ``password`` are set 168 as given, and the ``User`` gets ``is_active=True``. 169 170 If no password is provided, ``set_unusable_password()`` will be called. 158 171 159 172 See _`Creating users` for example usage.
