summaryrefslogtreecommitdiff
path: root/users/app/models
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2013-07-18 12:52:02 +0200
committerAzul <azul@leap.se>2013-07-24 10:55:50 +0200
commitd96fac2de074bbe3a44d888af5ceaff45b1b9b27 (patch)
treefbebc684c2227c1eceb9bb67c7ecdadb667aefc5 /users/app/models
parenta2e49d1b946fa34dd41ce1f07920515df13e09db (diff)
validations of email format and local domain moved over
Diffstat (limited to 'users/app/models')
-rw-r--r--users/app/models/email.rb20
-rw-r--r--users/app/models/local_email.rb20
2 files changed, 29 insertions, 11 deletions
diff --git a/users/app/models/email.rb b/users/app/models/email.rb
index 90fc645..1bcff1c 100644
--- a/users/app/models/email.rb
+++ b/users/app/models/email.rb
@@ -1,13 +1,11 @@
class Email < String
-=begin
- included do
- validates :email,
- :format => {
- :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/,
- :message => "needs to be a valid email address"
- }
- end
-=end
+ include ActiveModel::Validations
+
+ validates :email,
+ :format => {
+ :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/,
+ :message => "needs to be a valid email address"
+ }
def to_partial_path
"emails/email"
@@ -17,4 +15,8 @@ class Email < String
to_s
end
+ def email
+ self
+ end
+
end
diff --git a/users/app/models/local_email.rb b/users/app/models/local_email.rb
index d919102..e71d494 100644
--- a/users/app/models/local_email.rb
+++ b/users/app/models/local_email.rb
@@ -6,6 +6,18 @@ class LocalEmail < Email
validate :differs_from_login
=end
+ def self.domain
+ APP_CONFIG[:domain]
+ end
+
+ validates :email,
+ :format => {
+ :with => /@#{domain}\Z/i,
+ :message => "needs to end in @#{domain}"
+ }
+
+
+
def initialize(s)
super
append_domain_if_needed
@@ -16,7 +28,11 @@ class LocalEmail < Email
end
def handle
- gsub(/@#{APP_CONFIG[:domain]}/i, '')
+ gsub(/@#{domain}/i, '')
+ end
+
+ def domain
+ LocalEmail.domain
end
protected
@@ -46,7 +62,7 @@ class LocalEmail < Email
def append_domain_if_needed
unless self.index('@')
- self << "@#{APP_CONFIG[:domain]}"
+ self << '@' + domain
end
end