Merge pull request #3372 from Katee/show-min-password-length-on-edit-password

Show minimum password length on edit password
This commit is contained in:
José Valim 2014-12-17 21:18:48 +01:00
commit 5badce5e8e
5 changed files with 15 additions and 9 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -6,6 +6,9 @@
<div class="field">
<%= f.label :password, "New password" %><br />
<% if @validatable %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autofocus: true, autocomplete: "off" %>
</div>

View File

@ -7,7 +7,7 @@
<%= f.full_error :reset_password_token %>
<div class="form-inputs">
<%= 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 %>
</div>