/
sessions_controller.rb
44 lines (41 loc) · 1.53 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
38
39
40
41
42
43
44
class SessionsController < ApplicationController
skip_before_filter :verify_authenticity_token
def new
response.headers['WWW-Authenticate'] = Rack::OpenID.build_header(
:identifier => "https://www.google.com/accounts/o8/id",
:required => ["http://axschema.org/contact/email",
"http://axschema.org/namePerson/first",
"http://axschema.org/namePerson/last"],
:return_to => session_url,
:method => 'POST')
head 401
end
def create
if openid = request.env[Rack::OpenID::RESPONSE]
case openid.status
when :success
ax = OpenID::AX::FetchResponse.from_success_response(openid)
user = User.where(:openid_url => openid.display_identifier).first
user ||= User.create!(:openid_url => openid.display_identifier,
:email => ax.get_single('http://axschema.org/contact/email'),
:name => ax.get_single('http://axschema.org/namePerson/first'))
# we should have a last name ... grrr
#:last_name => ax.get_single('http://axschema.org/namePerson/last'))
session[:user_id] = user.id
if user.name.blank?
redirect_to(user_additional_info_path(user))
else
redirect_to(session[:redirect_to] || root_path)
end
when :failure
render :action => 'problem'
end
else
redirect_to new_session_path
end
end
def destroy
session[:user_id] = nil
redirect_to root_path
end
end