我遵循了以下文章中的教程,了解如何停用用户:https://github.com/plataformatec/devise/wiki/How-to:-Soft-delete-a-user-when-user-deletes-account
我的问题是,我如何让停用的用户登录时,它会显示一个页面,允许重新激活他们的帐户?即:“用户/重新激活”用一个按钮来重新激活?
当然,我知道我必须重写默认的用户会话控制器,但我不太确定active_for_authentication在什么时候被调用,如何调用,以及如何重写重定向。
发布于 2018-05-08 13:26:06
当用户尝试登录时,请求将被路由到sessions_controller.rb的create方法,在该方法中,如果凭据有效,则为该用户创建一个会话。在该方法中,您只需检查deleted_at列是否已填充,然后执行一些分支逻辑,以重定向到有效登录所拥有的任何登录页面或重新激活页面。
您的代码看起来类似于下面的示例,但是同样,您没有提供实现细节,因此需要您进行调整:
def create
user = User.find_by(email: params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
unless user.deleted_at.nil?
my_user_login_method
redirect_to user # or redirect to a dashboard/landing page/whatever
else
render 'reactivate' # this would be a view for your reactivation page
end
else
flash.now[:danger] = 'Invalid email/password combination'
render 'new'
end
endhttps://stackoverflow.com/questions/50225933
复制相似问题