Class: LocaleNinja::SessionController

Inherits:
ApplicationController show all
Defined in:
app/controllers/locale_ninja/session_controller.rb

Instance Method Summary collapse

Instance Method Details

#loginObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/locale_ninja/session_controller.rb', line 13

def 
  code = params['code']
  response = ::HTTParty.post('https://github.com/login/oauth/access_token',
                             body: {
                               client_id: CLIENT_ID,
                               client_secret: CLIENT_SECRET,
                               code:
                             }
                            )
  parsed = CGI.parse(response)
  session[:access_token] = parsed['access_token'].first
  user = GithubApiService.new(access_token:).user
  session[:user] = user.to_h.slice(:avatar_url, :id, :login)
  redirect_to(root_path)
end

#logoutObject



29
30
31
32
# File 'app/controllers/locale_ninja/session_controller.rb', line 29

def logout
  session.clear
  redirect_to('https://github.com/logout')
end