Ruby Gitlab电子邮件确认重定向

Ruby Gitlab电子邮件确认重定向,ruby,redirect,devise,gitlab,Ruby,Redirect,Devise,Gitlab,默认情况下,Gitlab会在电子邮件确认后将用户重定向到主页。我想改为在场外重定向 我不认为这有一个配置选项,所以我问如何破解它 我发现确认\u controller.rb: # frozen_string_literal: true class ConfirmationsController < Devise::ConfirmationsController include AcceptsPendingInvitations def almost_there flas

默认情况下,Gitlab会在电子邮件确认后将用户重定向到主页。我想改为在场外重定向

我不认为这有一个配置选项,所以我问如何破解它

我发现
确认\u controller.rb

# frozen_string_literal: true

class ConfirmationsController < Devise::ConfirmationsController
  include AcceptsPendingInvitations

  def almost_there
    flash[:notice] = nil
    render layout: "devise_empty"
  end

  protected

  def after_resending_confirmation_instructions_path_for(resource)
    users_almost_there_path
  end

  def after_confirmation_path_for(resource_name, resource)
    accept_pending_invitations

    # incoming resource can either be a :user or an :email
    if signed_in?(:user)
      after_sign_in(resource)
    else
      Gitlab::AppLogger.info("Email Confirmed: username=#{resource.username} email=#{resource.email} ip=#{request.remote_ip}")
      flash[:notice] = flash[:notice] + " Please sign in."
      new_session_path(:user, anchor: 'login-pane')
    end
  end

  def after_sign_in(resource)
    after_sign_in_path_for(resource)
  end
end
#冻结的字符串文字:true
类确认控制器<设计::确认控制器
包括接受提示
快到了
闪光[注意]=零
渲染布局:“设计为空”
结束
受保护的
重新发送后的def确认指令路径(资源)
用户\u几乎\u在那里\u路径
结束
确认后定义路径(资源名称、资源)
接受待定的邀请
#传入资源可以是:用户或:电子邮件
如果已登录?(:用户)
登录后(资源)
其他的
Gitlab::AppLogger.info(“电子邮件确认:用户名=#{resource.username}电子邮件=#{resource.Email}ip=#{request.remote_ip}”)
flash[:notice]=flash[:notice]+“请登录。”
新建会话路径(:用户,锚定:“登录窗格”)
结束
结束
登录后的def(资源)
为(资源)在路径中签名后
结束
结束

如何使它将我重定向到google.com?

在确认后从
返回
方法的路径。下面是谷歌的一个例子

class ConfirmationsController < Devise::ConfirmationsController
  ...

  protected


  def after_confirmation_path_for(resource_name, resource)
    ...
    'https://www.google.com' # assuming you're redirecting to Google
  end

end
类确认控制器
这是自定义确认控制器吗?如果没有,请在app/controllers目录中创建新的confirmations_controller.rb:

class ConfirmationsController < Devise::ConfirmationsController
  def show
    self.resource = resource_class.confirm_by_token(params[:confirmation_token])

    if resource.errors.empty?
      set_flash_message(:notice, :confirmed) if is_navigational_format?
      sign_in(resource_name, resource)
      respond_with_navigational(resource){ redirect_to your_desired_redirect_path }
    else
      respond_with_navigational(resource.errors, status: :unprocessable_entity){ render_with_scope :new }
    end
  end
end
类确认控制器
config/routes.rb
中,添加此行,以便designe将使用您的自定义
confirmationcontroller
。这假设Desive在用户表上运行(您可以编辑以匹配您的用户表)

design_用于:用户、控制器:{confirmations:'confirmations'}


答案链接:

只需在代码中覆盖
方法的
确认后路径的返回。您希望新的确认路径是什么?“以前接受的答案不再有效。”新行为与原始行为相同吗?阿法克·阿明的答案应该仍然有效。任何关于正在发生的事情的更多信息都会有帮助。你问过作者吗?在他们的代码中添加该功能并提交补丁怎么样?为什么以前接受的答案不再有效?如果答案不起作用,你的问题就会偏离方向,这意味着你需要问一个新问题,而不是坚持新的答案。请参阅这些关于meta的讨论:“谢谢你的回答,这在你回答问题时起了作用,但在更新到12.6之后,不幸的是,它不再起作用了。知道如何修复吗?在更新代码后,删除选定的答案是不公平的。如果事情发生了变化,问题也就发生了变化,这不是回答问题的人的错。相反,需要用所有新信息创建一个新问题。请看我上面评论中的链接页面。尽管这个答案应该被接受,但投票决定确保阿明至少获得一半的赏金。(并因此获得了全部的赏金)@theTinMan我认为是的,应该是一个真实文档的存储库。如果我接受这一点,来自谷歌的人不会得到正确的答案,尽管它当时还在工作。@Harry不,不是。它应该是问一个适用于你的问题,然后根据这个问题得到答案。这显然不是问一个问题,得到一个准确和正确的答案,然后以一种使答案无效的方式改变你的代码库。这个答案唯一的问题是,你在提出问题并收到答案后移动了门柱。感谢
config/routes.rb
中出现了两行新词:
#注册获取“用户/注册/欢迎”=>“注册”#欢迎“补丁”用户/注册/更新注册”=>“注册#更新_注册”
我不知道确认控制器是否是自定义的。我刚刚编辑了我在app/controllers/confirmations\u controller.rb中找到的一个。也许这两行新词会覆盖它?如果你想覆盖,你可以这样做。