使用 Devise for Rails 禁止/阻止用户的最佳方法是什么?

编程入门 行业动态 更新时间:2024-10-28 20:31:36
本文介绍了使用 Devise for Rails 禁止/阻止用户的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在 Rails 应用中使用 Devise 进行身份验证,我希望能够阻止某些帐户并防止用户使用被阻止的电子邮件重新注册.我只是不确定最好的方法是什么.

I'm using Devise for authentication in my rails app and I'd like to be able to block certain accounts and prevent users from reregistering with a blocked email. I'm just not sure what the best way is to go about it.

我的第一个想法是覆盖会话和注册控制器以检查具有阻塞位的用户的模型,但我觉得可能有更优雅的方法.

My first thought was to override the sessions and registrations controllers to check the model for a user with a blocked bit, but I have a feeling there might be a more elegant way.

推荐答案

我会这样做:

def after_sign_in_path_for(resource) if resource.is_a?(User) && resource.banned? sign_out resource banned_user_path else super end end

更多推荐

使用 Devise for Rails 禁止/阻止用户的最佳方法是什么?

本文发布于:2023-11-16 21:41:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607579.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   用户   Devise   Rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!