Skip to content

Commit e0a5a16

Browse files
committed
Merge pull request #58 from osbridge/with_omniauth
Switch to using OmniAuth for authentication
2 parents fdf3119 + 5e33e77 commit e0a5a16

File tree

100 files changed

+1014
-2919
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+1014
-2919
lines changed

Gemfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ gem 'sqlite3', :require => false
1414
# gem 'mysql2', :require => false
1515
# gem 'pg', :require => false
1616

17+
# Authentication
18+
gem 'omniauth-openid'
19+
gem 'omniauth-persona'
20+
1721
# Selectively-loaded:
1822
gem 'facets', '~> 2.8.0', :require => false # For initializers/dependencies.rb
1923
gem 'right_aws', '~> 1.0', :require => false # For paperclip
20-
gem 'ruby-openid', '~> 2.1.0', :require => false # For open_id_authentication
21-
gem 'rack-openid', '~> 1.3.1', :require => false # For open_id_authentication
2224
gem 'rwikibot', '= 2.0.6', :require => false,
2325
:git => 'git://github.com/reidab/rwikibot.git'
2426

@@ -31,6 +33,7 @@ gem 'comma', '~> 3.0'
3133
gem 'gchartrb', '~> 0.8.0', :require => 'google_chart'
3234
gem 'hpricot', '~> 0.8.2'
3335
gem 'paperclip', '~> 2.3.1'
36+
gem 'cocaine', '0.3.2'
3437
gem 'vpim-rails', :git => "https://github.com/osbridge/vpim-rails.git", :require => 'vpim/icalendar'
3538
gem 'action_mailer_tls', '~> 1.1.3'
3639
gem 'nokogiri', '~> 1.5.10'

Gemfile.lock

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ GEM
7373
xpath (~> 1.0.0)
7474
childprocess (0.3.9)
7575
ffi (~> 1.0, >= 1.0.11)
76-
climate_control (0.0.3)
77-
activesupport (>= 3.0)
78-
cocaine (0.5.1)
79-
climate_control (>= 0.0.3, < 1.0)
76+
cocaine (0.3.2)
8077
coderay (1.0.9)
8178
color (1.4.2)
8279
columnize (0.3.6)
@@ -116,12 +113,15 @@ GEM
116113
facets (2.8.4)
117114
factory_girl (2.6.4)
118115
activesupport (>= 2.3.9)
116+
faraday (0.8.8)
117+
multipart-post (~> 1.2.0)
119118
fastercsv (1.5.5)
120119
ffi (1.9.0)
121120
gchartrb (0.8)
122121
gherkin (2.12.1)
123122
multi_json (~> 1.3)
124123
hashery (2.1.1)
124+
hashie (2.0.5)
125125
highline (1.6.19)
126126
hike (1.2.3)
127127
hoe (3.7.1)
@@ -142,6 +142,7 @@ GEM
142142
mime-types (1.25)
143143
multi_json (1.8.2)
144144
multi_test (0.0.2)
145+
multipart-post (1.2.0)
145146
net-scp (1.1.2)
146147
net-ssh (>= 2.6.5)
147148
net-sftp (2.1.2)
@@ -150,6 +151,16 @@ GEM
150151
net-ssh-gateway (1.2.0)
151152
net-ssh (>= 2.6.5)
152153
nokogiri (1.5.10)
154+
omniauth (1.1.4)
155+
hashie (>= 1.2, < 3)
156+
rack
157+
omniauth-openid (1.0.1)
158+
omniauth (~> 1.0)
159+
rack-openid (~> 1.3.1)
160+
omniauth-persona (0.0.1)
161+
faraday
162+
multi_json
163+
omniauth (~> 1.0)
153164
paperclip (2.3.16)
154165
activerecord (>= 2.3.0)
155166
activesupport (>= 2.3.2)
@@ -271,6 +282,7 @@ DEPENDENCIES
271282
capistrano
272283
capistrano-ext
273284
capybara (~> 2.0.0)
285+
cocaine (= 0.3.2)
274286
color
275287
comma (~> 3.0)
276288
coveralls
@@ -287,18 +299,18 @@ DEPENDENCIES
287299
launchy
288300
memcache-client
289301
nokogiri (~> 1.5.10)
302+
omniauth-openid
303+
omniauth-persona
290304
paperclip (~> 2.3.1)
291305
prawn (= 0.11.1)
292306
pry
293-
rack-openid (~> 1.3.1)
294307
rails (~> 3.2.0)
295308
rake
296309
rcov
297310
right_aws (~> 1.0)
298311
rinku
299312
rspec-rails
300313
ruby-debug
301-
ruby-openid (~> 2.1.0)
302314
ruby18_source_location
303315
rwikibot (= 2.0.6)!
304316
simplecov

