FIX: Better error messages when name is too long
Previously you'd get a server side generic error due to a password check failing. Now the input element has a maxlength attribute and the server side will respond with a nicer error message if the value is too long.
This commit is contained in:
parent
31775c996c
commit
ee17138c0f
|
@ -30,7 +30,7 @@
|
||||||
<label class="control-label">{{i18n 'user.name.title'}}</label>
|
<label class="control-label">{{i18n 'user.name.title'}}</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
{{#if model.can_edit_name}}
|
{{#if model.can_edit_name}}
|
||||||
{{text-field value=newNameInput classNames="input-xxlarge"}}
|
{{text-field value=newNameInput classNames="input-xxlarge" maxlength="255"}}
|
||||||
{{else}}
|
{{else}}
|
||||||
<span class='static'>{{model.name}}</span>
|
<span class='static'>{{model.name}}</span>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -1402,10 +1402,11 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def name_validator
|
def name_validator
|
||||||
if name.present? &&
|
if name.present?
|
||||||
(confirm_password?(name) || confirm_password?(name&.downcase))
|
name_pw = name[0...User.max_password_length]
|
||||||
|
if confirm_password?(name_pw) || confirm_password?(name_pw.downcase)
|
||||||
errors.add(:name, :same_as_password)
|
errors.add(:name, :same_as_password)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,11 @@ describe User do
|
||||||
expect(user.errors.full_messages.first)
|
expect(user.errors.full_messages.first)
|
||||||
.to include(user_error_message(:name, :same_as_password))
|
.to include(user_error_message(:name, :same_as_password))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "doesn't raise an error if the name is longer than the max password length" do
|
||||||
|
user.name = 'x' * 220
|
||||||
|
expect(user).to be_valid
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'emails' do
|
describe 'emails' do
|
||||||
|
|
Loading…
Reference in New Issue