2

我想覆盖这个控制器,此时创建方法,我已经对其进行了一些更改

class RegistrationsController < Devise::RegistrationsController
    def create
      unless session[:invitation_token].blank?
        super
      else
        redirect_to new_user_session_path and return
      end
    end

end

遵循注册流程后,在数据库中创建资源,就像超类定义它一样

  def create
    build_resource

    if resource.save
      if resource.active_for_authentication?
        set_flash_message :notice, :signed_up if is_navigational_format?
        sign_up(resource_name, resource)
        respond_with resource, :location => after_sign_up_path_for(resource)
      else
        set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
        expire_session_data_after_sign_in!
        respond_with resource, :location => after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      respond_with resource
    end
  end

但在某种程度上,方法 active_for_authetication 存在问题?

抛出错误,我不知道为什么我检查了所有 gem,它说该方法被其他模块覆盖,正常定义是

def active_for_authentication?
  true
end

但我不使用任何覆盖它的模块,所以由于某种原因,它似乎设计它无法成功验证,但用户存储在数据库中,我在注册后登录。

这是我注册用户的配置。

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me, :username
end

这是我设计的初始化程序

Devise.setup do |config|

  config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"

  require 'devise/orm/active_record'
  config.case_insensitive_keys = [ :email ]
  config.strip_whitespace_keys = [ :email ]
  config.skip_session_storage = [:http_auth]
  config.stretches = Rails.env.test? ? 1 : 10
  config.password_length = 6..15
  config.reset_password_within = 6.hours
  config.sign_out_via = :delete


end
4

0 回答 0