devise/cancan 模拟账户

发布于 2024-10-31 18:31:45 字数 266 浏览 5 评论 0原文

我在我的应用程序中使用 devise/cancan ,一切都非常好 - 前提是用户创建一个帐户并登录。

我想做的是允许用户在不创建帐户的情况下开始使用。如果他们想真正保存他们的工作,然后注册。

以前有人遇到过这个吗?我应该弄清楚如何使用设备创建虚拟帐户吗?或者允许未经授权的用户通过 CanCan 在我的应用程序中创建模型?

我可以详细说明我是如何考虑解决这个问题的,但这感觉像是一个非常明显的用例,有人已经提出了一个很好的解决方案。

提前致谢, 麦克风

I'm using devise/cancan for my app and everything is pretty sound -- provided a user creates an account and signs in.

What I'd like to do is allow a user to get started without creating an account. And then sign up if they want to actually save their work.

Has anybody come across this before? Should I be figuring out how to create dummy accounts with devise? Or allowing unauthorized users access to creating models in my app via CanCan?

I could go into detail about how I've been thinking about approaching this, but it feels like a pretty obvious use case that somebody has come up with a nice solution for.

Thanks in advance,
Mike

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

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

发布评论

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

评论(2

平定天下 2024-11-07 18:31:45

如果您要创建虚拟帐户,则必须通过 cookie 以某种方式跟踪用户,并将该 cookie 中的值缓存在数据库中。 Cancan 确实允许通过能力模型创建访客帐户。例如:

user ||= User.new # Guest user, for users who are not registered or don't have an account yet

这足以让您开始为非注册用户应用权限。但请注意,仅通过 cookie 进行跟踪并不是很可靠,并且可能会导致某种类型的安全隐患(即通过 cookie 劫持)。有一天,用户也可以决定清除他的 cookie。

如果需要,我建议让用户与访客帐户进行最少的交互,并尽可能地激励用户注册/注册 Devise。

希望有帮助!

If you go with creating dummy accounts, you would have to track the user somehow via a cookie and cache the values in that cookie in your db. Cancan does allow for guest accounts via the ability model. For example:

user ||= User.new # Guest user, for users who are not registered or don't have an account yet

Which is enough you to you started with applying permissions for non registered users. Note though, tracking by cookie alone is not very reliable and can lead to some type of security hazard (i.e. by means of cookie hijacking). User, one day, can also decide to clear out his cookies.

If need be, I would suggest letting the user do minimal interaction with a guest account and motivating the user to sign up / register with Devise as much as possible.

Hope that helps!

放我走吧 2024-11-07 18:31:45

我实际上正在考虑同样的问题,我有一个制作日历的日程安排应用程序。为了解决这个问题,我认为您可以使用

user ||= User.new

上面建议的方法,并在用户创建帐户后使用 cookie 将数据获取到数据库。
这意味着您不必担心清除 cookie,因为如果他们想要保存数据,他们会创建一个帐户。

I actually am considering the same problem, I have a scheduling app that makes a calendar. To get over the problem I'm thinking that you use

user ||= User.new

Like was suggested above and using cookies to get the data to the database once the user creates an account.
This would mean that you would not have to worry about clearing out cookies because they would create an account if they want to save data.

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