Sha256: 2b9ddc71ac88bf9e831ab7b5afc7e93cf7e5c84fd9dc533e61c768a3131b91f0

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

# -*- coding: utf-8 -*-
class User < BaseNew
  taggable 'u'
  with_timestamps
  plugin :single_table_inheritance, :uuid, :model_map=>{}
  plugin :subclasses

  inheritable_schema do
    String :name, :fixed=>true, :size=>200, :null=>false
    primary_key :id, :type=>Integer
    String :login_id
    String :password, :null=>false
    String :primary_account_id
  end

  many_to_many :accounts,:join_table => :users_accounts
  
  class << self
    def authenticate(login_id,password)
      return nil if login_id.nil? || password.nil?
      u = User.find(:login_id=>login_id, :password => encrypt_password(password))
      u.nil? ? false : u
    end

    def get_user(uuid)
      return nil if uuid.nil?
      u = User.find(:uuid=>uuid)
      u.nil? ? false : u
    end
    
    def account_name_with_uuid(uuid)
      h = Hash.new
      User.find(:uuid => uuid).accounts.each{|row| h.store(row.name,row.uuid) }
      h
    end
    
    def primary_account_id(uuid)
      User.find(:uuid => uuid).primary_account_id
    end
    
    def encrypt_password(password)
      salt = Digest::SHA1.hexdigest(DcmgrGui::Application.config.secret_token)
      Digest::SHA1.hexdigest("--#{salt}--#{password}--")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wakame-vdc-webui-10.12.0 app/models/user.rb
wakame-vdc-webui-10.11.0 app/models/user.rb