return unless request.post?
cookies.delete :auth_token
- user=prepare_user
- if user.save
- flash[:notice] = 'User is created.'
- end
+ user = User.find_by_login(params[:user][:login])
+ if user && !user.active
+ # users was deleted, a message must be displayed to ask wether to override it or not
+ @user = user
+ @user.name = params[:user][:name]
+ @user.email = params[:user][:email]
+ @users = User.find(:all, :conditions => ["active=?", true], :include => 'groups')
+ render :index
+ else
+ user=prepare_user
+ if user.save
+ flash[:notice] = 'User is created.'
+ end
+ to_index(user.errors, nil)
+ end
- to_index(user.errors, nil)
end
def signup
to_index(user.errors, nil)
end
+
+ def reactivate
+ user = User.find_by_login(params[:user][:login])
+ if user
+ user.name = params[:user][:name]
+ user.email = params[:user][:email]
+ user.password = params[:user][:password]
+ user.password_confirmation = params[:user][:password_confirmation]
+ user.active = true
+ user.save!
+ flash[:notice] = 'User was successfully reactivated.'
+ else
+ flash[:error] = "A user with login #{params[:user][:login]} does not exist."
+ end
+ to_index(user.errors, nil)
+ end
def destroy
@user = User.find(params[:id])
<%
action_name = 'create'
title = 'Add new user'
+ submit_button_label = 'Create'
if @user.id
- action_name = 'update'
- title = 'Edit user'
- if params[:action] == 'change_password'
- action_name = 'update_password'
- title = 'Change password'
+ if @user.active
+ action_name = 'update'
+ title = 'Edit user'
+ submit_button_label = 'Update'
+ if params[:action] == 'change_password'
+ action_name = 'update_password'
+ title = 'Change password'
+ end
+ else
+ action_name = 'reactivate'
+ title = 'Reactivate user?'
+ submit_button_label = 'Reactivate user'
end
end
%>
<% form_for :user, @user, :url => { :id => @user.id, :action => action_name}, :html => { :method => @user.id.nil?? :post : :put } do |f| %>
<table class="admintable" width="100%">
<tr>
- <td class="left" valign="top"><h1><%= title %></h1></td>
+ <td class="left" valign="top"><h1><%= title %></h1></td>
+ </tr>
+
+ <% if @user && !@user.active %>
+ <%= @user.name -%>
+ <%= f.hidden_field :login %>
+ <%= f.hidden_field :name %>
+ <%= f.hidden_field :email %>
+ <tr>
+ <td>
+ <p class="error">
+ A user with login "<%= @user.login -%>" already exists in the database but had been deleted.<br/>
+ <br/>
+ Do you want to reactivate this user? (if yes, please provide a new password)
+ </p>
+ </td>
+ <tr>
+ <td class="left" valign="top">New password:<br/><%= f.password_field :password, :size => 30, :maxLength => 50 %></td>
+ </tr>
+ <tr>
+ <td class="left" valign="top">Confirm new password:<br/><%= f.password_field :password_confirmation, :size => 30, :maxLength => 50 %></td>
</tr>
+ <tr>
+ <% else %>
<tr>
<td class="left" valign="top">Login:
<% if @user.id %>
<td class="left" valign="top">Confirm new password:<br/><%= f.password_field :password_confirmation, :size => 30, :maxLength => 50 %></td>
</tr>
<% end %>
+ <% end %>
+
<tr>
<td class="left" nowrap="nowrap" valign="top" colspan="2">
- <%= submit_tag @user.id.nil?? 'Create':'Update' %>
+ <%= submit_tag submit_button_label %>
<%= link_to 'cancel', { :controller => 'users', :action => 'index'}, { :class => 'action' } %><br/>
</td>
</tr>