Skip to content

Commit

Permalink
[account][authentication] clean up plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
achiurizo committed Jul 23, 2010
1 parent 0222567 commit 2245058
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions app/models/plugins/authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@ module Plugins
module Authentication

def self.configure(model)
# fields
model.key :email, String
model.key :crypted_password, String
model.key :salt, String
model.key :role, String
# callbacks
model.before_save :generate_password
# validations
model.validates_presence_of :email, :role
model.validates_presence_of :password, :if => :password_required
model.validates_presence_of :password_confirmation, :if => :password_required
model.validates_length_of :password, :within => 4..40, :if => :password_required
model.validates_confirmation_of :password, :if => :password_required
model.validates_length_of :email, :within => 3..40
model.validates_uniqueness_of :email, :case_sensitive => false
model.validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
model.validates_format_of :role, :with => /[A-Za-z]/
model.class_eval do
# fields
key :email, String
key :crypted_password, String
key :salt, String
key :role, String
# callbacks
before_save :generate_password
# validations
validates_presence_of :email, :role
validates_presence_of :password, :if => :password_required
validates_presence_of :password_confirmation, :if => :password_required
validates_length_of :password, :within => 4..40, :if => :password_required
validates_confirmation_of :password, :if => :password_required
validates_length_of :email, :within => 3..40
validates_uniqueness_of :email, :case_sensitive => false
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
validates_format_of :role, :with => /[A-Za-z]/
end
end

module ClassMethods
Expand Down

0 comments on commit 2245058

Please sign in to comment.