diff options
author | Nicolas Braud-Santoni <nicoo@ffgraz.net> | 2016-08-07 16:39:42 +0200 |
---|---|---|
committer | Nicolas Braud-Santoni <nicoo@ffgraz.net> | 2016-08-07 16:39:42 +0200 |
commit | b6ca062670b342344df08b53fb216db619ef42bc (patch) | |
tree | 7680ac6b407239f6b7272c937e42f688b8de542c /app/models/person.rb |
Import legacy manman source
Copied from www.ffgraz.net
Diffstat (limited to 'app/models/person.rb')
-rw-r--r-- | app/models/person.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/app/models/person.rb b/app/models/person.rb new file mode 100644 index 0000000..26fa61f --- /dev/null +++ b/app/models/person.rb @@ -0,0 +1,48 @@ +require "digest/md5" + +class Person < ActiveRecord::Base + set_table_name "person" + belongs_to :admin + has_many :location + + attr_protected :password + + validates_presence_of :email, :password, :firstname, :lastname + validates_uniqueness_of :email + + validates_format_of :email, + :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i , + :on => :create + + + # operator overloading for updating passwords + def password=(str) + write_attribute(:password, Digest::MD5.hexdigest(str)) + end + + + def self.authenticate(user_name, password) + return Person.find( :first, :conditions => + ["email = BINARY ? AND password = BINARY ?", + user_name, + Digest::MD5.hexdigest(password)] ) + end + + def self.revoke_pass(email) + password = newpass( 8 ) + person = Person.find( :first, + :conditions => [ "email = ?", email] ) + # + + end + +private + # generate alphanumeric password + def newpass( len ) + chars = ("a".."z").to_a + ("A".."Z").to_a + ("1".."9").to_a + newpass = "" + 1.upto(len) { |i| newpass << chars[rand(chars.size-1)] } + return newpass + end + +end |