Gitlab电子邮件确认重定向

时间:2019-02-07 20:36:08

标签: ruby redirect devise gitlab

Gitlab默认情况下,在确认电子邮件后将用户重定向到主页。我想改址外。我认为没有配置选项,所以我想问如何破解它。

我发现了confirmations_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

如何使其重定向到google.com?红宝石的新手。

2 个答案:

答案 0 :(得分:0)

after_confirmation_path_for方法返回。这是Google的示例。

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

答案 1 :(得分:0)

这是自定义确认控制器吗?如果没有,请在app / controllers目录中创建一个新的Confirmation_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中,添加以下行,以便Devise使用您的自定义ConfirmationsController。假设Devise在用户表上运行(您可以进行编辑以匹配您的表)。

devise_for :users, controllers: { confirmations: 'confirmations' }

答案链接:How to make Devise redirect after confirmation