summaryrefslogtreecommitdiff
path: root/users/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'users/app/models')
-rw-r--r--users/app/models/email.rb4
-rw-r--r--users/app/models/user.rb30
2 files changed, 29 insertions, 5 deletions
diff --git a/users/app/models/email.rb b/users/app/models/email.rb
index 7c88c51..45101c1 100644
--- a/users/app/models/email.rb
+++ b/users/app/models/email.rb
@@ -3,11 +3,9 @@ class Email
property :email, String
- validates :email_forward,
+ validates :email,
:format => { :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/, :message => "needs to be a valid email address"}
- timestamps!
-
def to_s
email
end
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index a41554d..7d1691a 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -28,16 +28,42 @@ class User < CouchRest::Model::Base
# TODO: write a proper email validator to be used in the different places
validates :email,
- :format => { :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/, :message => "needs to be a valid email address"}
+ :format => { :with => /\A(([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,}))?\Z/, :message => "needs to be a valid email address"}
validates :email_forward,
- :format => { :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/, :message => "needs to be a valid email address"}
+ :format => { :with => /\A(([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,}))?\Z/, :message => "needs to be a valid email address"}
timestamps!
design do
view :by_login
view :by_created_at
+ view :by_email
+ view :by_email_alias,
+ :map => <<-EOJS
+ function(doc) {
+ if (doc.type != 'User') {
+ return;
+ }
+ doc.email_aliases.forEach(function(alias){
+ emit(alias.email, doc);
+ });
+ }
+ EOJS
+ view :by_email_or_alias,
+ :map => <<-EOJS
+ function(doc) {
+ if (doc.type != 'User') {
+ return;
+ }
+ if (doc.email) {
+ emit(doc.email, doc);
+ }
+ doc.email_aliases.forEach(function(alias){
+ emit(alias.email, doc);
+ });
+ }
+ EOJS
end
class << self