2 # This file is part of SMR.
4 # SMR is free software: you can redistribute it and/or modify it under the
5 # terms of the GNU General Public License as published by the Free Software
6 # Foundation, either version 3 of the License, or (at your option) any later
9 # SMR is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # SMR. If not, see <http://www.gnu.org/licenses/>.
18 # handles CRUD on User records
19 class Objects::UserController < ObjectsController
22 @users, @total_pages = smr_paginate(
24 User.order(:login).to_a
29 # defines new User to #create
36 # - until proper permissions are implemented a User can only edit itself,
38 # - each User can, however, create new users.
45 # handles creates and updates
46 # - until proper permissions are implemented a User can only edit itself,
49 if params[:user][:id].to_i > 0 then
50 u = User.where(:id=>current_user.id).first
53 if not params[:user][:password].empty? then
54 if params[:user][:password].eql?(params[:user][:password_confirm]) then
55 u.password = params[:user][:password].to_s
57 flash[:notice] = 'Password changed.'
59 redirect_to :back, :alert=>'Confirming password failed. Typo?'
64 u = User.new(user_params)
65 flash[:notice] = 'new users initial password is: "%s"' % u.generate_password
69 flash[:alert] = u.errors.full_messages.uniq.join(', ') unless u.errors.empty?
70 redirect_to objects_user_index_path
76 # internal helper defining parameters acceptable for User create/update
78 params.require(:user).permit(
79 :id, :login, :is_admin, :fullname, :email, :comment,
80 :Bookmark_attributes=> [ :id, :name, :url, :rank ]