Module: Omniauth::Edumall::User

Extended by:
User
Included in:
User
Defined in:
lib/omniauth/edumall/user.rb

Constant Summary collapse

EDUMALL_SSO_URL =
'https://accounts.edumall.vn'

Instance Method Summary collapse

Instance Method Details

#logout(cookies) ⇒ Object



28
29
30
31
# File 'lib/omniauth/edumall/user.rb', line 28

def logout(cookies)
  cookies.delete :_provider_sso_session, domain: '.edumall.vn'
  cookies.delete :edumall_access_token, domain: '.edumall.vn'
end

#user_logged(cookies) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/omniauth/edumall/user.rb', line 11

def user_logged(cookies)
  if user_logout?(cookies)
    return {}
  end
  edumall_access_token = cookies[:edumall_access_token]
  RestClient.get("#{EDUMALL_SSO_URL}/auth/sso/user.json?oauth_token=#{cookies[:edumall_access_token]}") { |response, request, result, &block|
    case response.code
    when 200
      user_response = JSON.parse(response.body)
      return user_response
    else
      logout(cookies)
      return {}
    end
  }
end

#user_logout?(cookies) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
# File 'lib/omniauth/edumall/user.rb', line 6

def user_logout?(cookies)
  edumall_access_token = cookies[:edumall_access_token]
  return edumall_access_token.blank?
end