设计了signed_up_but_unconfirmed won; t show

时间:2015-03-27 11:05:33

标签: ruby-on-rails devise devise-confirmable notice

我最近添加了确认到我的rails应用程序与设计。这一切都很顺利,但是当我创建一个新用户时,我得到了

signed_up: "Welcome! You have signed up successfully."

而不是

signed_up_but_unconfirmed:"A message with a confirmation link has been sent to your email address. Please follow the link to activate your account."

即使他们未经证实。添加确认更改此内容时,我需要做些什么吗?谢谢!

更新

我使用自己的用户控制器并将其路由如下:

的routes.rb

  devise_for :users, :controllers => {:registrations => "users"}

  devise_scope :user do
    get 'users/:id' => 'users#show', as: "user"
  end

1 个答案:

答案 0 :(得分:0)

您可以使用此

获取路线
as :user do
    patch '/users/confirmation' => 'users/confirmations#update', :via => :patch, :as => :update_user_confirmation
end

并将confirmmations_controller包含以下内容:

class Users::ConfirmationsController < Devise::ConfirmationsController
  skip_before_filter :authenticate_user!
  before_action :check_if_current_user

  # PUT /resource/confirmation
  def update
    with_unconfirmed_confirmable do
      if @confirmable.has_no_password?
        @confirmable.attempt_set_password(params[:user])
        if @confirmable.valid? && @confirmable.password_match?
          do_confirm
        else
          do_show
          @confirmable.errors.clear #so that we wont render :new
        end
      else
        self.class.add_error_on(self, :email, :password_already_set)
      end
    end

    if !@confirmable.errors.empty?
      render 'devise/confirmations/new' #Change this if you don't have the views on default path
    end
  end

  # GET /resource/confirmation?confirmation_token=abcdef
  def show
    with_unconfirmed_confirmable do
      if @confirmable.has_no_password?
        do_show
      else
        do_confirm
      end
    end
    if !@confirmable.errors.empty?
      self.resource = @confirmable
      render 'devise/confirmations/new' #Change this if you don't have the views on default path
    end
  end

  protected

  def with_unconfirmed_confirmable
    original_token = params[:confirmation_token]
    confirmation_token = Devise.token_generator.digest(User, :confirmation_token, original_token)
    @confirmable = User.find_or_initialize_with_error_by(:confirmation_token, confirmation_token)
    if !@confirmable.new_record?
      @confirmable.only_if_unconfirmed { yield }
    end
  end

  def do_show
    @confirmation_token = params[:confirmation_token]
    @requires_password = true
    self.resource = @confirmable
    render 'devise/confirmations/show' #Change this if you don't have the views on default path
  end

  def do_confirm
    @confirmable.confirm!
    set_flash_message :notice, :confirmed
    sign_in_and_redirect(resource_name, @confirmable)
  end

  def check_if_current_user
    if current_user.present?
      render :file => "#{Rails.root.to_s}/public/confirmed.html", :status => :unauthorized
    end
  end

end

希望它有用。