diff options
author | Azul <azul@leap.se> | 2013-08-21 09:49:26 +0200 |
---|---|---|
committer | Azul <azul@leap.se> | 2013-08-21 09:49:26 +0200 |
commit | 75db45671d432a0d81805ad50c6cc9f8f7eff7a7 (patch) | |
tree | 48504f5dc9dae4953aab37b8a142dccd8b895020 /users/app/models/login_format_validation.rb | |
parent | 115d96398246dcda23a51728dfafe1ea3c8ede88 (diff) |
use the same login validations on sessions and users
The session ones were outdated so valid usernames could not login if they contained a '.'
Refactored so both models use the same module for this validation to ensure consistency.
Diffstat (limited to 'users/app/models/login_format_validation.rb')
-rw-r--r-- | users/app/models/login_format_validation.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/users/app/models/login_format_validation.rb b/users/app/models/login_format_validation.rb new file mode 100644 index 0000000..1d02bd1 --- /dev/null +++ b/users/app/models/login_format_validation.rb @@ -0,0 +1,19 @@ +module LoginFormatValidation + extend ActiveSupport::Concern + + included do + # Have multiple regular expression validations so we can get specific error messages: + validates :login, + :format => { :with => /\A.{2,}\z/, + :message => "Login must have at least two characters"} + validates :login, + :format => { :with => /\A[a-z\d_\.-]+\z/, + :message => "Only lowercase letters, digits, . - and _ allowed."} + validates :login, + :format => { :with => /\A[a-z].*\z/, + :message => "Login must begin with a lowercase letter"} + validates :login, + :format => { :with => /\A.*[a-z\d]\z/, + :message => "Login must end with a letter or digit"} + end +end |