Django用户邀请定制库django-invitations

2024-01-2709:25:39后端程序开发Comments252 views字数 2493阅读模式

django-invitations是通用邀请解决方案,具有适应性强的后端和对 django-allauth 的支持,所有电子邮件和消息都是完全可定制的。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

这个应用最初是作为django-allauth的邀请解决方案编写的,现在已经重构已删除allauth依赖项,同时保持100%的向后兼容性。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

安装要求文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

  • 支持 Python 3.7 到 3.10
  • 支持 Django 3.2 到 4.0

安装文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

python -m pip install django-invitations

在INSTALLED_APPS添加“invitations”文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

INSTALLED_APPS = [    ...    "invitations",    ...]

Allauth 支持文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

INSTALLED_APPS中的invitations必须在allauth之后。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

将邀请 url 添加到您的 urlpatterns文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

INSTALLED_APPS = [    ...    "invitations",    ...]

运行迁移文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

python manage.py migrate

使用django-invitations有两种主要方法文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

通用邀请流程:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

  1. 特权用户通过电子邮件(通过 Django 管理员、表单发布、JSON 发布或编程方式)邀请潜在用户
  2. 用户收到带有确认链接的邀请电子邮件
  3. 用户单击链接并被重定向到预配置的 URL(默认为 accounts/signup)

Allauth 邀请流程:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

  1. 用户点击链接,他们的电子邮件被确认,他们被重定向到注册
  2. 注册 URL 已预填充电子邮件,用户在注册后将登录到站点

Allauth 集成文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

设置 allauth 设置ACCOUNT_ADAPTER文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

ACCOUNT_ADAPTER = 'invitations.models.InvitationsAdapter'

发送邀请文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

首先导入模型:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

from invitations.utils import get_invitation_model

创建模型的实例:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

Invitation = get_invitation_model()

最后将收件人传递给模型并发送。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

# inviter argument is optionalinvite = Invitation.create('email@example.com', inviter=request.user)invite.send_invitation(request)

要通过 django 管理员发送邀请,只需添加邀请并保存即可。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

批量邀请文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

支持通过 JSON 进行批量邀请。将逗号分隔的电子邮件列表发布到专用 URL,Invitations将返回一个包含有效和无效邀请列表的数据对象。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

信号文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

发出以下信号:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

  • invite_url_sent
  • invite_accepted

管理命令文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

可以使用命令清除已过期和已接受的邀请:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

python manage.py clear_expired_invitations

配置文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

邀请到期前多少天文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

设置名称:INVITATIONS_INVITATION_EXPIRY文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

类型:整数文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

默认值:3文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

是否可以通过 GET 请求接受确认文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

设置名称:INVITATIONS_CONFIRM_INVITE_ON_GET文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

类型:Boolean文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

默认值:True文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

是否在用户完成注册后接受邀请文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

设置名称:INVITATIONS_ACCEPT_INVITE_AFTER_SIGNUP文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

类型:Boolean文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

默认值:False文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

公开用于对受邀者进行身份验证的发布的 URL文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

设置名称:INVITATIONS_ALLOW_JSON_INVITES文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

类型:Boolean文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

默认值:False文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

注册 URL 的 URL 名称文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

设置名称:INVITATIONS_SIGNUP_REDIRECT文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

类型:字符串文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

默认值:“account_signup”文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

登录URL的URL名称文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

设置名称:INVITATIONS_LOGIN_REDIRECT文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

类型:字符串文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

默认值:来自 Django 设置LOGIN_URL文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

适配器文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

设置名称:INVITATIONS_ADAPTER文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

类型:字符串文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

默认值:“invitations.adapters.BaseInvitationsAdapter”文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

用于自定义集成。如果使用 django-allauth,请将其设置为 ACCOUNT_ADAPTER。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

设置自定义电子邮件最大长度值文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

设置名称:INVITATIONS_EMAIL_MAX_LENGTH文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

类型:整数文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

默认值:254文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

自定义电子邮件主题前缀文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

设置名称:INVITATIONS_EMAIL_SUBJECT_PREFIX文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

类型:字符串或无文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

默认值:无文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

如果设置为“无”(默认值),邀请电子邮件主题将以括号中的当前网站名称为前缀(例如 [example.com])。对于自定义电子邮件主题前缀,请将其设置为字符串,对于无前缀,请将其设置为空字符串。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

邀请模型的应用注册表路径文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

设置名称:INVITATIONS_INVITATION_MODEL文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

类型:字符串文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

违约:invitations.Invitation文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

管理员外部发送邀请的表单类文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

设置名称:INVITATIONS_INVITE_FORM文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

类型:字符串文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

违约:invitations.forms.InviteForm文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

admin中发送邀请的表单类文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

设置名称:INVITATIONS_ADMIN_ADD_FORM文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

类型:字符串文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

违约:invitations.forms.InvitationAdminAddForm文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

admin 中更新邀请的表单类文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

设置名称:INVITATIONS_ADMIN_CHANGE_FORM文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

类型:字符串文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

违约:invitations.forms.InvitationAdminChangeForm文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

邀请确认 URL文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

设置名称:INVITATIONS_CONFIRMATION_URL_NAME文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

类型:字符串文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

默认值:“invitations:accept-invite”文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

Allauth 相关设置文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

设置名称:INVITATIONS_INVITATION_ONLY文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

类型:Boolean文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

默认值:False文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

如果网站仅受邀或向所有人开放(仅在使用 allauth 时相关)文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html

项目github:https://github.com/jazzband/django-invitations
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/58816.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/bc/58816.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定