253 | | message = ERROR_MESSAGE |
254 | | if u'@' in username: |
255 | | # Mistakenly entered e-mail address instead of username? Look it up. |
256 | | try: |
257 | | user = User.objects.get(email=username) |
258 | | except (User.DoesNotExist, User.MultipleObjectsReturned): |
259 | | message = _("Usernames cannot contain the '@' character.") |
260 | | else: |
261 | | if user.check_password(password): |
262 | | message = _("Your e-mail address is not your username." |
263 | | " Try '%s' instead.") % user.username |
264 | | else: |
265 | | message = _("Usernames cannot contain the '@' character.") |
| 252 | message = self.get_login_error_message(request, False, username, password) |
| 328 | def get_login_error_message(self, request, is_authenticated, username, password): |
| 329 | """ |
| 330 | Returns a error message when login has failed, and gives suggestions on |
| 331 | how to resolve the error. |
| 332 | """ |
| 333 | |
| 334 | from django.contrib.auth.models import User |
| 335 | message = ERROR_MESSAGE |
| 336 | if not is_authenticated: |
| 337 | if u'@' in username: |
| 338 | # Mistakenly entered e-mail address instead of username? Look it up. |
| 339 | try: |
| 340 | user = User.objects.get(email=username) |
| 341 | except (User.DoesNotExist, User.MultipleObjectsReturned): |
| 342 | message = _("Usernames cannot contain the '@' character.") |
| 343 | else: |
| 344 | if user.check_password(password): |
| 345 | message = _("Your e-mail address is not your username." |
| 346 | " Try '%s' instead.") % user.username |
| 347 | else: |
| 348 | message = _("Usernames cannot contain the '@' character.") |
| 349 | return message |
| 350 | |