Skip to content

Commit

Permalink
Update username validation
Browse files Browse the repository at this point in the history
  • Loading branch information
dtaniwaki committed May 8, 2016
1 parent 131088c commit a24291c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class User < ApplicationRecord
validates :email, :encrypted_password, presence: true
validates :name, :username, presence: true, if: -> (u) { u.accepted_or_not_invited? || u.accepting_invitation? }
validates :name, length: { minimum: 1, maximum: 100 }, allow_blank: true
validates :username, format: { with: /\A[a-zA-Z0-9_\-]+\Z/ }, length: { minimum: 1, maximum: 20 }, allow_blank: true
validates :username,
format: { with: /\A([a-zA-Z0-9_][a-zA-Z0-9_\-\.]*[a-zA-Z0-9_]|[a-zA-Z0-9_])\Z/ },
length: { minimum: 1, maximum: 20 },
uniqueness: { case_sensitive: false },
allow_blank: true

def self.find_or_invite_by(params, user)
user = User.find_by(params)
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/invitations/edit.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ h2 = t 'devise.invitations.edit.header'
= simple_form_for resource, as: resource_name, url: invitation_path(resource_name), html: { autocomplete: 'off', method: :put } do |f|
= f.error_notification
= f.input :invitation_token, as: :hidden
= f.input :username, input_html: { autocomplete: 'off' }, required: true
= f.input :username, input_html: { autocomplete: 'off' }, required: true, hint: %|Username can contain only letters, digits, '_', '-' and '.'. Cannot start or end with '-' and '.'.|
= f.input :name, input_html: { autocomplete: 'off' }, required: true
= f.input :password, input_html: { autocomplete: 'off' }, required: true
= f.input :password_confirmation, input_html: { autocomplete: 'off' }, required: true
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/registrations/edit.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ h2 = "Edit #{resource_name.to_s.humanize}"

= simple_form_for resource, as: resource_name, url: registration_path(resource_name), html: { method: :put, autocomplete: 'off' } do |f|
= f.error_notification
= f.input :username, input_html: { autocomplete: 'off' }, required: true
= f.input :username, input_html: { autocomplete: 'off' }, required: true, hint: %|Username can contain only letters, digits, '_', '-' and '.'. Cannot start or end with '-' and '.'.|
= f.input :name, input_html: { autocomplete: 'off' }, required: true
= f.input :email, hint: email_hint, input_html: { autocomplete: 'off' }
= f.input :password, hint: password_hint, input_html: { autocomplete: 'off', data: { 'password-strength': 8 } }
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/registrations/new.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ h2 Sign up

= simple_form_for resource, as: resource_name, url: registration_path(resource_name), html: { autocomplete: 'off' } do |f|
= f.error_notification
= f.input :username, input_html: { autocomplete: 'off' }, required: true
= f.input :username, input_html: { autocomplete: 'off' }, required: true, hint: %|Username can contain only letters, digits, '_', '-' and '.'. Cannot start or end with '-' and '.'.|
= f.input :name, input_html: { autocomplete: 'off' }, required: true
= f.input :email, input_html: { autocomplete: 'off' }
= f.input :password, hint: password_hint, input_html: { autocomplete: 'off', data: { 'password-strength': 8 } }, required: true
Expand Down

0 comments on commit a24291c

Please sign in to comment.