summaryrefslogtreecommitdiff
path: root/users/app/models/user.rb
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-12-12 15:41:14 +0100
committerAzul <azul@leap.se>2012-12-12 15:41:14 +0100
commit60e8fc3e1309d1c972a7695e3344e63f5d633a06 (patch)
treed4bdc2d2e45702d5241c22404d77e8e4b2205378 /users/app/models/user.rb
parentd9fa19106998bc6ac484494334dcf150bb6aa5d5 (diff)
find users by email and aliases
Diffstat (limited to 'users/app/models/user.rb')
-rw-r--r--users/app/models/user.rb30
1 files changed, 28 insertions, 2 deletions
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