diff --git a/app/controllers/devise/passwords_controller.rb b/app/controllers/devise/passwords_controller.rb index d88ebdb6..5e3d3285 100644 --- a/app/controllers/devise/passwords_controller.rb +++ b/app/controllers/devise/passwords_controller.rb @@ -23,6 +23,7 @@ class Devise::PasswordsController < DeviseController # GET /resource/password/edit?reset_password_token=abcdef def edit self.resource = resource_class.new + set_minimum_password_length resource.reset_password_token = params[:reset_password_token] end diff --git a/app/controllers/devise/registrations_controller.rb b/app/controllers/devise/registrations_controller.rb index df65aa24..b66b4af8 100644 --- a/app/controllers/devise/registrations_controller.rb +++ b/app/controllers/devise/registrations_controller.rb @@ -5,10 +5,7 @@ class Devise::RegistrationsController < DeviseController # GET /resource/sign_up def new build_resource({}) - @validatable = devise_mapping.validatable? - if @validatable - @minimum_password_length = resource_class.password_length.min - end + set_minimum_password_length yield resource if block_given? respond_with self.resource end @@ -31,10 +28,7 @@ class Devise::RegistrationsController < DeviseController end else clean_up_passwords resource - @validatable = devise_mapping.validatable? - if @validatable - @minimum_password_length = resource_class.password_length.min - end + set_minimum_password_length respond_with resource end end diff --git a/app/controllers/devise_controller.rb b/app/controllers/devise_controller.rb index 722170ca..4ab8d570 100644 --- a/app/controllers/devise_controller.rb +++ b/app/controllers/devise_controller.rb @@ -154,6 +154,14 @@ MESSAGE end end + # Sets minimum password length to show to user + def set_minimum_password_length + @validatable = devise_mapping.validatable? + if @validatable + @minimum_password_length = resource_class.password_length.min + end + end + def devise_i18n_options(options) options end diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb index 1b2ff26a..a2ce2f5b 100644 --- a/app/views/devise/passwords/edit.html.erb +++ b/app/views/devise/passwords/edit.html.erb @@ -6,6 +6,9 @@
<%= f.label :password, "New password" %>
+ <% if @validatable %> + (<%= @minimum_password_length %> characters minimum) + <% end %>
<%= f.password_field :password, autofocus: true, autocomplete: "off" %>
diff --git a/lib/generators/templates/simple_form_for/passwords/edit.html.erb b/lib/generators/templates/simple_form_for/passwords/edit.html.erb index 8f995edc..90500324 100644 --- a/lib/generators/templates/simple_form_for/passwords/edit.html.erb +++ b/lib/generators/templates/simple_form_for/passwords/edit.html.erb @@ -7,7 +7,7 @@ <%= f.full_error :reset_password_token %>
- <%= f.input :password, label: "New password", required: true, autofocus: true %> + <%= f.input :password, label: "New password", required: true, autofocus: true, hint: ("#{@minimum_password_length} characters minimum" if @validatable) %> <%= f.input :password_confirmation, label: "Confirm your new password", required: true %>