Skip to content

Instantly share code, notes, and snippets.

@Talleyran
Created December 13, 2010 17:22
Show Gist options
  • Save Talleyran/739261 to your computer and use it in GitHub Desktop.
Save Talleyran/739261 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
attr_accessor :password
has_many :groups
validates_presence_of :email, :message => '.validates_presence_of_email'
validates_presence_of :password, :message => '.validates_presence_of_password'
#authorization and registration in this method
def self.get_authorized_user params
user = self.first :conditions => { :encrypted_password => encrypte( params[ :password ] ), :email => params[ :email ] }
return user if !!user
return if !!self.first( :conditions => { :email => params[ :email ] } )
user = self.new
usea.statuses_updated_at = Time.zone.now
user.email = params[ :email ]
user.password = params[ :password ]
user.encrypted_password = encrypte( params[ :password ] )
return unless user.save
user
end
private
def self.encrypte s
Digest::MD5.hexdigest s
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment