· 8 years ago · Mar 02, 2018, 01:06 PM
1diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
2index b4e300d..0b4959d 100644
3--- a/app/controllers/sessions_controller.rb
4+++ b/app/controllers/sessions_controller.rb
5@@ -6,11 +6,7 @@ class SessionsController < ApplicationController
6
7 def create
8 logout_keeping_session!
9- if using_open_id?
10- open_id_authentication
11- else
12- password_authentication
13- end
14+ password_authentication
15 end
16
17 def destroy
18@@ -18,18 +14,6 @@ class SessionsController < ApplicationController
19 flash[:notice] = "You have been logged out."
20 redirect_back_or_default(root_path)
21 end
22-
23- def open_id_authentication
24- authenticate_with_open_id do |result, identity_url|
25- if result.successful? && self.current_user = User.find_by_identity_url(identity_url)
26- successful_login
27- else
28- flash[:error] = result.message || "Sorry no user with that identity URL exists"
29- @remember_me = params[:remember_me]
30- render :action => :new
31- end
32- end
33- end
34
35 protected
36
37diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
38index f1078c1..3363c0d 100644
39--- a/app/controllers/users_controller.rb
40+++ b/app/controllers/users_controller.rb
41@@ -7,18 +7,7 @@ class UsersController < ApplicationController
42
43 def create
44 logout_keeping_session!
45- if using_open_id?
46- authenticate_with_open_id(params[:openid_url], :return_to => open_id_create_url,
47- :required => [:nickname, :email]) do |result, identity_url, registration|
48- if result.successful?
49- create_new_user(:identity_url => identity_url, :login => registration['nickname'], :email => registration['email'])
50- else
51- failed_creation(result.message || "Sorry, something went wrong")
52- end
53- end
54- else
55- create_new_user(params[:user])
56- end
57+ create_new_user(params[:user])
58 end
59
60 def activate
61@@ -43,11 +32,7 @@ class UsersController < ApplicationController
62 def create_new_user(attributes)
63 @user = User.new(attributes)
64 if @user && @user.valid?
65- if @user.not_using_openid?
66- @user.register!
67- else
68- @user.register_openid!
69- end
70+ @user.register!
71 end
72
73 if @user.errors.empty?
74@@ -60,8 +45,7 @@ class UsersController < ApplicationController
75 def successful_creation(user)
76 redirect_back_or_default(root_path)
77 flash[:notice] = "Thanks for signing up!"
78- flash[:notice] << " We're sending you an email with your activation code." if @user.not_using_openid?
79- flash[:notice] << " You can now login with your OpenID." unless @user.not_using_openid?
80+ flash[:notice] << " We're sending you an email with your activation code."
81 end
82
83 def failed_creation(message = 'Sorry, there was an error creating your account')
84diff --git a/app/models/user.rb b/app/models/user.rb
85index 82fb560..ed96282 100644
86--- a/app/models/user.rb
87+++ b/app/models/user.rb
88@@ -7,18 +7,16 @@ class User < ActiveRecord::Base
89 include Authorization::AasmRoles
90
91 # Validations
92- validates_presence_of :login, :if => :not_using_openid?
93- validates_length_of :login, :within => 3..40, :if => :not_using_openid?
94- validates_uniqueness_of :login, :case_sensitive => false, :if => :not_using_openid?
95- validates_format_of :login, :with => RE_LOGIN_OK, :message => MSG_LOGIN_BAD, :if => :not_using_openid?
96+ validates_presence_of :login
97+ validates_length_of :login, :within => 3..40
98+ validates_uniqueness_of :login, :case_sensitive => false
99+ validates_format_of :login, :with => RE_LOGIN_OK, :message => MSG_LOGIN_BAD
100 validates_format_of :name, :with => RE_NAME_OK, :message => MSG_NAME_BAD, :allow_nil => true
101 validates_length_of :name, :maximum => 100
102- validates_presence_of :email, :if => :not_using_openid?
103- validates_length_of :email, :within => 6..100, :if => :not_using_openid?
104- validates_uniqueness_of :email, :case_sensitive => false, :if => :not_using_openid?
105- validates_format_of :email, :with => RE_EMAIL_OK, :message => MSG_EMAIL_BAD, :if => :not_using_openid?
106- validates_uniqueness_of :identity_url, :unless => :not_using_openid?
107- validate :normalize_identity_url
108+ validates_presence_of :email
109+ validates_length_of :email, :within => 6..100
110+ validates_uniqueness_of :email, :case_sensitive => false
111+ validates_format_of :email, :with => RE_EMAIL_OK, :message => MSG_EMAIL_BAD
112
113 # Relationships
114 has_and_belongs_to_many :roles
115@@ -39,16 +37,6 @@ class User < ActiveRecord::Base
116 list ||= self.roles.map(&:name)
117 list.include?(role.to_s) || list.include?('admin')
118 end
119-
120- # Not using open id
121- def not_using_openid?
122- identity_url.blank?
123- end
124-
125- # Overwrite password_required for open id
126- def password_required?
127- new_record? ? not_using_openid? && (crypted_password.blank? || !password.blank?) : !password.blank?
128- end
129
130 protected
131
132@@ -56,10 +44,5 @@ class User < ActiveRecord::Base
133 self.deleted_at = nil
134 self.activation_code = self.class.make_token
135 end
136-
137- def normalize_identity_url
138- self.identity_url = OpenIdAuthentication.normalize_url(identity_url) unless not_using_openid?
139- rescue URI::InvalidURIError
140- errors.add_to_base("Invalid OpenID URL")
141- end
142+
143 end
144diff --git a/app/models/user_observer.rb b/app/models/user_observer.rb
145index c942ce3..6a56c44 100644
146--- a/app/models/user_observer.rb
147+++ b/app/models/user_observer.rb
148@@ -1,9 +1,9 @@
149 class UserObserver < ActiveRecord::Observer
150 def after_create(user)
151- UserMailer.deliver_signup_notification(user) if user.not_using_openid?
152+ UserMailer.deliver_signup_notification(user)
153 end
154
155 def after_save(user)
156- UserMailer.deliver_activation(user) if user.recently_activated? && user.not_using_openid?
157+ UserMailer.deliver_activation(user) if user.recently_activated?
158 end
159 end
160diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb
161index 52fe80f..444b71a 100644
162--- a/app/views/sessions/new.html.erb
163+++ b/app/views/sessions/new.html.erb
164@@ -17,15 +17,6 @@
165 </li>
166 </ol>
167 </fieldset>
168- <fieldset>
169- <legend>Login with OpenID</legend>
170- <ol>
171- <li>
172- <%= label_tag 'openid_url', 'OpenID URL' %>
173- <%= text_field_tag 'openid_url' %>
174- </li>
175- </ol>
176- </fieldset>
177 <div class="buttons">
178 <%= submit_tag 'Login' %>
179 <%= link_to 'Forgotten Password', forgot_password_path %>
180diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb
181index bd61ac0..de57238 100644
182--- a/app/views/users/new.html.erb
183+++ b/app/views/users/new.html.erb
184@@ -23,15 +23,6 @@
185 </li>
186 </ol>
187 </fieldset>
188- <fieldset>
189- <legend>Signup with OpenID</legend>
190- <ol>
191- <li>
192- <label for="openid_url">OpenID URL</label>
193- <%= text_field_tag :openid_url, params[:openid_url] || params['openid.identity'] %>
194- </li>
195- </ol>
196- </fieldset>
197 <div class="buttons">
198 <%= submit_tag 'Sign up' %>
199 </div>
200diff --git a/db/migrate/20080929171348_bort_migration.rb b/db/migrate/20080929171348_bort_migration.rb
201index b192edd..3bb5957 100644
202--- a/db/migrate/20080929171348_bort_migration.rb
203+++ b/db/migrate/20080929171348_bort_migration.rb
204@@ -10,23 +10,9 @@ class BortMigration < ActiveRecord::Migration
205 add_index :sessions, :session_id
206 add_index :sessions, :updated_at
207
208- # Create OpenID Tables
209- create_table :open_id_authentication_associations, :force => true do |t|
210- t.integer :issued, :lifetime
211- t.string :handle, :assoc_type
212- t.binary :server_url, :secret
213- end
214-
215- create_table :open_id_authentication_nonces, :force => true do |t|
216- t.integer :timestamp, :null => false
217- t.string :server_url, :null => true
218- t.string :salt, :null => false
219- end
220-
221 # Create Users Table
222 create_table :users do |t|
223 t.string :login, :limit => 40
224- t.string :identity_url
225 t.string :name, :limit => 100, :default => '', :null => true
226 t.string :email, :limit => 100
227 t.string :crypted_password, :limit => 40
228@@ -85,7 +71,5 @@ class BortMigration < ActiveRecord::Migration
229 drop_table :passwords
230 drop_table :roles
231 drop_table :roles_users
232- drop_table :open_id_authentication_associations
233- drop_table :open_id_authentication_nonces
234 end
235 end
236diff --git a/db/schema.rb b/db/schema.rb
237index 0ac248b..12ff1c7 100644
238--- a/db/schema.rb
239+++ b/db/schema.rb
240@@ -9,22 +9,7 @@
241 #
242 # It's strongly recommended to check this file into your version control system.
243
244-ActiveRecord::Schema.define(:version => 20080929171348) do
245-
246- create_table "open_id_authentication_associations", :force => true do |t|
247- t.integer "issued"
248- t.integer "lifetime"
249- t.string "handle"
250- t.string "assoc_type"
251- t.binary "server_url"
252- t.binary "secret"
253- end
254-
255- create_table "open_id_authentication_nonces", :force => true do |t|
256- t.integer "timestamp", :null => false
257- t.string "server_url"
258- t.string "salt", :null => false
259- end
260+ActiveRecord::Schema.define(:version => 0) do
261
262 create_table "passwords", :force => true do |t|
263 t.integer "user_id"
264@@ -50,8 +35,8 @@ ActiveRecord::Schema.define(:version => 20080929171348) do
265 t.datetime "updated_at"
266 end
267
268- add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
269 add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
270+ add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
271
272 create_table "users", :force => true do |t|
273 t.string "login", :limit => 40
274--
2751.6.0.1