Description:
NEED TESTING
move to stronger parameter for xxx.new(params[
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r637:d56b2e7de528 - - 4 files changed: 9 inserted, 5 deleted
@@ -24,49 +24,49 | |||||
|
24 | format.html # show.html.erb |
|
24 | format.html # show.html.erb |
|
25 | format.xml { render :xml => @announcement } |
|
25 | format.xml { render :xml => @announcement } |
|
26 | end |
|
26 | end |
|
27 | end |
|
27 | end |
|
28 |
|
28 | ||
|
29 | # GET /announcements/new |
|
29 | # GET /announcements/new |
|
30 | # GET /announcements/new.xml |
|
30 | # GET /announcements/new.xml |
|
31 | def new |
|
31 | def new |
|
32 | @announcement = Announcement.new |
|
32 | @announcement = Announcement.new |
|
33 |
|
33 | ||
|
34 | respond_to do |format| |
|
34 | respond_to do |format| |
|
35 | format.html # new.html.erb |
|
35 | format.html # new.html.erb |
|
36 | format.xml { render :xml => @announcement } |
|
36 | format.xml { render :xml => @announcement } |
|
37 | end |
|
37 | end |
|
38 | end |
|
38 | end |
|
39 |
|
39 | ||
|
40 | # GET /announcements/1/edit |
|
40 | # GET /announcements/1/edit |
|
41 | def edit |
|
41 | def edit |
|
42 | @announcement = Announcement.find(params[:id]) |
|
42 | @announcement = Announcement.find(params[:id]) |
|
43 | end |
|
43 | end |
|
44 |
|
44 | ||
|
45 | # POST /announcements |
|
45 | # POST /announcements |
|
46 | # POST /announcements.xml |
|
46 | # POST /announcements.xml |
|
47 | def create |
|
47 | def create |
|
48 |
- @announcement = Announcement.new( |
|
48 | + @announcement = Announcement.new(announcement_params) |
|
49 |
|
49 | ||
|
50 | respond_to do |format| |
|
50 | respond_to do |format| |
|
51 | if @announcement.save |
|
51 | if @announcement.save |
|
52 | flash[:notice] = 'Announcement was successfully created.' |
|
52 | flash[:notice] = 'Announcement was successfully created.' |
|
53 | format.html { redirect_to(@announcement) } |
|
53 | format.html { redirect_to(@announcement) } |
|
54 | format.xml { render :xml => @announcement, :status => :created, :location => @announcement } |
|
54 | format.xml { render :xml => @announcement, :status => :created, :location => @announcement } |
|
55 | else |
|
55 | else |
|
56 | format.html { render :action => "new" } |
|
56 | format.html { render :action => "new" } |
|
57 | format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity } |
|
57 | format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity } |
|
58 | end |
|
58 | end |
|
59 | end |
|
59 | end |
|
60 | end |
|
60 | end |
|
61 |
|
61 | ||
|
62 | # PUT /announcements/1 |
|
62 | # PUT /announcements/1 |
|
63 | # PUT /announcements/1.xml |
|
63 | # PUT /announcements/1.xml |
|
64 | def update |
|
64 | def update |
|
65 | @announcement = Announcement.find(params[:id]) |
|
65 | @announcement = Announcement.find(params[:id]) |
|
66 |
|
66 | ||
|
67 | respond_to do |format| |
|
67 | respond_to do |format| |
|
68 | if @announcement.update_attributes(announcement_params) |
|
68 | if @announcement.update_attributes(announcement_params) |
|
69 | flash[:notice] = 'Announcement was successfully updated.' |
|
69 | flash[:notice] = 'Announcement was successfully updated.' |
|
70 | format.html { redirect_to(@announcement) } |
|
70 | format.html { redirect_to(@announcement) } |
|
71 | format.js {} |
|
71 | format.js {} |
|
72 | format.xml { head :ok } |
|
72 | format.xml { head :ok } |
@@ -7,68 +7,68 | |||||
|
7 | in_place_edit_for :problem, :full_name |
|
7 | in_place_edit_for :problem, :full_name |
|
8 | in_place_edit_for :problem, :full_score |
|
8 | in_place_edit_for :problem, :full_score |
|
9 |
|
9 | ||
|
10 | def index |
|
10 | def index |
|
11 | @problems = Problem.order(date_added: :desc) |
|
11 | @problems = Problem.order(date_added: :desc) |
|
12 | end |
|
12 | end |
|
13 |
|
13 | ||
|
14 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
14 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
15 | verify :method => :post, :only => [ :create, :quick_create, |
|
15 | verify :method => :post, :only => [ :create, :quick_create, |
|
16 | :do_manage, |
|
16 | :do_manage, |
|
17 | :do_import, |
|
17 | :do_import, |
|
18 | ], |
|
18 | ], |
|
19 | :redirect_to => { :action => :index } |
|
19 | :redirect_to => { :action => :index } |
|
20 |
|
20 | ||
|
21 | def show |
|
21 | def show |
|
22 | @problem = Problem.find(params[:id]) |
|
22 | @problem = Problem.find(params[:id]) |
|
23 | end |
|
23 | end |
|
24 |
|
24 | ||
|
25 | def new |
|
25 | def new |
|
26 | @problem = Problem.new |
|
26 | @problem = Problem.new |
|
27 | @description = nil |
|
27 | @description = nil |
|
28 | end |
|
28 | end |
|
29 |
|
29 | ||
|
30 | def create |
|
30 | def create |
|
31 |
- @problem = Problem.new( |
|
31 | + @problem = Problem.new(problem_params) |
|
32 | @description = Description.new(params[:description]) |
|
32 | @description = Description.new(params[:description]) |
|
33 | if @description.body!='' |
|
33 | if @description.body!='' |
|
34 | if !@description.save |
|
34 | if !@description.save |
|
35 | render :action => new and return |
|
35 | render :action => new and return |
|
36 | end |
|
36 | end |
|
37 | else |
|
37 | else |
|
38 | @description = nil |
|
38 | @description = nil |
|
39 | end |
|
39 | end |
|
40 | @problem.description = @description |
|
40 | @problem.description = @description |
|
41 | if @problem.save |
|
41 | if @problem.save |
|
42 | flash[:notice] = 'Problem was successfully created.' |
|
42 | flash[:notice] = 'Problem was successfully created.' |
|
43 | redirect_to action: :index |
|
43 | redirect_to action: :index |
|
44 | else |
|
44 | else |
|
45 | render :action => 'new' |
|
45 | render :action => 'new' |
|
46 | end |
|
46 | end |
|
47 | end |
|
47 | end |
|
48 |
|
48 | ||
|
49 | def quick_create |
|
49 | def quick_create |
|
50 |
- @problem = Problem.new( |
|
50 | + @problem = Problem.new(problem_params) |
|
51 | @problem.full_name = @problem.name if @problem.full_name == '' |
|
51 | @problem.full_name = @problem.name if @problem.full_name == '' |
|
52 | @problem.full_score = 100 |
|
52 | @problem.full_score = 100 |
|
53 | @problem.available = false |
|
53 | @problem.available = false |
|
54 | @problem.test_allowed = true |
|
54 | @problem.test_allowed = true |
|
55 | @problem.output_only = false |
|
55 | @problem.output_only = false |
|
56 | @problem.date_added = Time.new |
|
56 | @problem.date_added = Time.new |
|
57 | if @problem.save |
|
57 | if @problem.save |
|
58 | flash[:notice] = 'Problem was successfully created.' |
|
58 | flash[:notice] = 'Problem was successfully created.' |
|
59 | redirect_to action: :index |
|
59 | redirect_to action: :index |
|
60 | else |
|
60 | else |
|
61 | flash[:notice] = 'Error saving problem' |
|
61 | flash[:notice] = 'Error saving problem' |
|
62 | redirect_to action: :index |
|
62 | redirect_to action: :index |
|
63 | end |
|
63 | end |
|
64 | end |
|
64 | end |
|
65 |
|
65 | ||
|
66 | def edit |
|
66 | def edit |
|
67 | @problem = Problem.find(params[:id]) |
|
67 | @problem = Problem.find(params[:id]) |
|
68 | @description = @problem.description |
|
68 | @description = @problem.description |
|
69 | end |
|
69 | end |
|
70 |
|
70 | ||
|
71 | def update |
|
71 | def update |
|
72 | @problem = Problem.find(params[:id]) |
|
72 | @problem = Problem.find(params[:id]) |
|
73 | @description = @problem.description |
|
73 | @description = @problem.description |
|
74 | if @description.nil? and params[:description][:body]!='' |
|
74 | if @description.nil? and params[:description][:body]!='' |
@@ -26,49 +26,49 | |||||
|
26 | end |
|
26 | end |
|
27 | @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at'] |
|
27 | @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at'] |
|
28 | @contests = Contest.enabled |
|
28 | @contests = Contest.enabled |
|
29 | end |
|
29 | end |
|
30 |
|
30 | ||
|
31 | def active |
|
31 | def active |
|
32 | sessions = ActiveRecord::SessionStore::Session.where("updated_at >= ?", 60.minutes.ago) |
|
32 | sessions = ActiveRecord::SessionStore::Session.where("updated_at >= ?", 60.minutes.ago) |
|
33 | @users = [] |
|
33 | @users = [] |
|
34 | sessions.each do |session| |
|
34 | sessions.each do |session| |
|
35 | if session.data[:user_id] |
|
35 | if session.data[:user_id] |
|
36 | @users << User.find(session.data[:user_id]) |
|
36 | @users << User.find(session.data[:user_id]) |
|
37 | end |
|
37 | end |
|
38 | end |
|
38 | end |
|
39 | end |
|
39 | end |
|
40 |
|
40 | ||
|
41 | def show |
|
41 | def show |
|
42 | @user = User.find(params[:id]) |
|
42 | @user = User.find(params[:id]) |
|
43 | end |
|
43 | end |
|
44 |
|
44 | ||
|
45 | def new |
|
45 | def new |
|
46 | @user = User.new |
|
46 | @user = User.new |
|
47 | end |
|
47 | end |
|
48 |
|
48 | ||
|
49 | def create |
|
49 | def create |
|
50 |
- @user = User.new(params |
|
50 | + @user = User.new(user_params) |
|
51 | @user.activated = true |
|
51 | @user.activated = true |
|
52 | if @user.save |
|
52 | if @user.save |
|
53 | flash[:notice] = 'User was successfully created.' |
|
53 | flash[:notice] = 'User was successfully created.' |
|
54 | redirect_to :action => 'index' |
|
54 | redirect_to :action => 'index' |
|
55 | else |
|
55 | else |
|
56 | render :action => 'new' |
|
56 | render :action => 'new' |
|
57 | end |
|
57 | end |
|
58 | end |
|
58 | end |
|
59 |
|
59 | ||
|
60 | def clear_last_ip |
|
60 | def clear_last_ip |
|
61 | @user = User.find(params[:id]) |
|
61 | @user = User.find(params[:id]) |
|
62 | @user.last_ip = nil |
|
62 | @user.last_ip = nil |
|
63 | @user.save |
|
63 | @user.save |
|
64 | redirect_to action: 'index', page: params[:page] |
|
64 | redirect_to action: 'index', page: params[:page] |
|
65 | end |
|
65 | end |
|
66 |
|
66 | ||
|
67 | def create_from_list |
|
67 | def create_from_list |
|
68 | lines = params[:user_list] |
|
68 | lines = params[:user_list] |
|
69 |
|
69 | ||
|
70 | note = [] |
|
70 | note = [] |
|
71 |
|
71 | ||
|
72 | lines.split("\n").each do |line| |
|
72 | lines.split("\n").each do |line| |
|
73 | items = line.chomp.split(',') |
|
73 | items = line.chomp.split(',') |
|
74 | if items.length>=2 |
|
74 | if items.length>=2 |
@@ -31,49 +31,49 | |||||
|
31 | end |
|
31 | end |
|
32 |
|
32 | ||
|
33 | def chg_passwd |
|
33 | def chg_passwd |
|
34 | user = User.find(session[:user_id]) |
|
34 | user = User.find(session[:user_id]) |
|
35 | user.password = params[:passwd] |
|
35 | user.password = params[:passwd] |
|
36 | user.password_confirmation = params[:passwd_verify] |
|
36 | user.password_confirmation = params[:passwd_verify] |
|
37 | if user.save |
|
37 | if user.save |
|
38 | flash[:notice] = 'password changed' |
|
38 | flash[:notice] = 'password changed' |
|
39 | else |
|
39 | else |
|
40 | flash[:notice] = 'Error: password changing failed' |
|
40 | flash[:notice] = 'Error: password changing failed' |
|
41 | end |
|
41 | end |
|
42 | redirect_to :action => 'index' |
|
42 | redirect_to :action => 'index' |
|
43 | end |
|
43 | end |
|
44 |
|
44 | ||
|
45 | def new |
|
45 | def new |
|
46 | @user = User.new |
|
46 | @user = User.new |
|
47 | render :action => 'new', :layout => 'empty' |
|
47 | render :action => 'new', :layout => 'empty' |
|
48 | end |
|
48 | end |
|
49 |
|
49 | ||
|
50 | def register |
|
50 | def register |
|
51 | if(params[:cancel]) |
|
51 | if(params[:cancel]) |
|
52 | redirect_to :controller => 'main', :action => 'login' |
|
52 | redirect_to :controller => 'main', :action => 'login' |
|
53 | return |
|
53 | return |
|
54 | end |
|
54 | end |
|
55 |
- @user = User.new(params |
|
55 | + @user = User.new(user_params) |
|
56 | @user.password_confirmation = @user.password = User.random_password |
|
56 | @user.password_confirmation = @user.password = User.random_password |
|
57 | @user.activated = false |
|
57 | @user.activated = false |
|
58 | if (@user.valid?) and (@user.save) |
|
58 | if (@user.valid?) and (@user.save) |
|
59 | if send_confirmation_email(@user) |
|
59 | if send_confirmation_email(@user) |
|
60 | render :action => 'new_splash', :layout => 'empty' |
|
60 | render :action => 'new_splash', :layout => 'empty' |
|
61 | else |
|
61 | else |
|
62 | @admin_email = GraderConfiguration['system.admin_email'] |
|
62 | @admin_email = GraderConfiguration['system.admin_email'] |
|
63 | render :action => 'email_error', :layout => 'empty' |
|
63 | render :action => 'email_error', :layout => 'empty' |
|
64 | end |
|
64 | end |
|
65 | else |
|
65 | else |
|
66 | @user.errors.add(:base,"Email cannot be blank") if @user.email=='' |
|
66 | @user.errors.add(:base,"Email cannot be blank") if @user.email=='' |
|
67 | render :action => 'new', :layout => 'empty' |
|
67 | render :action => 'new', :layout => 'empty' |
|
68 | end |
|
68 | end |
|
69 | end |
|
69 | end |
|
70 |
|
70 | ||
|
71 | def confirm |
|
71 | def confirm |
|
72 | login = params[:login] |
|
72 | login = params[:login] |
|
73 | key = params[:activation] |
|
73 | key = params[:activation] |
|
74 | @user = User.find_by_login(login) |
|
74 | @user = User.find_by_login(login) |
|
75 | if (@user) and (@user.verify_activation_key(key)) |
|
75 | if (@user) and (@user.verify_activation_key(key)) |
|
76 | if @user.valid? # check uniquenss of email |
|
76 | if @user.valid? # check uniquenss of email |
|
77 | @user.activated = true |
|
77 | @user.activated = true |
|
78 | @user.save |
|
78 | @user.save |
|
79 | @result = :successful |
|
79 | @result = :successful |
@@ -189,26 +189,30 | |||||
|
189 | :login => user.login, |
|
189 | :login => user.login, |
|
190 | :password => user.password, |
|
190 | :password => user.password, |
|
191 | :admin_email => GraderConfiguration['system.admin_email'] |
|
191 | :admin_email => GraderConfiguration['system.admin_email'] |
|
192 | }) |
|
192 | }) |
|
193 |
|
193 | ||
|
194 | logger.info mail_body |
|
194 | logger.info mail_body |
|
195 |
|
195 | ||
|
196 | send_mail(user.email, mail_subject, mail_body) |
|
196 | send_mail(user.email, mail_subject, mail_body) |
|
197 | end |
|
197 | end |
|
198 |
|
198 | ||
|
199 | # allow viewing of regular user profile only when options allow so |
|
199 | # allow viewing of regular user profile only when options allow so |
|
200 | # only admins can view admins profile |
|
200 | # only admins can view admins profile |
|
201 | def profile_authorization |
|
201 | def profile_authorization |
|
202 | #if view admins' profile, allow only admin |
|
202 | #if view admins' profile, allow only admin |
|
203 | return false unless(params[:id]) |
|
203 | return false unless(params[:id]) |
|
204 | user = User.find(params[:id]) |
|
204 | user = User.find(params[:id]) |
|
205 | return false unless user |
|
205 | return false unless user |
|
206 | return admin_authorization if user.admin? |
|
206 | return admin_authorization if user.admin? |
|
207 | return true if GraderConfiguration["right.user_view_submission"] |
|
207 | return true if GraderConfiguration["right.user_view_submission"] |
|
208 |
|
208 | ||
|
209 | #finally, we allow only admin |
|
209 | #finally, we allow only admin |
|
210 | admin_authorization |
|
210 | admin_authorization |
|
211 | end |
|
211 | end |
|
212 |
|
212 | ||
|
|
213 | + private | ||
|
|
214 | + def user_params | ||
|
|
215 | + params.require(:user).permit(:login, :full_name, :email) | ||
|
|
216 | + end | ||
|
213 |
|
217 | ||
|
214 | end |
|
218 | end |
You need to be logged in to leave comments.
Login now