##// END OF EJS Templates
Added the ability to login via OpenID....
Eric Davis -
r2381:896e64b759ae
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -46,24 +46,10 class AccountController < ApplicationController
46 self.logged_user = nil
46 self.logged_user = nil
47 else
47 else
48 # Authenticate user
48 # Authenticate user
49 user = User.try_to_login(params[:username], params[:password])
49 unless using_open_id?
50 if user.nil?
50 password_authentication
51 # Invalid credentials
52 flash.now[:error] = l(:notice_account_invalid_creditentials)
53 elsif user.new_record?
54 # Onthefly creation failed, display the registration form to fill/fix attributes
55 @user = user
56 session[:auth_source_registration] = {:login => user.login, :auth_source_id => user.auth_source_id }
57 render :action => 'register'
58 else
51 else
59 # Valid user
52 open_id_authenticate(params[:openid_url])
60 self.logged_user = user
61 # generate a key and set cookie if autologin
62 if params[:autologin] && Setting.autologin?
63 token = Token.create(:user => user, :action => 'autologin')
64 cookies[:autologin] = { :value => token.value, :expires => 1.year.from_now }
65 end
66 redirect_back_or_default :controller => 'my', :action => 'page'
67 end
53 end
68 end
54 end
69 end
55 end
@@ -191,4 +177,59 private
191 session[:user_id] = nil
177 session[:user_id] = nil
192 end
178 end
193 end
179 end
180
181 def password_authentication
182 user = User.try_to_login(params[:username], params[:password])
183 if user.nil?
184 # Invalid credentials
185 flash.now[:error] = l(:notice_account_invalid_creditentials)
186 elsif user.new_record?
187 # Onthefly creation failed, display the registration form to fill/fix attributes
188 @user = user
189 session[:auth_source_registration] = {:login => user.login, :auth_source_id => user.auth_source_id }
190 render :action => 'register'
191 else
192 # Valid user
193 successful_authentication(user)
194 end
195 end
196
197
198 def open_id_authenticate(openid_url)
199 user = nil
200 authenticate_with_open_id(openid_url, :required => [:nickname, :fullname, :email], :return_to => signin_url) do |result, identity_url, registration|
201 if result.successful?
202 user = User.find_or_initialize_by_identity_url(identity_url)
203 if user.new_record?
204 # Create on the fly
205 # TODO: name
206 user.login = registration['nickname']
207 user.mail = registration['email']
208 user.save
209 end
210
211 user.reload
212 if user.new_record?
213 # Onthefly creation failed, display the registration form to fill/fix attributes
214 @user = user
215 session[:auth_source_registration] = {:login => user.login, :identity_url => identity_url }
216 render :action => 'register'
217 else
218 successful_authentication(user)
219 end
220 end
221 end
222 end
223
224 def successful_authentication(user)
225 # Valid user
226 self.logged_user = user
227 # generate a key and set cookie if autologin
228 if params[:autologin] && Setting.autologin?
229 token = Token.create(:user => user, :action => 'autologin')
230 cookies[:autologin] = { :value => token.value, :expires => 1.year.from_now }
231 end
232 redirect_back_or_default :controller => 'my', :action => 'page'
233 end
234
194 end
235 end
@@ -11,6 +11,10
11 <td align="left"><%= password_field_tag 'password', nil, :size => 40 %></td>
11 <td align="left"><%= password_field_tag 'password', nil, :size => 40 %></td>
12 </tr>
12 </tr>
13 <tr>
13 <tr>
14 <td align="right"><label for="openid_url"><%=l(:field_identity_url)%></label></td>
15 <td align="left"><%= text_field_tag "openid_url" %></td>
16 </tr>
17 <tr>
14 <td></td>
18 <td></td>
15 <td align="left">
19 <td align="left">
16 <% if Setting.autologin? %>
20 <% if Setting.autologin? %>
@@ -1,4 +1,4
1 <h2><%=l(:label_register)%></h2>
1 <h2><%=l(:label_register)%> <%=link_to l(:label_login_with_open_id_option), signin_url %></h2>
2
2
3 <% form_tag({:action => 'register'}, :class => "tabular") do %>
3 <% form_tag({:action => 'register'}, :class => "tabular") do %>
4 <%= error_messages_for 'user' %>
4 <%= error_messages_for 'user' %>
@@ -29,6 +29,9
29 <p><label for="user_language"><%=l(:field_language)%></label>
29 <p><label for="user_language"><%=l(:field_language)%></label>
30 <%= select("user", "language", lang_options_for_select) %></p>
30 <%= select("user", "language", lang_options_for_select) %></p>
31
31
32 <p><label for="user_identity_url"><%=l(:field_identity_url)%></label>
33 <%= text_field 'user', 'identity_url' %></p>
34
32 <% @user.custom_field_values.select {|v| v.editable? || v.required?}.each do |value| %>
35 <% @user.custom_field_values.select {|v| v.editable? || v.required?}.each do |value| %>
33 <p><%= custom_field_tag_with_label :user, value %></p>
36 <p><%= custom_field_tag_with_label :user, value %></p>
34 <% end %>
37 <% end %>
@@ -15,6 +15,7
15 <p><%= f.text_field :lastname, :required => true %></p>
15 <p><%= f.text_field :lastname, :required => true %></p>
16 <p><%= f.text_field :mail, :required => true %></p>
16 <p><%= f.text_field :mail, :required => true %></p>
17 <p><%= f.select :language, lang_options_for_select %></p>
17 <p><%= f.select :language, lang_options_for_select %></p>
18 <p><%= f.text_field :identity_url %></p>
18
19
19 <% @user.custom_field_values.select(&:editable?).each do |value| %>
20 <% @user.custom_field_values.select(&:editable?).each do |value| %>
20 <p><%= custom_field_tag_with_label :user, value %></p>
21 <p><%= custom_field_tag_with_label :user, value %></p>
@@ -7,6 +7,7
7 <p><%= f.text_field :lastname, :required => true %></p>
7 <p><%= f.text_field :lastname, :required => true %></p>
8 <p><%= f.text_field :mail, :required => true %></p>
8 <p><%= f.text_field :mail, :required => true %></p>
9 <p><%= f.select :language, lang_options_for_select %></p>
9 <p><%= f.select :language, lang_options_for_select %></p>
10 <p><%= f.text_field :identity_url %></p>
10
11
11 <% @user.custom_field_values.each do |value| %>
12 <% @user.custom_field_values.each do |value| %>
12 <p><%= custom_field_tag_with_label :user, value %></p>
13 <p><%= custom_field_tag_with_label :user, value %></p>
@@ -255,4 +255,6 ActionController::Routing::Routes.draw do |map|
255 # Install the default route as the lowest priority.
255 # Install the default route as the lowest priority.
256 map.connect ':controller/:action/:id'
256 map.connect ':controller/:action/:id'
257 map.connect 'robots.txt', :controller => 'welcome', :action => 'robots'
257 map.connect 'robots.txt', :controller => 'welcome', :action => 'robots'
258 # Used for OpenID
259 map.root :controller => 'account', :action => 'login'
258 end
260 end
@@ -147,6 +147,7 field_mail_notification: Email notifications
147 field_admin: Administrator
147 field_admin: Administrator
148 field_last_login_on: Last connection
148 field_last_login_on: Last connection
149 field_language: Language
149 field_language: Language
150 field_identity_url: OpenID URL
150 field_effective_date: Date
151 field_effective_date: Date
151 field_password: Password
152 field_password: Password
152 field_new_password: New password
153 field_new_password: New password
@@ -332,6 +333,7 label_information: Information
332 label_information_plural: Information
333 label_information_plural: Information
333 label_please_login: Please log in
334 label_please_login: Please log in
334 label_register: Register
335 label_register: Register
336 label_login_with_open_id_option: or login with OpenID
335 label_password_lost: Lost password
337 label_password_lost: Lost password
336 label_home: Home
338 label_home: Home
337 label_my_page: My page
339 label_my_page: My page
@@ -69,6 +69,8 html>body #content { min-height: 600px; }
69 #login-form table td {padding: 6px;}
69 #login-form table td {padding: 6px;}
70 #login-form label {font-weight: bold;}
70 #login-form label {font-weight: bold;}
71
71
72 input#openid_url { background: url(../images/openid-bg.gif) no-repeat; background-color: #fff; background-position: 0 50%; padding-left: 18px; }
73
72 .clear:after{ content: "."; display: block; height: 0; clear: both; visibility: hidden; }
74 .clear:after{ content: "."; display: block; height: 0; clear: both; visibility: hidden; }
73
75
74 /***** Links *****/
76 /***** Links *****/
General Comments 0
You need to be logged in to leave comments. Login now