Module: LamAuth

Defined in:
lib/lam_auth.rb,
lib/lam_auth/model.rb,
lib/lam_auth/helpers.rb,
lib/lam_auth/version.rb,
lib/generators/lam_auth/lam_auth_generator.rb

Defined Under Namespace

Modules: Generators, Helpers, Model

Constant Summary collapse

VERSION =
"2.0.1"

Class Method Summary collapse

Class Method Details



43
44
45
46
# File 'lib/lam_auth.rb', line 43

def access_token_from_cookie(cookie)
  hash = parse_cookie_to_hash(cookie)
  valid_hash?(hash) && hash['access_token']
end

.appObject



10
11
12
# File 'lib/lam_auth.rb', line 10

def app
  @app ||= YAML.load_file(Rails.root.join("config/lam_auth.yml"))
end

.configObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lam_auth.rb', line 14

def config
  {
    'lookatme' => {
      'prefix' => 'lam',
      'url' => 'http://www.lookatme.ru',
      'api' => 'LAM',
      'api_url' => 'http://www.lookatme.ru/api/js/LAM.Login.js',
    },
    'village' => {
      'prefix' => 'village',
      'url' => 'http://www.the-village.ru',
      'api' => 'VLG',
      'api_url' => 'http://www.the-village.ru/api/js/VLG.Login.js',
    }
  }[site]
end


39
40
41
# File 'lib/lam_auth.rb', line 39

def cookie_id
  "#{config['prefix']}_#{app['app_id']}"
end


48
49
50
# File 'lib/lam_auth.rb', line 48

def parse_cookie_to_hash(data)
  Rack::Utils.parse_query(Rack::Utils.unescape(data.to_s.gsub('"', '')))
end

.siteObject



31
32
33
# File 'lib/lam_auth.rb', line 31

def site
  %w{lookatme village}.include?(app['site']) ? app['site'] : 'lookatme'
end

.urlObject



35
36
37
# File 'lib/lam_auth.rb', line 35

def url
  config['url']
end

.valid_hash?(hash) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/lam_auth.rb', line 52

def valid_hash?(hash)
  Digest::MD5.hexdigest(hash.except('sig').sort.map{|v| v.join('=')}.join + app['secret']) == hash['sig']
end