diff options
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/email.rb | 31 | ||||
| -rw-r--r-- | app/models/identity.rb | 2 | ||||
| -rw-r--r-- | app/models/local_email.rb | 66 | ||||
| -rw-r--r-- | app/models/login_format_validation.rb | 21 | ||||
| -rw-r--r-- | app/models/user.rb | 2 | 
5 files changed, 4 insertions, 118 deletions
| diff --git a/app/models/email.rb b/app/models/email.rb deleted file mode 100644 index 4090275..0000000 --- a/app/models/email.rb +++ /dev/null @@ -1,31 +0,0 @@ -class Email < String -  include ActiveModel::Validations - -  validates :email, -    :format => { -      :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/, #local part of email is case-sensitive, so allow uppercase letter. -      :message => "needs to be a valid email address" -    } - -  # Make sure we can call Email.new(nil) and get an invalid email address -  def initialize(s) -    super(s.to_s) -  end - -  def to_partial_path -    "emails/email" -  end - -  def to_param -    to_s -  end - -  def email -    self -  end - -  def handle -    self.split('@').first -  end - -end diff --git a/app/models/identity.rb b/app/models/identity.rb index f987e4e..92f8f7a 100644 --- a/app/models/identity.rb +++ b/app/models/identity.rb @@ -1,3 +1,5 @@ +require 'login_format_validation' +require 'local_email'  #  # Identity states:  # diff --git a/app/models/local_email.rb b/app/models/local_email.rb deleted file mode 100644 index ded7baf..0000000 --- a/app/models/local_email.rb +++ /dev/null @@ -1,66 +0,0 @@ -class LocalEmail < Email - -  BLACKLIST_FROM_RFC2142 = [ -    'postmaster', 'hostmaster', 'domainadmin', 'webmaster', 'www', -    'abuse', 'noc', 'security', 'usenet', 'news', 'uucp', -    'ftp', 'sales', 'marketing', 'support', 'info' -  ] - -  def self.domain -    APP_CONFIG[:domain] -  end - -  validates :email, -    :format => { -      :with => /@#{domain}\Z/i, -      :message => "needs to end in @#{domain}" -    } - -  validate :handle_allowed - -  def initialize(s) -    super -    append_domain_if_needed -  end - -  def to_key -    [handle] -  end - -  def domain -    LocalEmail.domain -  end - -  protected - -  def append_domain_if_needed -    unless self.index('@') -      self << '@' + domain -    end -  end - -  def handle_allowed -    errors.add(:handle, "is reserved.") if handle_reserved? -  end - -  def handle_reserved? -    # *ARRAY in a case statement tests if ARRAY includes the handle. -    case handle -    when *APP_CONFIG[:handle_blacklist] -      true -    when *APP_CONFIG[:handle_whitelist] -      false -    when *BLACKLIST_FROM_RFC2142 -      true -    else -      handle_in_passwd? -    end -  end - -  def handle_in_passwd? -    Etc.getpwnam(handle).present? -  rescue ArgumentError -    # handle was not found -    return false -  end -end diff --git a/app/models/login_format_validation.rb b/app/models/login_format_validation.rb deleted file mode 100644 index c1fcf70..0000000 --- a/app/models/login_format_validation.rb +++ /dev/null @@ -1,21 +0,0 @@ -module LoginFormatValidation -  extend ActiveSupport::Concern - -  #TODO: Probably will replace this. Playing with using it for aliases too, but won't want it connected to login field. - -  included do -    # Have multiple regular expression validations so we can get specific error messages: -    validates :login, -      :format => { :with => /\A.{2,}\z/, -        :message => "Must have at least two characters"} -    validates :login, -      :format => { :with => /\A[a-z\d_\.-]+\z/, -        :message => "Only lowercase letters, digits, . - and _ allowed."} -    validates :login, -      :format => { :with => /\A[a-z].*\z/, -        :message => "Must begin with a lowercase letter"} -    validates :login, -      :format => { :with => /\A.*[a-z\d]\z/, -        :message => "Must end with a letter or digit"} -  end -end diff --git a/app/models/user.rb b/app/models/user.rb index cb093cf..206c0df 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,5 @@ +require 'login_format_validation' +  class User < CouchRest::Model::Base    include LoginFormatValidation | 
