注册后不要登录 [英] Don't allow sign in after sign up in devise

查看:199
本文介绍了注册后不要登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用devise进行身份验证,设计自动登录后,
i只需要注册,但不能登录。
还有类似的问题链接,但没有帮助我

I am using devise for authentication, devise automatically sign in after signing up, i need just sign up but not sign in. There is similar question link but it didn't help me

推荐答案

免责声明:以下代码在我的实践中未被验证。在理论上他们很可能会工作。

起初你需要使用你的自定义注册控制器。您可以在Devise wiki中查看如何做到这一点。

At first you need to use your custom RegistrationsController. You can check how to do that in Devise wiki.

设置完成后,事情相当简单。在您的自定义控制器中执行以下操作

After setting up, things are fairly easy. Do the following in your custom controller

class Users::RegistrationsController < Devise::RegistrationsController
  def create
    super #Nothing special here.
  end

  protected

  def sign_up(resource_name, resource)
    true
  end
end

它是如何工作的?在Devise的代码中,成功保存后, #create 将调用受保护的方法 #sign_up 。该方法只对用户进行登录。我们需要做的是覆盖此方法来停止该操作。当然,如果需要,你甚至可以添加更多的逻辑。

How does it work? In Devise's code, #create will call a protected method #sign_up after saving successfully. This method does nothing but sign in the user. What we need to do is to overwrite this method to stop that action. Of course you can even add more of your logic here if necessary.

这篇关于注册后不要登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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