Description:
add enabled option for user
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r670:f90ec3934e15 - - 1 file changed: 11 inserted, 13 deleted
@@ -18,91 +18,89 | |||
|
18 | 18 | @current_user ||= User.find(session[:user_id]) |
|
19 | 19 | end |
|
20 | 20 | |
|
21 | 21 | def admin_authorization |
|
22 | 22 | return false unless authenticate |
|
23 | 23 | user = User.includes(:roles).find(session[:user_id]) |
|
24 | 24 | unless user.admin? |
|
25 | 25 | unauthorized_redirect |
|
26 | 26 | return false |
|
27 | 27 | end |
|
28 | 28 | return true |
|
29 | 29 | end |
|
30 | 30 | |
|
31 | 31 | def authorization_by_roles(allowed_roles) |
|
32 | 32 | return false unless authenticate |
|
33 | 33 | user = User.find(session[:user_id]) |
|
34 | 34 | unless user.roles.detect { |role| allowed_roles.member?(role.name) } |
|
35 | 35 | unauthorized_redirect |
|
36 | 36 | return false |
|
37 | 37 | end |
|
38 | 38 | end |
|
39 | 39 | |
|
40 | 40 | def testcase_authorization |
|
41 | 41 | #admin always has privileged |
|
42 | - puts "haha" | |
|
43 | 42 | if @current_user.admin? |
|
44 | 43 | return true |
|
45 | 44 | end |
|
46 | 45 | |
|
47 | - puts "hehe" | |
|
48 | - puts GraderConfiguration["right.view_testcase"] | |
|
49 | 46 | unauthorized_redirect unless GraderConfiguration["right.view_testcase"] |
|
50 | 47 | end |
|
51 | 48 | |
|
52 | 49 | protected |
|
53 | 50 | |
|
54 | 51 | def authenticate |
|
55 | 52 | unless session[:user_id] |
|
56 | 53 | flash[:notice] = 'You need to login' |
|
57 | 54 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
58 | 55 | flash[:notice] = 'You need to login but you cannot log in at this time' |
|
59 | 56 | end |
|
60 | 57 | redirect_to :controller => 'main', :action => 'login' |
|
61 | 58 | return false |
|
62 | 59 | end |
|
63 | 60 | |
|
61 | + | |
|
64 | 62 | # check if run in single user mode |
|
65 | 63 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
66 | - user = User.find_by_id(session[:user_id]) | |
|
67 | - if user==nil or (not user.admin?) | |
|
64 | + if @current_user==nil or (not @current_user.admin?) | |
|
68 | 65 | flash[:notice] = 'You cannot log in at this time' |
|
69 | 66 | redirect_to :controller => 'main', :action => 'login' |
|
70 | 67 | return false |
|
71 | 68 | end |
|
72 | - unless user.enabled? | |
|
73 | - flash[:notice] = 'Your account is disabled' | |
|
74 | - redirect_to :controller => 'main', :action => 'login' | |
|
75 | - return false | |
|
76 | - end | |
|
77 | 69 | return true |
|
78 | 70 | end |
|
79 | 71 | |
|
72 | + # check if the user is enabled | |
|
73 | + unless @current_user.enabled? or @current_user.admin? | |
|
74 | + flash[:notice] = 'Your account is disabled' | |
|
75 | + redirect_to :controller => 'main', :action => 'login' | |
|
76 | + return false | |
|
77 | + end | |
|
78 | + | |
|
80 | 79 | if GraderConfiguration.multicontests? |
|
81 | - user = User.find(session[:user_id]) | |
|
82 | - return true if user.admin? | |
|
80 | + return true if @current_user.admin? | |
|
83 | 81 | begin |
|
84 | - if user.contest_stat(true).forced_logout | |
|
82 | + if @current_user.contest_stat(true).forced_logout | |
|
85 | 83 | flash[:notice] = 'You have been automatically logged out.' |
|
86 | 84 | redirect_to :controller => 'main', :action => 'index' |
|
87 | 85 | end |
|
88 | 86 | rescue |
|
89 | 87 | end |
|
90 | 88 | end |
|
91 | 89 | return true |
|
92 | 90 | end |
|
93 | 91 | |
|
94 | 92 | def authenticate_by_ip_address |
|
95 | 93 | #this assume that we have already authenticate normally |
|
96 | 94 | unless GraderConfiguration[MULTIPLE_IP_LOGIN_CONF_KEY] |
|
97 | 95 | user = User.find(session[:user_id]) |
|
98 | 96 | if (not user.admin? and user.last_ip and user.last_ip != request.remote_ip) |
|
99 | 97 | flash[:notice] = "You cannot use the system from #{request.remote_ip}. Your last ip is #{user.last_ip}" |
|
100 | 98 | redirect_to :controller => 'main', :action => 'login' |
|
101 | 99 | puts "CHEAT: user #{user.login} tried to login from '#{request.remote_ip}' while last ip is '#{user.last_ip}' at #{Time.zone.now}" |
|
102 | 100 | return false |
|
103 | 101 | end |
|
104 | 102 | unless user.last_ip |
|
105 | 103 | user.last_ip = request.remote_ip |
|
106 | 104 | user.save |
|
107 | 105 | end |
|
108 | 106 | end |
You need to be logged in to leave comments.
Login now