summaryrefslogtreecommitdiff
path: root/users/app/models/user.rb
diff options
context:
space:
mode:
Diffstat (limited to 'users/app/models/user.rb')
-rw-r--r--users/app/models/user.rb44
1 files changed, 39 insertions, 5 deletions
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index fb7f0aa..546d571 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -6,8 +6,6 @@ class User < CouchRest::Model::Base
property :password_verifier, String, :accessible => true
property :password_salt, String, :accessible => true
- property :public_key, :accessible => true
-
property :enabled, TrueClass, :default => true
validates :login, :password_salt, :password_verifier,
@@ -49,14 +47,50 @@ class User < CouchRest::Model::Base
view :by_created_at
end # end of design
+ # We proxy access to the pgp_key. So we need to make sure
+ # the updated identity actually gets saved.
+ def save(*args)
+ super
+ identity.user_id ||= self.id
+ identity.save if identity.changed?
+ end
+
+ # So far this only works for creating a new user.
+ # TODO: Create an alias for the old login when changing the login
+ def login=(value)
+ write_attribute 'login', value
+ @identity = build_identity
+ end
+
+ # DEPRECATED
+ #
+ # Please access identity.keys[:pgp] directly
+ def public_key=(value)
+ identity.keys[:pgp] = value
+ end
+
+ # DEPRECATED
+ #
+ # Please access identity.keys[:pgp] directly
+ def public_key
+ identity.keys[:pgp]
+ end
+
class << self
alias_method :find_by_param, :find
end
+ # this is the main identity. login@domain.tld
+ # aliases and forwards are represented in other identities.
+ def identity
+ @identity ||=
+ Identity.find_by_address_and_destination([email_address, email_address])
+ end
+
def create_identity(attribs = {}, &block)
- identity = build_identity(attribs, &block)
- identity.save
- identity
+ new_identity = build_identity(attribs, &block)
+ new_identity.save
+ new_identity
end
def build_identity(attribs = {}, &block)