-
Notifications
You must be signed in to change notification settings - Fork 2
/
sessions_controller.rb
37 lines (32 loc) · 1 KB
/
sessions_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class SessionsController < ApplicationController
def create
# Have a look at the info returned by the provider by uncommenting the next line:
# render text: "<pre>" + env["omniauth.auth"].to_yaml and return
omniauth = env['omniauth.auth']
user = User.find_or_create_with_omniauth(omniauth)
session[:user_id] = user.id
flash[:notice] = t('controllers.sessions.create', provider: pretty_name(omniauth.provider))
render_or_redirect
end
def failure
flash[:alert] = t('controllers.sessions.failure', provider: pretty_name(env['omniauth.error.strategy'].name))
render_or_redirect
end
def destroy
session[:user_id] = nil
redirect_to root_url, notice: t('controllers.sessions.destroy')
end
protected
def render_or_redirect
page = env['omniauth.origin']
if env['omniauth.params']['popup']
@page = page
render 'callback', layout: false
else
redirect_to page
end
end
def pretty_name(provider_name)
provider_name.titleize
end
end