foo290/Django-Verify-Email

'Users' object has no attribute 'last_login'

camster91 opened this issue · 3 comments

Hello! Thanks so much for this simple and easy to use package!

I think I might be missing something in my Users model or maybe something else. I'm not sure what this means.

'Users' object has no attribute 'last_login'

I'm happy to provide any code to help troubleshoot this. Sorry I'm very new to python I appreciate any support you can provide me.

Thanks!

Traceback (most recent call last):
File "C:\Users\camst\AppData\Local\Programs\Python\Python39\lib\site-packages\verify_email\email_handler.py", line 46, in send_verification_link
verification_url = self.token_manager.generate_link(request, inactive_user, useremail)
File "C:\Users\camst\AppData\Local\Programs\Python\Python39\lib\site-packages\verify_email\token_manager.py", line 200, in generate_link
token = self.__generate_token(inactive_user)
File "C:\Users\camst\AppData\Local\Programs\Python\Python39\lib\site-packages\verify_email\token_manager.py", line 149, in __generate_token
user_token = default_token_generator.make_token(user)
File "C:\Users\camst\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\auth\tokens.py", line 28, in make_token
return self._make_token_with_timestamp(user, self._num_seconds(self._now()))
File "C:\Users\camst\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\auth\tokens.py", line 78, in _make_token_with_timestamp
self._make_hash_value(user, timestamp),
File "C:\Users\camst\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\auth\tokens.py", line 104, in _make_hash_value
login_timestamp = '' if user.last_login is None else user.last_login.replace(microsecond=0, tzinfo=None)

During handling of the above exception ('Users' object has no attribute 'last_login'), another exception occurred:
File "C:\Users\camst\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\camst\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\camst\OneDrive\Documents\GitHub\Newsletter\JW-Newsletter\website\app\views.py", line 13, in index
inactive_user = send_verification_email(request, form)
File "C:\Users\camst\AppData\Local\Programs\Python\Python39\lib\site-packages\verify_email\email_handler.py", line 83, in send_verification_email
return _VerifyEmail().send_verification_link(request, form)
File "C:\Users\camst\AppData\Local\Programs\Python\Python39\lib\site-packages\verify_email\email_handler.py", line 59, in send_verification_link
raise Exception(error)

Exception Type: Exception at /
Exception Value: 'Users' object has no attribute 'last_login'

The problem is when we are trying to make an encrypted link for the user.

This process also encrypts the last login details of a user to ensure that the link is being used only once, but in your case, the user doesn't t have the last login which seems like an issue on your side because by default all users in Django has this attribute.
(unless you are using a completely different custom model which is not even inherited from Django AbstractUser class)

Thanks! I am using a custom model. I'll have to look into the Django AbstractUser class. Not sure how that works yet.

It's easy, here is the docs

Happy coding 😃