django-registration 用户激活与“已删除”冲突不活跃用户
最近,我一直在研究使用激活步骤进行用户注册的选项,并遇到了 django-registration 项目。
基本上,我在浏览代码时注意到的问题如下,我不知道解决它的“最便宜”方法是什么:
“已删除”用户之间存在歧义(标记为非活动 - 许多来源都建议这样做) )、未激活帐户(但激活尚未过期)的不活跃用户以及激活已过期的用户。
auth_user 数据库中的所有这些用户都有 is_active=False
为了区分“有效”和“无效”用户,任何用户数据库查询都应该转到用户的个人资料并检查几件事:即以下是有效用户:
- user.is_active= False AND user.get_profile().activated != ACTIVATED AND not_expired_yet
- user.is_active=True
如果只想考虑的话,这基本上会影响用户对象上的所有查询操作有效用户。
我喜欢配置文件扩展而不是从用户模型继承(创建 SQL JOIN 查询)的原因是为了避免在我不一定需要访问用户的配置文件字段的地方进行额外的 JOIN 查询。
所以我想长话短说 - 有两个问题:
您对 django 注册之类解决歧义的方法有何建议? QuerySet.select_lated 是我能想到的最多的,它基本上最终会在 userdb 上的每个查询中加入 JOIN。
如何很好地包装对 django.auth.contrib.User.objects 方法(如过滤器、获取、排除)的直接调用,以便它们仅考虑有效用户?我能想到的最好的办法就是检查 RegistrationProfile 方法,即使是用户查询...
任何反馈表示赞赏
Recently I've been looking into options for user registration using activation steps and came across the django-registration project.
Basically, the problem I noticed walking thru the code is the following and I don't know what's the "cheapest" way to solve it:
There is an ambiguity between "deleted" users (marked inactive - that is being suggested in number of sources), inactive users that just didn't activate their account (but activation has not expired yet) and ones with expired activation.
All these users in auth_user db have is_active=False
To distinguish between "valid" and "invalid" users any of user db queries should go also to user's profile and check for couple of things: i.e. the following are valid users:
- user.is_active=False AND user.get_profile().activated != ACTIVATED AND not_expired_yet
- user.is_active=True
This basically impacts all the query operations on users objects if one wants to consider only valid users.
The reason I liked the profile extension over inheritance from User model (that creates SQL JOIN queries) was to avoid extra JOIN queries wherever I don't necessarily need to access user's profile fields.
So I guess to make long story short - two questions:
What would be your suggestions for django-registration like approach to solve the ambiguity? QuerySet.select_related is the most I could think of that will basically end up in JOIN for every query on userdb.
How to nicely wrap the direct calls to django.auth.contrib.User.objects methods like filter,get,exclude so that they take into account only the valid users? The best I could think of was to go over RegistrationProfile method even for user queries...
Any feedback appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论