New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I get 'User' object has no attribute 'is_verified' #39
Comments
Sounds rather like the middleware isn't installed. |
I have faced the same error in a project that uses the old |
Thank you for sharing this!! I ran into this exact issue today after upgrading |
I am having the same problem. I have the middleware installed, not sure what the issue is |
I had to override the Below it the overridden code in my
|
Has anyone solved this? Im really clueless here... |
It looks like the issue you're experiencing might be caused by the fact that the is_verified method is not defined on the default User model in Django. This method is added by the django-otp package to provide verification functionality. To use the is_verified method in your custom login view, you'll need to make sure that your user model is a subclass of AbstractBaseUser and includes the OTPUserMixin from django-otp. This will ensure that the is_verified method is available on your user model. Once you've made sure that your user model includes the OTPUserMixin, you should be able to use the is_verified method in your custom login view. As for the issue with the django_otp.middleware.OTPMiddleware middleware, it's hard to know exactly what's causing the incompatibility without more information about the error you're seeing. However, it's possible that the middleware is assuming that the is_verified method is available on the User model, which is causing the error you're seeing. If you're unable to resolve the issue with the OTPMiddleware, you may need to remove it from your middleware stack. In many cases, the functionality provided by OTPMiddleware can be duplicated using other middleware or custom code. It's worth noting that removing OTPMiddleware could reduce the security of your application, since it's responsible for enforcing two-factor authentication for your users. If you do decide to remove it, make sure that you have other security measures in place to protect your user's accounts.
Here's an example of how you can define a custom User model that subclasses AbstractBaseUser and includes the OTPUserMixin from django-otp:
In this example, our custom User model includes an email field (which we're using as the USERNAME_FIELD for authentication), a full_name field, and inherits from both OTPUserMixin and AbstractBaseUser. To use the is_verified method in a custom login view, make sure to import your CustomUser model instead of the default User model. Here's an example of a custom login view that checks whether the user is verified:
In this example, we import our CustomUser model and use the is_verified method to check whether the user is verified before logging them in. If the user is not verified, we return an error message instead. Keep in mind that this is just one example of how you can use the is_verified method in a custom login view. Depending on the specific requirements of your application, you may need to modify this code or use a different approach to achieve your goals. |
Hi I'm having this problem (only in production, not local development), but I don't see an OTPUserMixin class in django_otp.models. Is this still the correct approach? |
Hey, same problem here, any solutions so far? The middleware is correctly installed and as @kimberlymcm mentioned, there's no OTPUserMixin Class to import. |
Maybe try adding the class itself if it does not exist:
|
yeah i just added to my user manager a property. Maybe some conflicts with other middlewares or your user setup, which was my issue |
Hi, thanks for the awesome project.
I having some problems with a custom login View, when i try to check if user is_verified, looks like that method isnt in the user
The text was updated successfully, but these errors were encountered: