Guest User

Untitled

a guest
Oct 17th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. diff --cc app/controllers/application_controller.rb
  2. index 9d4f99a,9d4f99a,9d4f99a,9d4f99a..7313d36
  3. --- a/app/controllers/application_controller.rb
  4. +++ b/app/controllers/application_controller.rb
  5. @@@@@ -3,7 -3,7 -3,7 -3,7 +3,6 @@@@@ class ApplicationController < ActionCon
  6.  
  7. before_filter :initialize_query_filter
  8. before_filter :authenticate_user!
  9. ---- before_filter :handle_password_change
  10.  
  11. private
  12.  
  13. @@@@@ -23,30 -23,30 -23,30 -23,30 +22,4 @@@@@
  14. end
  15. end
  16.  
  17. ---- # lookup if an password change needed
  18. ---- def handle_password_change
  19. ---- if !devise_controller? and !request.format.nil? && request.format.html?
  20. ---- Devise.mappings.keys.flatten.any? do |scope|
  21. ---- if signed_in?(scope) and warden.session(scope)[:password_expired]
  22. ---- session["#{scope}_return_to"] = request.path if request.get?
  23. ---- redirect_for_password_change scope
  24. ---- return
  25. ---- end
  26. ---- end
  27. ---- end
  28. ---- end
  29. ----
  30. ---- # redirect for password update with alert message
  31. ---- def redirect_for_password_change(scope)
  32. ---- redirect_to change_password_required_path_for(scope), :alert => I18n.t('change_required', {:scope => 'devise.password_expired'})
  33. ---- end
  34. ----
  35. ---- # path for change password
  36. ---- def change_password_required_path_for(resource_or_scope = nil)
  37. ---- scope = Devise::Mapping.find_scope!(resource_or_scope)
  38. ---- change_path = "#{scope}_password_expired_path"
  39. ---- send(change_path)
  40. ---- end
  41. ----
  42. ----
  43. end
  44. diff --cc app/controllers/password_expired_controller.rb
  45. index 3eb1091,3eb1091,3eb1091,3eb1091..0000000
  46. --- a/app/controllers/password_expired_controller.rb
  47. +++ b/app/controllers/password_expired_controller.rb
  48. diff --cc app/models/password_expirable.rb
  49. index a8a2ecb,a8a2ecb,a8a2ecb,a8a2ecb..0000000
  50. --- a/app/models/password_expirable.rb
  51. +++ b/app/models/password_expirable.rb
  52. diff --cc app/models/user.rb
  53. index 7d66b32,7d66b32,7d66b32,7d66b32..bc6f635
  54. --- a/app/models/user.rb
  55. +++ b/app/models/user.rb
  56. @@@@@ -1,6 -1,6 -1,6 -1,6 +1,6 @@@@@
  57. class User
  58. include Mongoid::Document
  59. ---- devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable, :registerable, :password_expirable
  60. ++++ devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable, :registerable
  61.  
  62. ## Database authenticatable
  63. field :email, :type => String, :null => false, :default => ""
  64. @@@@@ -20,15 -20,15 -20,15 -20,15 +20,9 @@@@@
  65. field :current_sign_in_ip, :type => String
  66. field :last_sign_in_ip, :type => String
  67.  
  68. ---- ## Password expirable
  69. ---- field :password_changed_at, :type => Time
  70. ----
  71. ## Encryptable
  72. # field :password_salt, :type => String
  73.  
  74. validates_uniqueness_of :email, :case_sensitive => false
  75. attr_accessible :email, :password, :password_confirmation, :remember_me
  76. ----
  77. ---- validates :password, format: /^(?=.*\d)(?=.*[a-zA-Z]).{7,}$/
  78. ----
  79. end
  80. diff --cc app/views/password_expired/show.html.erb
  81. index 2873988,2873988,2873988,2873988..0000000
  82. --- a/app/views/password_expired/show.html.erb
  83. +++ b/app/views/password_expired/show.html.erb
  84. diff --cc config/initializers/devise.rb
  85. index c65b653,c65b653,c65b653,c65b653..a2bee5a
  86. --- a/config/initializers/devise.rb
  87. +++ b/config/initializers/devise.rb
  88. @@@@@ -121,7 -121,7 -121,7 -121,7 +121,7 @@@@@ Devise.setup do |config
  89.  
  90. # ==> Configuration for :validatable
  91. # Range for password length. Default is 6..128.
  92. ---- config.password_length = 7..128
  93. ++++ # config.password_length = 6..128
  94.  
  95. # Email regex used to validate email formats. It simply asserts that
  96. # an one (and only one) @ exists in the given string. This is mainly
  97. @@@@@ -221,25 -221,25 -221,25 -221,25 +221,3 @@@@@
  98. # manager.default_strategies(:scope => :user).unshift :some_external_strategy
  99. # end
  100. end
  101. ----
  102. ----Warden::Manager.after_authentication do |record, warden, options|
  103. ---- if record.respond_to?(:need_change_password?)
  104. ---- warden.session(options[:scope])[:password_expired] = record.need_change_password?
  105. ---- end
  106. ----end
  107. ----
  108. ----module ActionDispatch::Routing
  109. ---- class Mapper
  110. ----
  111. ---- protected
  112. ----
  113. ---- # route for handle expired passwords
  114. ---- def devise_password_expired(mapping, controllers)
  115. ---- resource :password_expired, :only => [:show, :update], :path => mapping.path_names[:password_expired], :controller => controllers[:password_expired]
  116. ---- end
  117. ----
  118. ---- end
  119. ----end
  120. ----
  121. ----Devise.add_module :password_expirable, :model => 'password_expirable', :controller => :password_expirable, :route => :password_expired
  122. ----
Add Comment
Please, Sign In to add comment