Created
January 4, 2012 20:38
-
-
Save dapi/1562013 to your computer and use it in GitHub Desktop.
1С-Битрикс авторизация на рельсах (ruby on rails)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Session < ActiveRecord::Base | |
set_table_name :b_user_stored_auth | |
belongs_to :user, :foreign_key => 'user_id' | |
attr_accessor :login, :password, :backurl | |
def self.create_or_update_by_hash(hash, user, ip_addr) | |
t = Time.now | |
if hash and auth = find_by_stored_hash(hash) | |
auth.update_attributes('last_auth' => t, | |
'user_id' => user.id, | |
'temp_hash' => 'N', | |
'ip_addr' => ip_addr) | |
auth | |
else | |
create('user_id' => user.id, | |
'last_auth' => t, | |
'date_reg' => t, | |
'temp_hash' => 'N', | |
'ip_addr' => ip_addr, | |
'stored_hash' => session_hash) | |
end | |
end | |
def self.delete_by_hash(hash) | |
find_by_stored_hash(hash).try :destroy | |
end | |
def self.session_hash | |
(0...32).map{ ('a'..'z').to_a[rand(26)] }.join | |
end | |
end | |
# | |
# разработчик - Дмитрий Максимов http://www.dmaximov.net/ | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment