如何在不设计 gem 的情况下在 rails 中使用相同的身份验证回调对两种类型的用户进行身份验证? [英] How to authenticate two types of user with same authentication callback in rails without devise gem?

查看:55
本文介绍了如何在不设计 gem 的情况下在 rails 中使用相同的身份验证回调对两种类型的用户进行身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 rails 6.0.0 创建一个网页,它有两种类型的用户(模型)而没有设计 gem.行政用户/查看者

I want to create a webpage using rails 6.0.0, which has two types of users(model) without devise gem. Admin User/viewer

但问题是我想使用相同的回调地址为 facebook 或 google_oauth2 的两个用户进行身份验证(注册/登录),而无需设计 gem:/auth/:provider/callback

But the problems is that I want to authenticate (sign up /sign in) for both users with facebook or google_oauth2 with same callbacks address without devise gem: /auth/:provider/callback

在互联网、github 和 youtube 上,我找到了仅用于验证单个模型的文章和视频.但我想对两个模型进行身份验证(注册/登录).

On internet, github and youtube I have found articles and videos only for authenticate single model. But I want to authenticate (sign up /sign in) for two models.

有人可以帮忙吗?请给出一个想法,通过一些示例来验证两个模型,而无需设计初学者可以理解的 gem.

Can anyone help? Please give an idea to authenticate both model with some example without devise gem that an beginner can understand.

推荐答案

通常不建议对两个模型进行身份验证.只有在非常罕见的情况下才需要这样做.(想想 Uber,它有司机和客户预订乘车).

Generally it is not advised to authenticate two models. Only in really rare cases this is needed. (Think of Uber which has drivers and clients booking the rides).

如果你想要一个管理员和一个普通用户,实现的方法是在用户模型中添加一个名为 admin 的列,它是一个布尔值.这样你就只有一个用户模型——大多数时候管理员可以做至少用户可以做的事情.如果您的用户是管理员,您只需将 admin 布尔值设置为 true :)

If you want to have an admin and a normal user, the way to do it is to add a column in the user model called admin which is a boolean. This way you only have one user model - most of the times the admin can do at leat what the user can do. If your user is an admin, you just set the admin boolean to true :)

这篇关于如何在不设计 gem 的情况下在 rails 中使用相同的身份验证回调对两种类型的用户进行身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