summaryrefslogtreecommitdiff
path: root/app/models/user.rb
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2014-05-28 10:45:14 +0200
committerAzul <azul@leap.se>2014-05-28 10:55:42 +0200
commit154d32bbc7cfe21d83141ff2c9a3d805165231b8 (patch)
treeedbb82449a9a50c0b5141e435939150bef7dee57 /app/models/user.rb
parent1d0d61389011a8d0d169bc139590d90a6fbbac60 (diff)
use Identity for testing login availability
We create an identity alongside each user. Make sure the identity is valid when creating the user. This also ensures that the login picked is available because otherwise the identities address would not be available anymore.
Diffstat (limited to 'app/models/user.rb')
-rw-r--r--app/models/user.rb13
1 files changed, 6 insertions, 7 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 6678de6..6b4d1a9 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -24,7 +24,7 @@ class User < CouchRest::Model::Base
:uniqueness => true,
:if => :serverside?
- validate :login_is_unique_alias
+ validate :identity_is_valid
validates :password_salt, :password_verifier,
:format => { :with => /\A[\dA-Fa-f]+\z/, :message => "Only hex numbers allowed" }
@@ -161,12 +161,11 @@ class User < CouchRest::Model::Base
# Validation Functions
##
- def login_is_unique_alias
- alias_identity = Identity.find_by_address(self.email_address)
- return if alias_identity.blank?
- if alias_identity.user != self
- errors.add(:login, "has already been taken")
- end
+ def identity_is_valid
+ refresh_identity
+ return if identity.valid?
+ # hand on the first error only for now
+ self.errors.add(:login, identity.errors.messages.values.first)
end
def password