Description:
- bootstrap: user admin quick add
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r571:f8d309d2e37e - - 2 files changed: 30 inserted, 29 deleted

@@ -1,456 +1,456
1 require 'csv'
1 require 'csv'
2
2
3 class UserAdminController < ApplicationController
3 class UserAdminController < ApplicationController
4
4
5 include MailHelperMethods
5 include MailHelperMethods
6
6
7 before_filter :admin_authorization
7 before_filter :admin_authorization
8
8
9 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
9 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
10 verify :method => :post, :only => [ :destroy,
10 verify :method => :post, :only => [ :destroy,
11 :create, :create_from_list,
11 :create, :create_from_list,
12 :update,
12 :update,
13 :manage_contest,
13 :manage_contest,
14 :bulk_mail
14 :bulk_mail
15 ],
15 ],
16 :redirect_to => { :action => :list }
16 :redirect_to => { :action => :list }
17
17
18 def index
18 def index
19 list
19 list
20 end
20 end
21
21
22 def list
22 def list
23 @user_count = User.count
23 @user_count = User.count
24 if params[:page] == 'all'
24 if params[:page] == 'all'
25 @users = User.all
25 @users = User.all
26 @paginated = false
26 @paginated = false
27 else
27 else
28 @users = User.paginate :page => params[:page]
28 @users = User.paginate :page => params[:page]
29 @paginated = true
29 @paginated = true
30 end
30 end
31 @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at']
31 @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at']
32 @contests = Contest.enabled
32 @contests = Contest.enabled
33 end
33 end
34
34
35 def active
35 def active
36 sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago])
36 sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago])
37 @users = []
37 @users = []
38 sessions.each do |session|
38 sessions.each do |session|
39 if session.data[:user_id]
39 if session.data[:user_id]
40 @users << User.find(session.data[:user_id])
40 @users << User.find(session.data[:user_id])
41 end
41 end
42 end
42 end
43 end
43 end
44
44
45 def show
45 def show
46 @user = User.find(params[:id])
46 @user = User.find(params[:id])
47 end
47 end
48
48
49 def new
49 def new
50 @user = User.new
50 @user = User.new
51 end
51 end
52
52
53 def create
53 def create
54 @user = User.new(params[:user])
54 @user = User.new(params[:user])
55 @user.activated = true
55 @user.activated = true
56 if @user.save
56 if @user.save
57 flash[:notice] = 'User was successfully created.'
57 flash[:notice] = 'User was successfully created.'
58 - redirect_to :action => 'list'
58 + redirect_to :action => 'index'
59 else
59 else
60 render :action => 'new'
60 render :action => 'new'
61 end
61 end
62 end
62 end
63
63
64 def clear_last_ip
64 def clear_last_ip
65 @user = User.find(params[:id])
65 @user = User.find(params[:id])
66 @user.last_ip = nil
66 @user.last_ip = nil
67 @user.save
67 @user.save
68 - redirect_to action: 'list', page: params[:page]
68 + redirect_to action: 'index', page: params[:page]
69 end
69 end
70
70
71 def create_from_list
71 def create_from_list
72 lines = params[:user_list]
72 lines = params[:user_list]
73
73
74 note = []
74 note = []
75
75
76 lines.split("\n").each do |line|
76 lines.split("\n").each do |line|
77 items = line.chomp.split(',')
77 items = line.chomp.split(',')
78 if items.length>=2
78 if items.length>=2
79 login = items[0]
79 login = items[0]
80 full_name = items[1]
80 full_name = items[1]
81
81
82 added_random_password = false
82 added_random_password = false
83 if items.length>=3
83 if items.length>=3
84 password = items[2].chomp(" ")
84 password = items[2].chomp(" ")
85 user_alias = (items.length>=4) ? items[3] : login
85 user_alias = (items.length>=4) ? items[3] : login
86 else
86 else
87 password = random_password
87 password = random_password
88 user_alias = (items.length>=4) ? items[3] : login
88 user_alias = (items.length>=4) ? items[3] : login
89 added_random_password = true
89 added_random_password = true
90 end
90 end
91
91
92 user = User.find_by_login(login)
92 user = User.find_by_login(login)
93 if (user)
93 if (user)
94 user.full_name = full_name
94 user.full_name = full_name
95 user.password = password
95 user.password = password
96 else
96 else
97 user = User.new({:login => login,
97 user = User.new({:login => login,
98 :full_name => full_name,
98 :full_name => full_name,
99 :password => password,
99 :password => password,
100 :password_confirmation => password,
100 :password_confirmation => password,
101 :alias => user_alias})
101 :alias => user_alias})
102 end
102 end
103 user.activated = true
103 user.activated = true
104 user.save
104 user.save
105
105
106 if added_random_password
106 if added_random_password
107 note << "'#{login}' (+)"
107 note << "'#{login}' (+)"
108 else
108 else
109 note << login
109 note << login
110 end
110 end
111 end
111 end
112 end
112 end
113 flash[:notice] = 'User(s) ' + note.join(', ') +
113 flash[:notice] = 'User(s) ' + note.join(', ') +
114 ' were successfully created. ' +
114 ' were successfully created. ' +
115 '( (+) - created with random passwords.)'
115 '( (+) - created with random passwords.)'
116 - redirect_to :action => 'list'
116 + redirect_to :action => 'index'
117 end
117 end
118
118
119 def edit
119 def edit
120 @user = User.find(params[:id])
120 @user = User.find(params[:id])
121 end
121 end
122
122
123 def update
123 def update
124 @user = User.find(params[:id])
124 @user = User.find(params[:id])
125 if @user.update_attributes(params[:user])
125 if @user.update_attributes(params[:user])
126 flash[:notice] = 'User was successfully updated.'
126 flash[:notice] = 'User was successfully updated.'
127 redirect_to :action => 'show', :id => @user
127 redirect_to :action => 'show', :id => @user
128 else
128 else
129 render :action => 'edit'
129 render :action => 'edit'
130 end
130 end
131 end
131 end
132
132
133 def destroy
133 def destroy
134 User.find(params[:id]).destroy
134 User.find(params[:id]).destroy
135 - redirect_to :action => 'list'
135 + redirect_to :action => 'index'
136 end
136 end
137
137
138 def user_stat
138 def user_stat
139 if params[:commit] == 'download csv'
139 if params[:commit] == 'download csv'
140 @problems = Problem.all
140 @problems = Problem.all
141 else
141 else
142 @problems = Problem.find_available_problems
142 @problems = Problem.find_available_problems
143 end
143 end
144 @users = User.includes(:contests, :contest_stat).where(enabled: true) #find(:all, :include => [:contests, :contest_stat]).where(enabled: true)
144 @users = User.includes(:contests, :contest_stat).where(enabled: true) #find(:all, :include => [:contests, :contest_stat]).where(enabled: true)
145 @scorearray = Array.new
145 @scorearray = Array.new
146 @users.each do |u|
146 @users.each do |u|
147 ustat = Array.new
147 ustat = Array.new
148 ustat[0] = u
148 ustat[0] = u
149 @problems.each do |p|
149 @problems.each do |p|
150 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
150 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
151 if (sub!=nil) and (sub.points!=nil) and p and p.full_score
151 if (sub!=nil) and (sub.points!=nil) and p and p.full_score
152 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
152 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
153 else
153 else
154 ustat << [0,false]
154 ustat << [0,false]
155 end
155 end
156 end
156 end
157 @scorearray << ustat
157 @scorearray << ustat
158 end
158 end
159 if params[:commit] == 'download csv' then
159 if params[:commit] == 'download csv' then
160 csv = gen_csv_from_scorearray(@scorearray,@problems)
160 csv = gen_csv_from_scorearray(@scorearray,@problems)
161 send_data csv, filename: 'last_score.csv'
161 send_data csv, filename: 'last_score.csv'
162 else
162 else
163 render template: 'user_admin/user_stat'
163 render template: 'user_admin/user_stat'
164 end
164 end
165 end
165 end
166
166
167 def user_stat_max
167 def user_stat_max
168 if params[:commit] == 'download csv'
168 if params[:commit] == 'download csv'
169 @problems = Problem.all
169 @problems = Problem.all
170 else
170 else
171 @problems = Problem.find_available_problems
171 @problems = Problem.find_available_problems
172 end
172 end
173 @users = User.find(:all, :include => [:contests, :contest_stat])
173 @users = User.find(:all, :include => [:contests, :contest_stat])
174 @scorearray = Array.new
174 @scorearray = Array.new
175 #set up range from param
175 #set up range from param
176 since_id = params.fetch(:since_id, 0).to_i
176 since_id = params.fetch(:since_id, 0).to_i
177 until_id = params.fetch(:until_id, 0).to_i
177 until_id = params.fetch(:until_id, 0).to_i
178 @users.each do |u|
178 @users.each do |u|
179 ustat = Array.new
179 ustat = Array.new
180 ustat[0] = u
180 ustat[0] = u
181 @problems.each do |p|
181 @problems.each do |p|
182 max_points = 0
182 max_points = 0
183 Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
183 Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
184 max_points = sub.points if sub and sub.points and (sub.points > max_points)
184 max_points = sub.points if sub and sub.points and (sub.points > max_points)
185 end
185 end
186 ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
186 ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
187 end
187 end
188 @scorearray << ustat
188 @scorearray << ustat
189 end
189 end
190
190
191 if params[:commit] == 'download csv' then
191 if params[:commit] == 'download csv' then
192 csv = gen_csv_from_scorearray(@scorearray,@problems)
192 csv = gen_csv_from_scorearray(@scorearray,@problems)
193 send_data csv, filename: 'max_score.csv'
193 send_data csv, filename: 'max_score.csv'
194 else
194 else
195 render template: 'user_admin/user_stat'
195 render template: 'user_admin/user_stat'
196 end
196 end
197 end
197 end
198
198
199 def import
199 def import
200 if params[:file]==''
200 if params[:file]==''
201 flash[:notice] = 'Error importing no file'
201 flash[:notice] = 'Error importing no file'
202 - redirect_to :action => 'list' and return
202 + redirect_to :action => 'index' and return
203 end
203 end
204 import_from_file(params[:file])
204 import_from_file(params[:file])
205 end
205 end
206
206
207 def random_all_passwords
207 def random_all_passwords
208 users = User.find(:all)
208 users = User.find(:all)
209 @prefix = params[:prefix] || ''
209 @prefix = params[:prefix] || ''
210 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
210 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
211 @changed = false
211 @changed = false
212 if request.request_method == 'POST'
212 if request.request_method == 'POST'
213 @non_admin_users.each do |user|
213 @non_admin_users.each do |user|
214 password = random_password
214 password = random_password
215 user.password = password
215 user.password = password
216 user.password_confirmation = password
216 user.password_confirmation = password
217 user.save
217 user.save
218 end
218 end
219 @changed = true
219 @changed = true
220 end
220 end
221 end
221 end
222
222
223 # contest management
223 # contest management
224
224
225 def contests
225 def contests
226 @contest, @users = find_contest_and_user_from_contest_id(params[:id])
226 @contest, @users = find_contest_and_user_from_contest_id(params[:id])
227 @contests = Contest.enabled
227 @contests = Contest.enabled
228 end
228 end
229
229
230 def assign_from_list
230 def assign_from_list
231 contest_id = params[:users_contest_id]
231 contest_id = params[:users_contest_id]
232 org_contest, users = find_contest_and_user_from_contest_id(contest_id)
232 org_contest, users = find_contest_and_user_from_contest_id(contest_id)
233 contest = Contest.find(params[:new_contest][:id])
233 contest = Contest.find(params[:new_contest][:id])
234 if !contest
234 if !contest
235 flash[:notice] = 'Error: no contest'
235 flash[:notice] = 'Error: no contest'
236 redirect_to :action => 'contests', :id =>contest_id
236 redirect_to :action => 'contests', :id =>contest_id
237 end
237 end
238
238
239 note = []
239 note = []
240 users.each do |u|
240 users.each do |u|
241 u.contests = [contest]
241 u.contests = [contest]
242 note << u.login
242 note << u.login
243 end
243 end
244 flash[:notice] = 'User(s) ' + note.join(', ') +
244 flash[:notice] = 'User(s) ' + note.join(', ') +
245 " were successfully reassigned to #{contest.title}."
245 " were successfully reassigned to #{contest.title}."
246 redirect_to :action => 'contests', :id =>contest.id
246 redirect_to :action => 'contests', :id =>contest.id
247 end
247 end
248
248
249 def add_to_contest
249 def add_to_contest
250 user = User.find(params[:id])
250 user = User.find(params[:id])
251 contest = Contest.find(params[:contest_id])
251 contest = Contest.find(params[:contest_id])
252 if user and contest
252 if user and contest
253 user.contests << contest
253 user.contests << contest
254 end
254 end
255 - redirect_to :action => 'list'
255 + redirect_to :action => 'index'
256 end
256 end
257
257
258 def remove_from_contest
258 def remove_from_contest
259 user = User.find(params[:id])
259 user = User.find(params[:id])
260 contest = Contest.find(params[:contest_id])
260 contest = Contest.find(params[:contest_id])
261 if user and contest
261 if user and contest
262 user.contests.delete(contest)
262 user.contests.delete(contest)
263 end
263 end
264 - redirect_to :action => 'list'
264 + redirect_to :action => 'index'
265 end
265 end
266
266
267 def contest_management
267 def contest_management
268 end
268 end
269
269
270 def manage_contest
270 def manage_contest
271 contest = Contest.find(params[:contest][:id])
271 contest = Contest.find(params[:contest][:id])
272 if !contest
272 if !contest
273 flash[:notice] = 'You did not choose the contest.'
273 flash[:notice] = 'You did not choose the contest.'
274 redirect_to :action => 'contest_management' and return
274 redirect_to :action => 'contest_management' and return
275 end
275 end
276
276
277 operation = params[:operation]
277 operation = params[:operation]
278
278
279 if not ['add','remove','assign'].include? operation
279 if not ['add','remove','assign'].include? operation
280 flash[:notice] = 'You did not choose the operation to perform.'
280 flash[:notice] = 'You did not choose the operation to perform.'
281 redirect_to :action => 'contest_management' and return
281 redirect_to :action => 'contest_management' and return
282 end
282 end
283
283
284 lines = params[:login_list]
284 lines = params[:login_list]
285 if !lines or lines.blank?
285 if !lines or lines.blank?
286 flash[:notice] = 'You entered an empty list.'
286 flash[:notice] = 'You entered an empty list.'
287 redirect_to :action => 'contest_management' and return
287 redirect_to :action => 'contest_management' and return
288 end
288 end
289
289
290 note = []
290 note = []
291 users = []
291 users = []
292 lines.split("\n").each do |line|
292 lines.split("\n").each do |line|
293 user = User.find_by_login(line.chomp)
293 user = User.find_by_login(line.chomp)
294 if user
294 if user
295 if operation=='add'
295 if operation=='add'
296 if ! user.contests.include? contest
296 if ! user.contests.include? contest
297 user.contests << contest
297 user.contests << contest
298 end
298 end
299 elsif operation=='remove'
299 elsif operation=='remove'
300 user.contests.delete(contest)
300 user.contests.delete(contest)
301 else
301 else
302 user.contests = [contest]
302 user.contests = [contest]
303 end
303 end
304
304
305 if params[:reset_timer]
305 if params[:reset_timer]
306 user.contest_stat.forced_logout = true
306 user.contest_stat.forced_logout = true
307 user.contest_stat.reset_timer_and_save
307 user.contest_stat.reset_timer_and_save
308 end
308 end
309
309
310 if params[:notification_emails]
310 if params[:notification_emails]
311 send_contest_update_notification_email(user, contest)
311 send_contest_update_notification_email(user, contest)
312 end
312 end
313
313
314 note << user.login
314 note << user.login
315 users << user
315 users << user
316 end
316 end
317 end
317 end
318
318
319 if params[:reset_timer]
319 if params[:reset_timer]
320 logout_users(users)
320 logout_users(users)
321 end
321 end
322
322
323 flash[:notice] = 'User(s) ' + note.join(', ') +
323 flash[:notice] = 'User(s) ' + note.join(', ') +
324 ' were successfully modified. '
324 ' were successfully modified. '
325 redirect_to :action => 'contest_management'
325 redirect_to :action => 'contest_management'
326 end
326 end
327
327
328 # admin management
328 # admin management
329
329
330 def admin
330 def admin
331 @admins = User.find(:all).find_all {|user| user.admin? }
331 @admins = User.find(:all).find_all {|user| user.admin? }
332 end
332 end
333
333
334 def grant_admin
334 def grant_admin
335 login = params[:login]
335 login = params[:login]
336 user = User.find_by_login(login)
336 user = User.find_by_login(login)
337 if user!=nil
337 if user!=nil
338 admin_role = Role.find_by_name('admin')
338 admin_role = Role.find_by_name('admin')
339 user.roles << admin_role
339 user.roles << admin_role
340 else
340 else
341 flash[:notice] = 'Unknown user'
341 flash[:notice] = 'Unknown user'
342 end
342 end
343 flash[:notice] = 'User added as admins'
343 flash[:notice] = 'User added as admins'
344 redirect_to :action => 'admin'
344 redirect_to :action => 'admin'
345 end
345 end
346
346
347 def revoke_admin
347 def revoke_admin
348 user = User.find(params[:id])
348 user = User.find(params[:id])
349 if user==nil
349 if user==nil
350 flash[:notice] = 'Unknown user'
350 flash[:notice] = 'Unknown user'
351 redirect_to :action => 'admin' and return
351 redirect_to :action => 'admin' and return
352 elsif user.login == 'root'
352 elsif user.login == 'root'
353 flash[:notice] = 'You cannot revoke admisnistrator permission from root.'
353 flash[:notice] = 'You cannot revoke admisnistrator permission from root.'
354 redirect_to :action => 'admin' and return
354 redirect_to :action => 'admin' and return
355 end
355 end
356
356
357 admin_role = Role.find_by_name('admin')
357 admin_role = Role.find_by_name('admin')
358 user.roles.delete(admin_role)
358 user.roles.delete(admin_role)
359 flash[:notice] = 'User permission revoked'
359 flash[:notice] = 'User permission revoked'
360 redirect_to :action => 'admin'
360 redirect_to :action => 'admin'
361 end
361 end
362
362
363 # mass mailing
363 # mass mailing
364
364
365 def mass_mailing
365 def mass_mailing
366 end
366 end
367
367
368 def bulk_mail
368 def bulk_mail
369 lines = params[:login_list]
369 lines = params[:login_list]
370 if !lines or lines.blank?
370 if !lines or lines.blank?
371 flash[:notice] = 'You entered an empty list.'
371 flash[:notice] = 'You entered an empty list.'
372 redirect_to :action => 'mass_mailing' and return
372 redirect_to :action => 'mass_mailing' and return
373 end
373 end
374
374
375 mail_subject = params[:subject]
375 mail_subject = params[:subject]
376 if !mail_subject or mail_subject.blank?
376 if !mail_subject or mail_subject.blank?
377 flash[:notice] = 'You entered an empty mail subject.'
377 flash[:notice] = 'You entered an empty mail subject.'
378 redirect_to :action => 'mass_mailing' and return
378 redirect_to :action => 'mass_mailing' and return
379 end
379 end
380
380
381 mail_body = params[:email_body]
381 mail_body = params[:email_body]
382 if !mail_body or mail_body.blank?
382 if !mail_body or mail_body.blank?
383 flash[:notice] = 'You entered an empty mail body.'
383 flash[:notice] = 'You entered an empty mail body.'
384 redirect_to :action => 'mass_mailing' and return
384 redirect_to :action => 'mass_mailing' and return
385 end
385 end
386
386
387 note = []
387 note = []
388 users = []
388 users = []
389 lines.split("\n").each do |line|
389 lines.split("\n").each do |line|
390 user = User.find_by_login(line.chomp)
390 user = User.find_by_login(line.chomp)
391 if user
391 if user
392 send_mail(user.email, mail_subject, mail_body)
392 send_mail(user.email, mail_subject, mail_body)
393 note << user.login
393 note << user.login
394 end
394 end
395 end
395 end
396
396
397 flash[:notice] = 'User(s) ' + note.join(', ') +
397 flash[:notice] = 'User(s) ' + note.join(', ') +
398 ' were successfully modified. '
398 ' were successfully modified. '
399 redirect_to :action => 'mass_mailing'
399 redirect_to :action => 'mass_mailing'
400 end
400 end
401
401
402 protected
402 protected
403
403
404 def random_password(length=5)
404 def random_password(length=5)
405 chars = 'abcdefghijkmnopqrstuvwxyz23456789'
405 chars = 'abcdefghijkmnopqrstuvwxyz23456789'
406 newpass = ""
406 newpass = ""
407 length.times { newpass << chars[rand(chars.size-1)] }
407 length.times { newpass << chars[rand(chars.size-1)] }
408 return newpass
408 return newpass
409 end
409 end
410
410
411 def import_from_file(f)
411 def import_from_file(f)
412 data_hash = YAML.load(f)
412 data_hash = YAML.load(f)
413 @import_log = ""
413 @import_log = ""
414
414
415 country_data = data_hash[:countries]
415 country_data = data_hash[:countries]
416 site_data = data_hash[:sites]
416 site_data = data_hash[:sites]
417 user_data = data_hash[:users]
417 user_data = data_hash[:users]
418
418
419 # import country
419 # import country
420 countries = {}
420 countries = {}
421 country_data.each_pair do |id,country|
421 country_data.each_pair do |id,country|
422 c = Country.find_by_name(country[:name])
422 c = Country.find_by_name(country[:name])
423 if c!=nil
423 if c!=nil
424 countries[id] = c
424 countries[id] = c
425 @import_log << "Found #{country[:name]}\n"
425 @import_log << "Found #{country[:name]}\n"
426 else
426 else
427 countries[id] = Country.new(:name => country[:name])
427 countries[id] = Country.new(:name => country[:name])
428 countries[id].save
428 countries[id].save
429 @import_log << "Created #{country[:name]}\n"
429 @import_log << "Created #{country[:name]}\n"
430 end
430 end
431 end
431 end
432
432
433 # import sites
433 # import sites
434 sites = {}
434 sites = {}
435 site_data.each_pair do |id,site|
435 site_data.each_pair do |id,site|
436 s = Site.find_by_name(site[:name])
436 s = Site.find_by_name(site[:name])
437 if s!=nil
437 if s!=nil
438 @import_log << "Found #{site[:name]}\n"
438 @import_log << "Found #{site[:name]}\n"
439 else
439 else
440 s = Site.new(:name => site[:name])
440 s = Site.new(:name => site[:name])
441 @import_log << "Created #{site[:name]}\n"
441 @import_log << "Created #{site[:name]}\n"
442 end
442 end
443 s.password = site[:password]
443 s.password = site[:password]
444 s.country = countries[site[:country_id]]
444 s.country = countries[site[:country_id]]
445 s.save
445 s.save
446 sites[id] = s
446 sites[id] = s
447 end
447 end
448
448
449 # import users
449 # import users
450 user_data.each_pair do |id,user|
450 user_data.each_pair do |id,user|
451 u = User.find_by_login(user[:login])
451 u = User.find_by_login(user[:login])
452 if u!=nil
452 if u!=nil
453 @import_log << "Found #{user[:login]}\n"
453 @import_log << "Found #{user[:login]}\n"
454 else
454 else
455 u = User.new(:login => user[:login])
455 u = User.new(:login => user[:login])
456 @import_log << "Created #{user[:login]}\n"
456 @import_log << "Created #{user[:login]}\n"
@@ -1,86 +1,87
1 %h1 Listing users
1 %h1 Listing users
2 +
3 + .panel.panel-primary
4 + .panel-title.panel-heading
5 + Quick Add
6 + .panel-body
7 + = form_tag( {method: 'post'}, {class: 'form-inline'}) do
8 + .form-group
9 + = label_tag 'user_login', 'Login'
10 + = text_field 'user', 'login', :size => 10,class: 'form-control'
11 + .form-group
12 + = label_tag 'user_full_name', 'Full Name'
13 + = text_field 'user', 'full_name', :size => 10,class: 'form-control'
14 + .form-group
15 + = label_tag 'user_password', 'Password'
16 + = text_field 'user', 'password', :size => 10,class: 'form-control'
17 + .form-group
18 + = label_tag 'user_password_confirmation', 'Confirm'
19 + = text_field 'user', 'password_confirmation', :size => 10,class: 'form-control'
20 + .form-group
21 + = label_tag 'user_email', 'email'
22 + = text_field 'user', 'email', :size => 10,class: 'form-control'
23 + =submit_tag "Create", class: 'btn btn-primary'
24 +
2 .submitbox
25 .submitbox
3 - %b Quick add
4 - = form_tag :action => 'create' do
5 - %table{:border => "0"}
6 - %tr
7 - %td
8 - %label{:for => "user_login"} Login
9 - %td
10 - %label{:for => "user_full_name"} Full name
11 - %td
12 - %label{:for => "user_password"} Password
13 - %td
14 - %label{:for => "user_password_confirmation"} Confirm
15 - %td
16 - %label{:for => "user_email"} Email
17 - %tr
18 - %td= text_field 'user', 'login', :size => 10
19 - %td= text_field 'user', 'full_name', :size => 30
20 - %td= password_field 'user', 'password', :size => 10
21 - %td= password_field 'user', 'password_confirmation', :size => 10
22 - %td= email_field 'user', 'email', :size => 15
23 - %td= submit_tag "Create"
24 - %br/
25 %b Import from site management
26 %b Import from site management
26 = form_tag({:action => 'import'}, :multipart => true) do
27 = form_tag({:action => 'import'}, :multipart => true) do
27 File: #{file_field_tag 'file'} #{submit_tag 'Import'}
28 File: #{file_field_tag 'file'} #{submit_tag 'Import'}
28 %br/
29 %br/
29 %b What else:
30 %b What else:
30 = link_to 'New user', {:action => 'new'}, { class: 'btn btn-default btn-sm'}
31 = link_to 'New user', {:action => 'new'}, { class: 'btn btn-default btn-sm'}
31 = link_to 'New list of users',{ :action => 'new_list'}, { class: 'btn btn-default btn-sm'}
32 = link_to 'New list of users',{ :action => 'new_list'}, { class: 'btn btn-default btn-sm'}
32 = link_to 'View administrators',{ :action => 'admin'}, { class: 'btn btn-default btn-sm'}
33 = link_to 'View administrators',{ :action => 'admin'}, { class: 'btn btn-default btn-sm'}
33 = link_to 'Random passwords',{ :action => 'random_all_passwords'}, { class: 'btn btn-default btn-sm'}
34 = link_to 'Random passwords',{ :action => 'random_all_passwords'}, { class: 'btn btn-default btn-sm'}
34 = link_to 'View active users',{ :action => 'active'}, { class: 'btn btn-default btn-sm'}
35 = link_to 'View active users',{ :action => 'active'}, { class: 'btn btn-default btn-sm'}
35 = link_to 'Mass mailing',{ :action => 'mass_mailing'}, { class: 'btn btn-default btn-sm'}
36 = link_to 'Mass mailing',{ :action => 'mass_mailing'}, { class: 'btn btn-default btn-sm'}
36 - if GraderConfiguration.multicontests?
37 - if GraderConfiguration.multicontests?
37 %br/
38 %br/
38 %b Multi-contest:
39 %b Multi-contest:
39 = link_to '[Manage bulk users in contests]', :action => 'contest_management'
40 = link_to '[Manage bulk users in contests]', :action => 'contest_management'
40 View users in:
41 View users in:
41 - @contests.each do |contest|
42 - @contests.each do |contest|
42 = link_to "[#{contest.name}]", :action => 'contests', :id => contest.id
43 = link_to "[#{contest.name}]", :action => 'contests', :id => contest.id
43 = link_to "[no contest]", :action => 'contests', :id => 'none'
44 = link_to "[no contest]", :action => 'contests', :id => 'none'
44 Total #{@user_count} users |
45 Total #{@user_count} users |
45 - if !@paginated
46 - if !@paginated
46 Display all users.
47 Display all users.
47 \#{link_to '[show in pages]', :action => 'index', :page => '1'}
48 \#{link_to '[show in pages]', :action => 'index', :page => '1'}
48 - else
49 - else
49 Display in pages.
50 Display in pages.
50 \#{link_to '[display all]', :action => 'index', :page => 'all'} |
51 \#{link_to '[display all]', :action => 'index', :page => 'all'} |
51 \#{will_paginate @users, :container => false}
52 \#{will_paginate @users, :container => false}
52
53
53
54
54 %table.table.table-hover.table-condense
55 %table.table.table-hover.table-condense
55 %thead
56 %thead
56 %th Login
57 %th Login
57 %th Full name
58 %th Full name
58 %th email
59 %th email
59 %th Remark
60 %th Remark
60 %th
61 %th
61 Activated
62 Activated
62 %sup{class: 'text-primary',data: {toggle: 'tooltip', placement: 'top'}, title: 'User has already confirmed the email?' } [?]
63 %sup{class: 'text-primary',data: {toggle: 'tooltip', placement: 'top'}, title: 'User has already confirmed the email?' } [?]
63 %th
64 %th
64 Enabled
65 Enabled
65 %sup{class: 'text-primary',data: {toggle: 'tooltip', placement: 'top'}, title: 'Allow the user to login?' } [?]
66 %sup{class: 'text-primary',data: {toggle: 'tooltip', placement: 'top'}, title: 'Allow the user to login?' } [?]
66 %th Last IP
67 %th Last IP
67 %th
68 %th
68 %th
69 %th
69 %th
70 %th
70 %th
71 %th
71 - for user in @users
72 - for user in @users
72 %tr
73 %tr
73 %td= link_to user.login, controller: :users, :action => 'profile', :id => user
74 %td= link_to user.login, controller: :users, :action => 'profile', :id => user
74 %td= user.full_name
75 %td= user.full_name
75 %td= user.email
76 %td= user.email
76 %td= user.remark
77 %td= user.remark
77 %td= toggle_button(user.activated?, toggle_activate_user_url(user),"toggle_activate_user_#{user.id}")
78 %td= toggle_button(user.activated?, toggle_activate_user_url(user),"toggle_activate_user_#{user.id}")
78 %td= toggle_button(user.enabled?, toggle_enable_user_url(user),"toggle_enable_user_#{user.id}")
79 %td= toggle_button(user.enabled?, toggle_enable_user_url(user),"toggle_enable_user_#{user.id}")
79 %td= user.last_ip
80 %td= user.last_ip
80 %td= link_to 'Clear IP', {:action => 'clear_last_ip', :id => user, :page=>params[:page]}, :confirm => 'This will reset last logging in ip of the user, are you sure?', class: 'btn btn-default btn-xs btn-block'
81 %td= link_to 'Clear IP', {:action => 'clear_last_ip', :id => user, :page=>params[:page]}, :confirm => 'This will reset last logging in ip of the user, are you sure?', class: 'btn btn-default btn-xs btn-block'
81 %td= link_to 'Show', {:action => 'show', :id => user}, class: 'btn btn-default btn-xs btn-block'
82 %td= link_to 'Show', {:action => 'show', :id => user}, class: 'btn btn-default btn-xs btn-block'
82 %td= link_to 'Edit', {:action => 'edit', :id => user}, class: 'btn btn-default btn-xs btn-block'
83 %td= link_to 'Edit', {:action => 'edit', :id => user}, class: 'btn btn-default btn-xs btn-block'
83 %td= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post, class: 'btn btn-danger btn-xs btn-block'
84 %td= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post, class: 'btn btn-danger btn-xs btn-block'
84 %br/
85 %br/
85 = link_to '[New user]', :action => 'new'
86 = link_to '[New user]', :action => 'new'
86 = link_to '[New list of users]', :action => 'new_list'
87 = link_to '[New list of users]', :action => 'new_list'
You need to be logged in to leave comments. Login now