Description:
fixed form_tag bug in views
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r340:f512a445945b - - 2 files changed: 3 inserted, 3 deleted
@@ -60,193 +60,193 | |||
|
60 | 60 | end |
|
61 | 61 | end |
|
62 | 62 | |
|
63 | 63 | def create_from_list |
|
64 | 64 | lines = params[:user_list] |
|
65 | 65 | |
|
66 | 66 | note = [] |
|
67 | 67 | |
|
68 | 68 | lines.split("\n").each do |line| |
|
69 | 69 | items = line.chomp.split(',') |
|
70 | 70 | if items.length>=2 |
|
71 | 71 | login = items[0] |
|
72 | 72 | full_name = items[1] |
|
73 | 73 | |
|
74 | 74 | added_random_password = false |
|
75 | 75 | if items.length>=3 |
|
76 | 76 | password = items[2].chomp(" ") |
|
77 | 77 | user_alias = (items.length>=4) ? items[3] : login |
|
78 | 78 | else |
|
79 | 79 | password = random_password |
|
80 | 80 | user_alias = (items.length>=4) ? items[3] : login |
|
81 | 81 | added_random_password = true |
|
82 | 82 | end |
|
83 | 83 | |
|
84 | 84 | user = User.new({:login => login, |
|
85 | 85 | :full_name => full_name, |
|
86 | 86 | :password => password, |
|
87 | 87 | :password_confirmation => password, |
|
88 | 88 | :alias => user_alias}) |
|
89 | 89 | user.activated = true |
|
90 | 90 | user.save |
|
91 | 91 | |
|
92 | 92 | if added_random_password |
|
93 | 93 | note << "'#{login}' (+)" |
|
94 | 94 | else |
|
95 | 95 | note << login |
|
96 | 96 | end |
|
97 | 97 | end |
|
98 | 98 | end |
|
99 | 99 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
100 | 100 | ' were successfully created. ' + |
|
101 | 101 | '( (+) - created with random passwords.)' |
|
102 | 102 | redirect_to :action => 'list' |
|
103 | 103 | end |
|
104 | 104 | |
|
105 | 105 | def edit |
|
106 | 106 | @user = User.find(params[:id]) |
|
107 | 107 | end |
|
108 | 108 | |
|
109 | 109 | def update |
|
110 | 110 | @user = User.find(params[:id]) |
|
111 | 111 | if @user.update_attributes(params[:user]) |
|
112 | 112 | flash[:notice] = 'User was successfully updated.' |
|
113 | 113 | redirect_to :action => 'show', :id => @user |
|
114 | 114 | else |
|
115 | 115 | render :action => 'edit' |
|
116 | 116 | end |
|
117 | 117 | end |
|
118 | 118 | |
|
119 | 119 | def destroy |
|
120 | 120 | User.find(params[:id]).destroy |
|
121 | 121 | redirect_to :action => 'list' |
|
122 | 122 | end |
|
123 | 123 | |
|
124 | 124 | def user_stat |
|
125 | 125 | @problems = Problem.find_available_problems |
|
126 | 126 | @users = User.find(:all, :include => [:contests, :contest_stat]) |
|
127 | 127 | @scorearray = Array.new |
|
128 | 128 | @users.each do |u| |
|
129 | 129 | ustat = Array.new |
|
130 | 130 | ustat[0] = u |
|
131 | 131 | @problems.each do |p| |
|
132 | 132 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
133 | 133 | if (sub!=nil) and (sub.points!=nil) |
|
134 | 134 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
135 | 135 | else |
|
136 | 136 | ustat << [0,false] |
|
137 | 137 | end |
|
138 | 138 | end |
|
139 | 139 | @scorearray << ustat |
|
140 | 140 | end |
|
141 | 141 | end |
|
142 | 142 | |
|
143 | 143 | def import |
|
144 | 144 | if params[:file]=='' |
|
145 | 145 | flash[:notice] = 'Error importing no file' |
|
146 | 146 | redirect_to :action => 'list' and return |
|
147 | 147 | end |
|
148 | 148 | import_from_file(params[:file]) |
|
149 | 149 | end |
|
150 | 150 | |
|
151 | 151 | def random_all_passwords |
|
152 | 152 | users = User.find(:all) |
|
153 | 153 | @prefix = params[:prefix] || '' |
|
154 | 154 | @non_admin_users = User.find_non_admin_with_prefix(@prefix) |
|
155 | 155 | @changed = false |
|
156 |
- if request.request_method == |
|
|
156 | + if request.request_method == 'POST' | |
|
157 | 157 | @non_admin_users.each do |user| |
|
158 | 158 | password = random_password |
|
159 | 159 | user.password = password |
|
160 | 160 | user.password_confirmation = password |
|
161 | 161 | user.save |
|
162 | 162 | end |
|
163 | 163 | @changed = true |
|
164 | 164 | end |
|
165 | 165 | end |
|
166 | 166 | |
|
167 | 167 | # contest management |
|
168 | 168 | |
|
169 | 169 | def contests |
|
170 | 170 | @contest, @users = find_contest_and_user_from_contest_id(params[:id]) |
|
171 | 171 | @contests = Contest.enabled |
|
172 | 172 | end |
|
173 | 173 | |
|
174 | 174 | def assign_from_list |
|
175 | 175 | contest_id = params[:users_contest_id] |
|
176 | 176 | org_contest, users = find_contest_and_user_from_contest_id(contest_id) |
|
177 | 177 | contest = Contest.find(params[:new_contest][:id]) |
|
178 | 178 | if !contest |
|
179 | 179 | flash[:notice] = 'Error: no contest' |
|
180 | 180 | redirect_to :action => 'contests', :id =>contest_id |
|
181 | 181 | end |
|
182 | 182 | |
|
183 | 183 | note = [] |
|
184 | 184 | users.each do |u| |
|
185 | 185 | u.contests = [contest] |
|
186 | 186 | note << u.login |
|
187 | 187 | end |
|
188 | 188 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
189 | 189 | " were successfully reassigned to #{contest.title}." |
|
190 | 190 | redirect_to :action => 'contests', :id =>contest.id |
|
191 | 191 | end |
|
192 | 192 | |
|
193 | 193 | def add_to_contest |
|
194 | 194 | user = User.find(params[:id]) |
|
195 | 195 | contest = Contest.find(params[:contest_id]) |
|
196 | 196 | if user and contest |
|
197 | 197 | user.contests << contest |
|
198 | 198 | end |
|
199 | 199 | redirect_to :action => 'list' |
|
200 | 200 | end |
|
201 | 201 | |
|
202 | 202 | def remove_from_contest |
|
203 | 203 | user = User.find(params[:id]) |
|
204 | 204 | contest = Contest.find(params[:contest_id]) |
|
205 | 205 | if user and contest |
|
206 | 206 | user.contests.delete(contest) |
|
207 | 207 | end |
|
208 | 208 | redirect_to :action => 'list' |
|
209 | 209 | end |
|
210 | 210 | |
|
211 | 211 | def contest_management |
|
212 | 212 | end |
|
213 | 213 | |
|
214 | 214 | def manage_contest |
|
215 | 215 | contest = Contest.find(params[:contest][:id]) |
|
216 | 216 | if !contest |
|
217 | 217 | flash[:notice] = 'You did not choose the contest.' |
|
218 | 218 | redirect_to :action => 'contest_management' and return |
|
219 | 219 | end |
|
220 | 220 | |
|
221 | 221 | operation = params[:operation] |
|
222 | 222 | |
|
223 | 223 | if not ['add','remove','assign'].include? operation |
|
224 | 224 | flash[:notice] = 'You did not choose the operation to perform.' |
|
225 | 225 | redirect_to :action => 'contest_management' and return |
|
226 | 226 | end |
|
227 | 227 | |
|
228 | 228 | lines = params[:login_list] |
|
229 | 229 | if !lines or lines.blank? |
|
230 | 230 | flash[:notice] = 'You entered an empty list.' |
|
231 | 231 | redirect_to :action => 'contest_management' and return |
|
232 | 232 | end |
|
233 | 233 | |
|
234 | 234 | note = [] |
|
235 | 235 | users = [] |
|
236 | 236 | lines.split("\n").each do |line| |
|
237 | 237 | user = User.find_by_login(line.chomp) |
|
238 | 238 | if user |
|
239 | 239 | if operation=='add' |
|
240 | 240 | if ! user.contests.include? contest |
|
241 | 241 | user.contests << contest |
|
242 | 242 | end |
|
243 | 243 | elsif operation=='remove' |
|
244 | 244 | user.contests.delete(contest) |
|
245 | 245 | else |
|
246 | 246 | user.contests = [contest] |
|
247 | 247 | end |
|
248 | 248 | |
|
249 | 249 | if params[:reset_timer] |
|
250 | 250 | user.contest_stat.forced_logout = true |
|
251 | 251 | user.contest_stat.reset_timer_and_save |
|
252 | 252 | end |
@@ -1,39 +1,39 | |||
|
1 | 1 | %h1 Random user passwords |
|
2 | 2 | |
|
3 | 3 | -if @changed |
|
4 | 4 | %p |
|
5 | 5 | %b Done! |
|
6 | 6 | Here's a new password list. |
|
7 | 7 | Go back to |
|
8 | 8 | = (link_to '[user list]', :action => 'index') + '.' |
|
9 | 9 | %br/ |
|
10 | 10 | %table |
|
11 | 11 | %tr |
|
12 | 12 | %th Login |
|
13 | 13 | %th Fullname |
|
14 | 14 | %th Password |
|
15 | 15 | -for u in @non_admin_users |
|
16 | 16 | %tr |
|
17 | 17 | %td= u.login |
|
18 | 18 | %td= u.full_name |
|
19 | 19 | %td |
|
20 | 20 | %tt= u.password |
|
21 | 21 | |
|
22 | 22 | -else |
|
23 | 23 | -if @prefix!='' |
|
24 | 24 | Current prefix: |
|
25 | 25 | = @prefix |
|
26 |
- |
|
|
26 | + = form_tag((url_for :action => 'random_all_passwords'), :method => 'get') do | |
|
27 | 27 | Change prefix |
|
28 | 28 | =text_field_tag 'prefix' |
|
29 | 29 | =submit_tag 'Change' |
|
30 | 30 | |
|
31 | 31 | This will change passwords of the following users. |
|
32 | 32 | %ul |
|
33 | 33 | -for u in @non_admin_users |
|
34 | 34 | %li= u.login |
|
35 | 35 | |
|
36 |
- |
|
|
36 | + = form_tag((url_for :action => 'random_all_passwords'), :method => 'post') do | |
|
37 | 37 | =hidden_field_tag 'prefix', @prefix |
|
38 | 38 | Are you sure? |
|
39 | 39 | =submit_tag 'Go ahead' |
You need to be logged in to leave comments.
Login now