Sha256: fbe93f7384caa006acc86e352b789b4d119895620241a6c4cc0d7f0175083111
Contents?: true
Size: 1.01 KB
Versions: 1
Compression:
Stored size: 1.01 KB
Contents
module MyForum class User < ActiveRecord::Base require 'digest' has_many :posts, class_name: 'MyForum::Post' has_many :user_roles has_many :roles, through: :user_roles has_many :user_group_links has_many :user_groups, through: :user_group_links scope :online, -> { where("updated_at > ?", 10.minutes.ago) } scope :today_visited, -> { where("updated_at > ?", Time.now.beginning_of_day) } validates_uniqueness_of :login, :email before_save :encrypt_password def valid_password?(submitted_password) password == encrypt(submitted_password) end def can_quick_answer?(forum) true end private def encrypt_password self.salt = make_salt unless valid_password?(password) self.password = encrypt(password) end def encrypt(string) secure_hash("#{salt}--#{string}") end def make_salt secure_hash("#{Time.now.utc}--#{password}") end def secure_hash(string) Digest::SHA2.hexdigest(string) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
my_forum-0.0.1.beta1 | app/models/my_forum/user.rb |