summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/anonymous_user.rb4
-rw-r--r--app/models/identity.rb6
-rw-r--r--app/models/service_level.rb8
-rw-r--r--app/models/token.rb4
-rw-r--r--app/models/user.rb9
5 files changed, 31 insertions, 0 deletions
diff --git a/app/models/anonymous_user.rb b/app/models/anonymous_user.rb
index 360a577..87239eb 100644
--- a/app/models/anonymous_user.rb
+++ b/app/models/anonymous_user.rb
@@ -13,6 +13,10 @@ class AnonymousUser < Object
nil
end
+ def email
+ nil
+ end
+
def email_address
nil
end
diff --git a/app/models/identity.rb b/app/models/identity.rb
index 9b97b51..ad8c01e 100644
--- a/app/models/identity.rb
+++ b/app/models/identity.rb
@@ -70,6 +70,12 @@ class Identity < CouchRest::Model::Base
end
end
+ def self.destroy_all_for(user)
+ Identity.by_user_id.key(user.id).each do |identity|
+ identity.destroy
+ end
+ end
+
def self.destroy_all_disabled
Identity.disabled.each do |identity|
identity.destroy
diff --git a/app/models/service_level.rb b/app/models/service_level.rb
index 5dd8838..a8df55b 100644
--- a/app/models/service_level.rb
+++ b/app/models/service_level.rb
@@ -24,6 +24,14 @@ class ServiceLevel
end
end
+ def provides?(service)
+ services.include? service
+ end
+
+ def services
+ config_hash[:services] || []
+ end
+
protected
def limited_cert?
diff --git a/app/models/token.rb b/app/models/token.rb
index 4856c31..e759ee3 100644
--- a/app/models/token.rb
+++ b/app/models/token.rb
@@ -30,6 +30,10 @@ class Token < CouchRest::Model::Base
end
end
+ def to_s
+ id
+ end
+
def authenticate
if expired?
destroy
diff --git a/app/models/user.rb b/app/models/user.rb
index c297ac8..6678de6 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -61,6 +61,15 @@ class User < CouchRest::Model::Base
login
end
+ # use this if you want to get a working email address only.
+ def email
+ if effective_service_level.provides?('email')
+ email_address
+ end
+ end
+
+ # use this if you want the email address associated with a
+ # user no matter if the user actually has a local email account
def email_address
LocalEmail.new(login)
end