app/controllers/application_controller.rb

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ class ApplicationController < ActionController::Base
1818
# Provide access to page_title in controllers
1919
include PageTitleHelper
2020

21-
# Setup authentication (e.g., login)
22-
include AuthenticatedSystem
23-
2421
# Setup breadcrumbs
2522
include BreadcrumbsMixin
2623
add_breadcrumbs(SETTINGS.breadcrumbs)
@@ -33,6 +30,70 @@ class ApplicationController < ActionController::Base
3330
before_filter :log_the_current_user
3431
before_filter :log_the_session
3532

33+
#---[ Authentication ]--------------------------------------------------
34+
35+
# Store the given user in the session.
36+
def current_user=(new_user)
37+
session[:user_id] = (new_user.nil? || new_user.is_a?(Symbol)) ? nil : new_user.id
38+
@current_user = new_user
39+
end
40+
41+
# Accesses the current user from the session.
42+
def current_user
43+
@current_user ||= User.find(session[:user_id]) if session[:user_id]
44+
rescue ActiveRecord::RecordNotFound
45+
reset_session
46+
end
47+
helper_method :current_user
48+
49+
# Returns true or false if the user is logged in.
50+
# Preloads @current_user with the user model if they're logged in.
51+
def logged_in?
52+
!!current_user
53+
end
54+
helper_method :logged_in?
55+
56+
# Filter method to enforce a login requirement.
57+
def authentication_required
58+
logged_in? || access_denied(:message => "Please sign in to access the requested page.")
59+
end
60+
61+
# Redirect as appropriate when an access request fails.
62+
def access_denied(opts={})
63+
message = opts[:message] || "Access denied, please sign in with enough privileges to complete that operation."
64+
fallback_url = opts[:fallback_url] || opts[:fallback] || sign_in_path
65+
66+
store_location
67+
redirect_to fallback_url, :alert => message
68+
end
69+
70+
# Store the URI of the current request in the session.
71+
#
72+
# We can return to this location by calling #redirect_back_or_default.
73+
def store_location(path=nil)
74+
session[:return_to] = path || request.fullpath
75+
end
76+
77+
# Redirect to the URI stored by the most recent store_location call or
78+
# to the passed default.
79+
def redirect_back_or_default(default=nil)
80+
redirect_to(session[:return_to] || default || default_path)
81+
session[:return_to] = nil
82+
end
83+
alias_method :redirect_back_or_to, :redirect_back_or_default
84+
85+
def default_path
86+
if @event
87+
if @event.proposal_status_published?
88+
event_sessions_path(@event)
89+
else
90+
event_proposals_path(@event)
91+
end
92+
else
93+
proposals_path
94+
end
95+
end
96+
3697
protected
3798

3899
#---[ General ]---------------------------------------------------------
@@ -344,7 +405,7 @@ def assert_user
344405
if logged_in?
345406
@user = current_user
346407
else
347-
return access_denied(:message => "Please login to access your user profile.")
408+
return access_denied(:message => "Please sign in to access your user profile.")
348409
end
349410
else
350411
begin
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
class AuthenticationsController < ApplicationController
2+
before_filter :require_auth_hash, :only => [:create]
3+
4+
def sign_in
5+
page_title "Sign In"
6+
end
7+
8+
def sign_out
9+
cookies.delete :auth_token
10+
reset_session
11+
flash[:notice] = "You have been logged out."
12+
13+
redirect_back_or_default
14+
end
15+
16+
def create
17+
@authentication = Authentication.find_and_update_or_create_from_auth_hash(auth_hash)
18+
19+
if @authentication.user
20+
self.current_user = @authentication.user
21+
elsif logged_in?
22+
@authentication.user = current_user
23+
@authentication.save
24+
else
25+
self.current_user = User.create_from_authentication(@authentication)
26+
end
27+
28+
redirect_back_or_default
29+
end
30+
31+
protected
32+
33+
def auth_hash
34+
request.env['omniauth.auth']
35+
end
36+
37+
def require_auth_hash
38+
redirect_to(sign_in_path) and return unless auth_hash
39+
end
40+
end

app/controllers/browser_sessions_controller.rb

Lines changed: 0 additions & 156 deletions
This file was deleted.

0 commit comments

Comments
 (0)