devise-security gem找不到Devise控制器,rails 5.2

时间:2018-05-01 12:35:58

标签: ruby-on-rails devise

使用devise-security gem

ActionController::UrlGenerationError at /

No route matches {:action=>"show", :controller=>"devise/password_expired"}

在app / models / user.rb

  devise :database_authenticatable, :registerable, :recoverable,
         :rememberable, :trackable, :validatable, :timeoutable, 
         :password_expirable, :password_archivable, :session_limitable, :expirable, # devise-security extension gem
         timeout_in: 45.minutes

在config / initializers / devise-security.rb

 Devise.setup do |config|
  # ==> Security Extension
  # Configure security extension for devise

  # Should the password expire (e.g 3.months)
  config.expire_password_after = 3.months

  # Need 1 char of A-Z, a-z and 0-9
  config.password_regex = /(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/

  # How many passwords to keep in archive
  config.password_archiving_count = 5

  # Deny old password (true, false, count)
  config.deny_old_passwords = true


  # Time period for account expiry from last_activity_at
  config.expire_after = 90.days
end

配置/ routes.rb中

  devise_for :users,
controllers: { registrations: "registrations", sessions: "sessions", passwords: "passwords" },
path_names: {sign_in: "login", sign_out: "logout"}

rake routes

                          new_user_session GET                       /users/login(.:format)                                                            sessions#new
                          user_session POST                      /users/login(.:format)                                                            sessions#create
                  destroy_user_session DELETE                    /users/logout(.:format)                                                           sessions#destroy
                     new_user_password GET                       /users/password/new(.:format)                                                     passwords#new
                    edit_user_password GET                       /users/password/edit(.:format)                                                    passwords#edit
                         user_password PATCH                     /users/password(.:format)                                                         passwords#update
                                       PUT                       /users/password(.:format)                                                         passwords#update
                                       POST                      /users/password(.:format)                                                         passwords#create
              cancel_user_registration GET                       /users/cancel(.:format)                                                           registrations#cancel
                 new_user_registration GET                       /users/sign_up(.:format)                                                          registrations#new
                edit_user_registration GET                       /users/edit(.:format)                                                             registrations#edit
                     user_registration PATCH                     /users(.:format)                                                                  registrations#update
                                       PUT                       /users(.:format)                                                                  registrations#update
                                       DELETE                    /users(.:format)                                                                  registrations#destroy
                                       POST                      /users(.:format)                                                                  registrations#create
                 user_password_expired GET                       /users/password_expired(.:format)                                                 devise/password_expired#show
                                       PATCH                     /users/password_expired(.:format)                                                 devise/password_expired#update
                                       PUT                       /users/password_expired(.:format)                                                 devise/password_expired#update

堆栈跟踪:

 Started GET "/" for 127.0.0.1 at 2018-05-01 13:27:54 +0100
Processing by MyEngine::DashboardController#index as HTML
  User Load (0.5ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
  User Update All (2.7ms)  UPDATE "users" SET "last_activity_at" = '2018-05-01 12:27:54.495467' WHERE "users"."id" = 1
Completed 401 Unauthorized in 10ms (ActiveRecord: 3.3ms)



ActionController::UrlGenerationError - No route matches {:action=>"show", :controller=>"devise/password_expired"}

更新:

    # path for change password
    def change_password_required_path_for(resource_or_scope = nil)
      scope       = Devise::Mapping.find_scope!(resource_or_scope)
      change_path = "#{scope}_password_expired_path"
      send(change_path)
    end

(change_path是" user_password_expired_pa​​th")

只有在我改变

时才有效
send(change_path)

main_app.send(change_path)

0 个答案:

没有答案