Permalink
Browse files

login: allow to register new user accounts

  • Loading branch information...
nackd committed Dec 29, 2010
1 parent 0218a28 commit 80f35d21b77e7061ab824511960b8c0f9248969b
Showing with 40 additions and 3 deletions.
  1. +32 −0 app/views/account/register_with_cas.html.erb
  2. +8 −3 lib/cas/application_controller_patch.rb
@@ -0,0 +1,32 @@
+<h2><%=l(:label_register)%></h2>
+
+<% form_tag({:controller => 'account', :action => 'register'}, :class => "tabular") do %>
+<%= error_messages_for 'user' %>
+
+<div class="box">
+<!--[form:user]-->
+<% if @user.auth_source_id.nil? %>
+<p><label for="user_login"><%=l(:field_login)%> <span class="required">*</span></label>
+<%= text_field 'user', 'login', :size => 25, :disabled => true %></p>
+<% end %>
+
+<p><label for="user_firstname"><%=l(:field_firstname)%> <span class="required">*</span></label>
+<%= text_field 'user', 'firstname' %></p>
+
+<p><label for="user_lastname"><%=l(:field_lastname)%> <span class="required">*</span></label>
+<%= text_field 'user', 'lastname' %></p>
+
+<p><label for="user_mail"><%=l(:field_mail)%> <span class="required">*</span></label>
+<%= text_field 'user', 'mail' %></p>
+
+<p><label for="user_language"><%=l(:field_language)%></label>
+<%= select("user", "language", lang_options_for_select) %></p>
+
+<% @user.custom_field_values.select {|v| v.editable? || v.required?}.each do |value| %>
+ <p><%= custom_field_tag_with_label :user, value %></p>
+<% end %>
+<!--[eoform:user]-->
+</div>
+
+<%= submit_tag l(:button_submit) %>
+<% end %>
@@ -19,7 +19,7 @@ def self.included(base) # :nodoc:
module InstanceMethods
def cas_filter
- if CAS::CONFIG['enabled'] and !['atom', 'xml', 'json'].include?request.format
+ if CAS::CONFIG['enabled'] and !['atom', 'xml', 'json'].include? request.format
if params[:controller] != 'account'
CASClient::Frameworks::Rails::GatewayFilter.filter(self)
else
@@ -33,9 +33,14 @@ def cas_filter
def set_user_id
if CAS::CONFIG['enabled']
user = User.find_by_login session[:cas_user]
- if user and session[:user_id] != user.id
+ if user.nil? # New user
+ @user = User.new(:language => Setting.default_language)
+ @user.login = session[:cas_user]
+ session[:auth_source_registration] = { :login => @user.login }
+ render :template => 'account/register_with_cas'
+ elsif session[:user_id] != user.id
session[:user_id] = user.id
- call_hook(:controller_account_success_authentication_after, {:user => user })
+ call_hook(:controller_account_success_authentication_after, { :user => user })
end
end
true

0 comments on commit 80f35d2

Please sign in to comment.