Description:
change to encrypted cookies
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r853:da84d756f1f9 - - 2 files changed: 8 inserted, 6 deleted
@@ -48,28 +48,30 | |||||
|
48 | end |
|
48 | end |
|
49 |
|
49 | ||
|
50 | def testcase_authorization |
|
50 | def testcase_authorization |
|
51 | #admin always has privileged |
|
51 | #admin always has privileged |
|
52 | if @current_user.admin? |
|
52 | if @current_user.admin? |
|
53 | return true |
|
53 | return true |
|
54 | end |
|
54 | end |
|
55 |
|
55 | ||
|
56 | unauthorized_redirect unless GraderConfiguration["right.view_testcase"] |
|
56 | unauthorized_redirect unless GraderConfiguration["right.view_testcase"] |
|
57 | end |
|
57 | end |
|
58 |
|
58 | ||
|
59 | def unique_visitor_id |
|
59 | def unique_visitor_id |
|
60 | - unless cookies[:uuid] |
|
60 | + unless cookies.encrypted[:uuid] |
|
61 | value = SecureRandom.uuid |
|
61 | value = SecureRandom.uuid |
|
62 | - cookies[:uuid] = { value: value, expires: 20.year } |
|
62 | + cookies.encrypted[:uuid] = { value: value, expires: 20.year } |
|
63 | end |
|
63 | end |
|
|
64 | + puts "encrypt " + cookies.encrypted[:uuid] | ||
|
|
65 | + puts cookies[:uuid] | ||
|
64 | end |
|
66 | end |
|
65 |
|
67 | ||
|
66 | protected |
|
68 | protected |
|
67 |
|
69 | ||
|
68 | #redirect to root (and also force logout) |
|
70 | #redirect to root (and also force logout) |
|
69 | #if the user is not logged_in or the system is in "ADMIN ONLY" mode |
|
71 | #if the user is not logged_in or the system is in "ADMIN ONLY" mode |
|
70 | def check_valid_login |
|
72 | def check_valid_login |
|
71 | #check if logged in |
|
73 | #check if logged in |
|
72 | unless session[:user_id] |
|
74 | unless session[:user_id] |
|
73 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
75 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
74 | unauthorized_redirect('You need to login but you cannot log in at this time') |
|
76 | unauthorized_redirect('You need to login but you cannot log in at this time') |
|
75 | else |
|
77 | else |
@@ -15,49 +15,49 | |||||
|
15 | redirect_to :controller => 'main', :action => 'login' |
|
15 | redirect_to :controller => 'main', :action => 'login' |
|
16 | return |
|
16 | return |
|
17 | end |
|
17 | end |
|
18 |
|
18 | ||
|
19 | if (!GraderConfiguration['right.bypass_agreement']) and (!params[:accept_agree]) and !user.admin? |
|
19 | if (!GraderConfiguration['right.bypass_agreement']) and (!params[:accept_agree]) and !user.admin? |
|
20 | flash[:notice] = 'You must accept the agreement before logging in' |
|
20 | flash[:notice] = 'You must accept the agreement before logging in' |
|
21 | redirect_to :controller => 'main', :action => 'login' |
|
21 | redirect_to :controller => 'main', :action => 'login' |
|
22 | return |
|
22 | return |
|
23 | end |
|
23 | end |
|
24 |
|
24 | ||
|
25 | #store uuid when login |
|
25 | #store uuid when login |
|
26 | if user.last_ip.nil? |
|
26 | if user.last_ip.nil? |
|
27 | - user.last_ip = cookies[:uuid] |
|
27 | + user.last_ip = cookies.encrypted[:uuid] |
|
28 | else |
|
28 | else |
|
29 | - if user.last_ip != cookies[:uuid] |
|
29 | + if user.last_ip != cookies.encrypted[:uuid] |
|
30 | - user.last_ip =cookies[:uuid] |
|
30 | + user.last_ip =cookies.encrypted[:uuid] |
|
31 | #log different login |
|
31 | #log different login |
|
32 | end |
|
32 | end |
|
33 | end |
|
33 | end |
|
34 |
|
34 | ||
|
35 | #process logging in |
|
35 | #process logging in |
|
36 | session[:user_id] = user.id |
|
36 | session[:user_id] = user.id |
|
37 | session[:admin] = user.admin? |
|
37 | session[:admin] = user.admin? |
|
38 |
|
38 | ||
|
39 | # clear forced logout flag for multicontests contest change |
|
39 | # clear forced logout flag for multicontests contest change |
|
40 | if GraderConfiguration.multicontests? |
|
40 | if GraderConfiguration.multicontests? |
|
41 | contest_stat = user.contest_stat |
|
41 | contest_stat = user.contest_stat |
|
42 | if contest_stat.respond_to? :forced_logout |
|
42 | if contest_stat.respond_to? :forced_logout |
|
43 | if contest_stat.forced_logout |
|
43 | if contest_stat.forced_logout |
|
44 | contest_stat.forced_logout = false |
|
44 | contest_stat.forced_logout = false |
|
45 | contest_stat.save |
|
45 | contest_stat.save |
|
46 | end |
|
46 | end |
|
47 | end |
|
47 | end |
|
48 | end |
|
48 | end |
|
49 |
|
49 | ||
|
50 | #save login information |
|
50 | #save login information |
|
51 | - Login.create(user_id: user.id, ip_address: cookies[:uuid]) |
|
51 | + Login.create(user_id: user.id, ip_address: cookies.encrypted[:uuid]) |
|
52 |
|
52 | ||
|
53 | redirect_to :controller => 'main', :action => 'list' |
|
53 | redirect_to :controller => 'main', :action => 'list' |
|
54 | end |
|
54 | end |
|
55 |
|
55 | ||
|
56 | def site_login |
|
56 | def site_login |
|
57 | begin |
|
57 | begin |
|
58 | site = Site.find(params[:login][:site_id]) |
|
58 | site = Site.find(params[:login][:site_id]) |
|
59 | rescue ActiveRecord::RecordNotFound |
|
59 | rescue ActiveRecord::RecordNotFound |
|
60 | site = nil |
|
60 | site = nil |
|
61 | end |
|
61 | end |
|
62 | if site==nil |
|
62 | if site==nil |
|
63 | flash[:notice] = 'Wrong site' |
|
63 | flash[:notice] = 'Wrong site' |
You need to be logged in to leave comments.
Login now