Django社交全部验证 - 多重用户类型

发布于 2025-02-03 01:43:59 字数 770 浏览 3 评论 0原文

我有两个注册页:注册为买方,注册为卖家

在这两个页面上,我都使用了使用Google和Facebook的正常注册和社交认证。

我已经使用Django all-auth添加了社交认证,但无法获得user_role。

[1] [注册页]:

  • 注册后:用户被重定向到家庭页面,并且由于社交身份验证中没有User_role设置,因此无法访问买方或卖方部分。

[2] [与Google注册]:注册后:用户被注册为空白登录。

  • 在Google注册后查看主页:

我的任务:是在两个按钮上分配user_type:买家卖家。单击按钮将用户重定向到其特定的注册页面,并使用社交认证登录/注册,并在成功的login重定向用户登录到其页面,并显示 django-administration-sistristration-sistration-emer_type AS:

user_type |电子邮件| IS_Active

买家|

卖家| [email  procectived] |错误的

I have two Registration pages: Register as Buyer, Register as Seller.

on both Pages , I've included Normal Registration and social authentication using Google and Facebook.

I've added social authentication using Django all-auth, but cannot get user_role.

[1][Registration Page]:

  • after Registration : user is redirected to home page and as there is no user_role set in social authentication , one cannot access Buyer or Seller 's section.

[2][Signup with Google]: After signup : User is registered as Blank Login.

  • check home page after Google signup:

MY TASK : Is to assign user_type on both the buttons: Buyer and Seller. on click button redirect user to its particular Registration Page and Login/Signup with Social Authentication and after Successful-Login Redirect User to its Page and show user_type in Django-administration-panel as:

User_type | Email | is_active

Buyer | [email protected] | True

Seller | [email protected] | False

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

_畞蕅 2025-02-10 01:43:59

您可以为所有用户创建配置文件模型,然后为用户提供类似的个人资料。

#models.py

class Profile(models.Model):
    user_type = models.CharField()
    user = models.ForeignKey(User, related_name="profile")

这将在用户创建后运行。

#signals.py

from django.db.models.signals import post_save
from django.dispatch import receiver
from . models import Profile
from django.conf import settings

User = settings.AUTH_USER_MODEL

@receiver(post_save, sender=User)
def create_profile(sender, instance, created, **kwargs):
    if created:
        Profile.objects.create(user=instance, user_type=instance.user_type)

编辑:我不知道您的USER_TYPE字段如何,我认为它是“ user_type”

You can create a profile model for all users and then give the user a profile like this.

#models.py

class Profile(models.Model):
    user_type = models.CharField()
    user = models.ForeignKey(User, related_name="profile")

this will run after the user has created.

#signals.py

from django.db.models.signals import post_save
from django.dispatch import receiver
from . models import Profile
from django.conf import settings

User = settings.AUTH_USER_MODEL

@receiver(post_save, sender=User)
def create_profile(sender, instance, created, **kwargs):
    if created:
        Profile.objects.create(user=instance, user_type=instance.user_type)

edit: I don't know how is your user_type field I assume it is "user_type"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文