1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Set minimum password length for edit and new views (#4068)

* Set minimum password length for edit and new views

* Update edit.html.erb

* Update registerable_test.rb
This commit is contained in:
Matt Yanchek 2016-05-05 13:16:41 -07:00 committed by Lucas Mazza
parent a45c4c0ac4
commit 85bcbdf18b
3 changed files with 11 additions and 1 deletions

View file

@ -1,11 +1,11 @@
class Devise::RegistrationsController < DeviseController class Devise::RegistrationsController < DeviseController
prepend_before_action :require_no_authentication, only: [:new, :create, :cancel] prepend_before_action :require_no_authentication, only: [:new, :create, :cancel]
prepend_before_action :authenticate_scope!, only: [:edit, :update, :destroy] prepend_before_action :authenticate_scope!, only: [:edit, :update, :destroy]
prepend_before_action :set_minimum_password_length, only: [:new, :edit]
# GET /resource/sign_up # GET /resource/sign_up
def new def new
build_resource({}) build_resource({})
set_minimum_password_length
yield resource if block_given? yield resource if block_given?
respond_with self.resource respond_with self.resource
end end

View file

@ -15,6 +15,10 @@
<div class="field"> <div class="field">
<%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br /> <%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password, autocomplete: "off" %> <%= f.password_field :password, autocomplete: "off" %>
<% if @minimum_password_length %>
<br />
<em><%= @minimum_password_length %> characters minimum</em>
<% end %>
</div> </div>
<div class="field"> <div class="field">

View file

@ -219,6 +219,12 @@ class RegistrationTest < Devise::IntegrationTest
assert_contain "Password confirmation doesn't match Password" assert_contain "Password confirmation doesn't match Password"
refute User.to_adapter.find_first.valid_password?('pas123') refute User.to_adapter.find_first.valid_password?('pas123')
end end
test 'a signed in user should see a warning about minimum password length' do
sign_in_as_user
get edit_user_registration_path
assert_contain 'characters minimum'
end
test 'a signed in user should be able to cancel their account' do test 'a signed in user should be able to cancel their account' do
sign_in_as_user sign_in_as_user