简体   繁体   English

在 Django python 中首次成功登录后重置密码

[英]Reset password after first successful login in Django python

I am building an web application using existing Auth features in Django where admin create user profile with username and password.我正在使用 Django 中现有的身份验证功能构建一个 Web 应用程序,其中管理员使用用户名和密码创建用户配置文件。 Admin created user name and password will be given to user to login.管理员创建的用户名和密码将提供给用户登录。 So for security reasons I need to ask user to reset password (given by admin) after user's first successful login.因此,出于安全原因,我需要在用户第一次成功登录后要求用户重置密码(由管理员提供)。 To reset password, I will be displaying template where user should be entering only new password and new password again for confirmation.要重置密码,我将显示模板,用户应该只输入新密码和新密码以进行确认。 This new password will be updated in sqlite database.这个新密码将在 sqlite 数据库中更新。

So whenever admin changes the users password.所以每当管理员更改用户密码时。 I need to ask users to reset password after first successful login.我需要在第一次成功登录后要求用户重置密码。

I know this if off topic for stacoverflow and for reasons I couldnt post a question in StackExchange.我知道这对于 stacoverflow 来说是否离题,并且出于我无法在 StackExchange 中发布问题的原因。 Please refer me or help will be appreciated.请参考我或帮助将不胜感激。

You can have a boolean attribute in the User model which gets set True, whenever Admin user sets the password for that user.您可以在 User 模型中设置一个布尔属性,该属性设置为 True,只要 Admin 用户为该用户设置密码。

Then in middleware, you can check if that User needs to set the password, then correspondingly you can redirect the user to Reset password view.然后在中间件中,您可以检查该用户是否需要设置密码,然后您可以相应地将用户重定向到重置密码视图。

You can use these blogs to create a password reset views.您可以使用这些博客来创建密码重置视图。 Middleware logic you need to write by yourself, for setting that attribute you can override User save in admin.py, set that attribute and call super您需要自己编写中间件逻辑,要设置该属性,您可以覆盖 admin.py 中保存的用户,设置该属性并调用 super

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM