Description:
fixed userlist-add inconsistency
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@272 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r136:877c184d2b5d - - 2 files changed: 12 inserted, 7 deleted
@@ -1,94 +1,94 | |||
|
1 | 1 | class UserAdminController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :admin_authorization |
|
4 | 4 | |
|
5 | 5 | def index |
|
6 | 6 | list |
|
7 | 7 | render :action => 'list' |
|
8 | 8 | end |
|
9 | 9 | |
|
10 | 10 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
11 | 11 | verify :method => :post, :only => [ :destroy, :create, :update ], |
|
12 | 12 | :redirect_to => { :action => :list } |
|
13 | 13 | |
|
14 | 14 | def list |
|
15 | 15 | @users = User.find(:all) |
|
16 | 16 | end |
|
17 | 17 | |
|
18 | 18 | def show |
|
19 | 19 | @user = User.find(params[:id]) |
|
20 | 20 | end |
|
21 | 21 | |
|
22 | 22 | def new |
|
23 | 23 | @user = User.new |
|
24 | 24 | end |
|
25 | 25 | |
|
26 | 26 | def create |
|
27 | 27 | @user = User.new(params[:user]) |
|
28 | 28 | if @user.save |
|
29 | 29 | flash[:notice] = 'User was successfully created.' |
|
30 | 30 | redirect_to :action => 'list' |
|
31 | 31 | else |
|
32 | 32 | render :action => 'new' |
|
33 | 33 | end |
|
34 | 34 | end |
|
35 | 35 | |
|
36 | 36 | def create_from_list |
|
37 | 37 | lines = params[:user_list] |
|
38 | 38 | lines.split("\n").each do |line| |
|
39 | - items = line.split | |
|
40 |
- if items.length== |
|
|
39 | + items = line.split(',') | |
|
40 | + if items.length==4 | |
|
41 | 41 | user = User.new |
|
42 | 42 | user.login = items[0] |
|
43 |
- user.full_name = |
|
|
44 |
- user.alias = items[ |
|
|
45 |
- user.password = items[ |
|
|
46 |
- user.password_confirmation = items[ |
|
|
43 | + user.full_name = items[1] | |
|
44 | + user.alias = items[2] | |
|
45 | + user.password = items[3] | |
|
46 | + user.password_confirmation = items[3] | |
|
47 | 47 | user.save |
|
48 | 48 | end |
|
49 | 49 | end |
|
50 | 50 | redirect_to :action => 'list' |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | def edit |
|
54 | 54 | @user = User.find(params[:id]) |
|
55 | 55 | end |
|
56 | 56 | |
|
57 | 57 | def update |
|
58 | 58 | @user = User.find(params[:id]) |
|
59 | 59 | if @user.update_attributes(params[:user]) |
|
60 | 60 | flash[:notice] = 'User was successfully updated.' |
|
61 | 61 | redirect_to :action => 'show', :id => @user |
|
62 | 62 | else |
|
63 | 63 | render :action => 'edit' |
|
64 | 64 | end |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | def destroy |
|
68 | 68 | User.find(params[:id]).destroy |
|
69 | 69 | redirect_to :action => 'list' |
|
70 | 70 | end |
|
71 | 71 | |
|
72 | 72 | def user_stat |
|
73 | 73 | @problems = Problem.find_available_problems |
|
74 | 74 | @users = User.find(:all) |
|
75 | 75 | @scorearray = Array.new |
|
76 | 76 | @users.each do |u| |
|
77 | 77 | ustat = Array.new |
|
78 | 78 | ustat[0] = u.login |
|
79 | 79 | ustat[1] = u.full_name |
|
80 | 80 | @problems.each do |p| |
|
81 | 81 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
82 | 82 | if (sub!=nil) and (sub.points!=nil) |
|
83 | 83 | ustat << [sub.points, (sub.points>=p.full_score)] |
|
84 | 84 | else |
|
85 | 85 | ustat << [0,false] |
|
86 | 86 | end |
|
87 | 87 | end |
|
88 | 88 | @scorearray << ustat |
|
89 | 89 | end |
|
90 | 90 | end |
|
91 | 91 | |
|
92 | 92 | def import |
|
93 | 93 | if params[:file]=='' |
|
94 | 94 | flash[:notice] = 'Error importing no file' |
You need to be logged in to leave comments.
Login now