Description:
add option to disable login from multiple ip
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r525:89e2deff986b - - 6 files changed: 59 inserted, 27 deleted
@@ -2,6 +2,7 | |||||
|
2 | protect_from_forgery |
|
2 | protect_from_forgery |
|
3 |
|
3 | ||
|
4 | SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode' |
|
4 | SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode' |
|
|
5 | + MULTIPLE_IP_LOGIN_CONF_KEY = 'right.multiple_ip_login' | ||
|
5 |
|
6 | ||
|
6 | def admin_authorization |
|
7 | def admin_authorization |
|
7 | return false unless authenticate |
|
8 | return false unless authenticate |
@@ -61,6 +62,23 | |||||
|
61 | return true |
|
62 | return true |
|
62 | end |
|
63 | end |
|
63 |
|
64 | ||
|
|
65 | + def authenticate_by_ip_address | ||
|
|
66 | + #this assume that we have already authenticate normally | ||
|
|
67 | + unless GraderConfiguration[MULTIPLE_IP_LOGIN_CONF_KEY] | ||
|
|
68 | + user = User.find(session[:user_id]) | ||
|
|
69 | + if (not user.admin? and user.last_ip and user.last_ip != request.remote_ip) | ||
|
|
70 | + flash[:notice] = "You cannot use the system from #{request.remote_ip}. Your last ip is #{user.last_ip}" | ||
|
|
71 | + redirect_to :controller => 'main', :action => 'login' | ||
|
|
72 | + return false | ||
|
|
73 | + end | ||
|
|
74 | + unless user.last_ip | ||
|
|
75 | + user.last_ip = request.remote_ip | ||
|
|
76 | + user.save | ||
|
|
77 | + end | ||
|
|
78 | + end | ||
|
|
79 | + return true | ||
|
|
80 | + end | ||
|
|
81 | + | ||
|
64 | def authorization |
|
82 | def authorization |
|
65 | return false unless authenticate |
|
83 | return false unless authenticate |
|
66 | user = User.find(session[:user_id]) |
|
84 | user = User.find(session[:user_id]) |
@@ -16,6 +16,7 | |||||
|
16 |
|
16 | ||
|
17 | def update |
|
17 | def update |
|
18 | @config = GraderConfiguration.find(params[:id]) |
|
18 | @config = GraderConfiguration.find(params[:id]) |
|
|
19 | + User.clear_last_login if @config.key = 'multiple_ip_login' and @config.value == 'true' and params[:grader_configuration][:value] == 'false' | ||
|
19 | respond_to do |format| |
|
20 | respond_to do |format| |
|
20 | if @config.update_attributes(params[:grader_configuration]) |
|
21 | if @config.update_attributes(params[:grader_configuration]) |
|
21 | format.json { head :ok } |
|
22 | format.json { head :ok } |
@@ -13,6 +13,8 | |||||
|
13 | prepend_before_filter :reject_announcement_refresh_when_logged_out, |
|
13 | prepend_before_filter :reject_announcement_refresh_when_logged_out, |
|
14 | :only => [:announcements] |
|
14 | :only => [:announcements] |
|
15 |
|
15 | ||
|
|
16 | + before_filter :authenticate_by_ip_address, :only => [:list] | ||
|
|
17 | + | ||
|
16 | # COMMENTED OUT: filter in each action instead |
|
18 | # COMMENTED OUT: filter in each action instead |
|
17 | # before_filter :verify_time_limit, :only => [:submit] |
|
19 | # before_filter :verify_time_limit, :only => [:submit] |
|
18 |
|
20 |
@@ -307,6 +307,10 | |||||
|
307 | end |
|
307 | end |
|
308 | end |
|
308 | end |
|
309 |
|
309 | ||
|
|
310 | + def self.clear_last_login | ||
|
|
311 | + User.update_all(:last_ip => nil) | ||
|
|
312 | + end | ||
|
|
313 | + | ||
|
310 | protected |
|
314 | protected |
|
311 | def encrypt_new_password |
|
315 | def encrypt_new_password |
|
312 | return if password.blank? |
|
316 | return if password.blank? |
@@ -11,16 +11,16 | |||||
|
11 | # |
|
11 | # |
|
12 | # It's strongly recommended to check this file into your version control system. |
|
12 | # It's strongly recommended to check this file into your version control system. |
|
13 |
|
13 | ||
|
14 |
- ActiveRecord::Schema.define(:version => 20150 |
|
14 | + ActiveRecord::Schema.define(:version => 20150618085823) do |
|
15 |
|
15 | ||
|
16 | create_table "announcements", :force => true do |t| |
|
16 | create_table "announcements", :force => true do |t| |
|
17 | t.string "author" |
|
17 | t.string "author" |
|
18 |
- t.text "body" |
|
18 | + t.text "body" |
|
19 | t.boolean "published" |
|
19 | t.boolean "published" |
|
20 |
- t.datetime "created_at", |
|
20 | + t.datetime "created_at", :null => false |
|
21 |
- t.datetime "updated_at", |
|
21 | + t.datetime "updated_at", :null => false |
|
22 |
- t.boolean "frontpage", |
|
22 | + t.boolean "frontpage", :default => false |
|
23 |
- t.boolean "contest_only", |
|
23 | + t.boolean "contest_only", :default => false |
|
24 | t.string "title" |
|
24 | t.string "title" |
|
25 | t.string "notes" |
|
25 | t.string "notes" |
|
26 | end |
|
26 | end |
@@ -50,19 +50,19 | |||||
|
50 | end |
|
50 | end |
|
51 |
|
51 | ||
|
52 | create_table "descriptions", :force => true do |t| |
|
52 | create_table "descriptions", :force => true do |t| |
|
53 |
- t.text "body" |
|
53 | + t.text "body" |
|
54 | t.boolean "markdowned" |
|
54 | t.boolean "markdowned" |
|
55 |
- t.datetime "created_at", |
|
55 | + t.datetime "created_at", :null => false |
|
56 |
- t.datetime "updated_at", |
|
56 | + t.datetime "updated_at", :null => false |
|
57 | end |
|
57 | end |
|
58 |
|
58 | ||
|
59 | create_table "grader_configurations", :force => true do |t| |
|
59 | create_table "grader_configurations", :force => true do |t| |
|
60 | t.string "key" |
|
60 | t.string "key" |
|
61 | t.string "value_type" |
|
61 | t.string "value_type" |
|
62 | t.string "value" |
|
62 | t.string "value" |
|
63 |
- t.datetime "created_at", |
|
63 | + t.datetime "created_at", :null => false |
|
64 |
- t.datetime "updated_at", |
|
64 | + t.datetime "updated_at", :null => false |
|
65 |
- t.text "description" |
|
65 | + t.text "description" |
|
66 | end |
|
66 | end |
|
67 |
|
67 | ||
|
68 | create_table "grader_processes", :force => true do |t| |
|
68 | create_table "grader_processes", :force => true do |t| |
@@ -97,10 +97,10 | |||||
|
97 | t.integer "sender_id" |
|
97 | t.integer "sender_id" |
|
98 | t.integer "receiver_id" |
|
98 | t.integer "receiver_id" |
|
99 | t.integer "replying_message_id" |
|
99 | t.integer "replying_message_id" |
|
100 | - t.text "body", :limit => 16777215 |
|
100 | + t.text "body" |
|
101 | t.boolean "replied" |
|
101 | t.boolean "replied" |
|
102 |
- t.datetime "created_at", |
|
102 | + t.datetime "created_at", :null => false |
|
103 |
- t.datetime "updated_at", |
|
103 | + t.datetime "updated_at", :null => false |
|
104 | end |
|
104 | end |
|
105 |
|
105 | ||
|
106 | create_table "problems", :force => true do |t| |
|
106 | create_table "problems", :force => true do |t| |
@@ -142,7 +142,7 | |||||
|
142 |
|
142 | ||
|
143 | create_table "sessions", :force => true do |t| |
|
143 | create_table "sessions", :force => true do |t| |
|
144 | t.string "session_id" |
|
144 | t.string "session_id" |
|
145 |
- t.text "data" |
|
145 | + t.text "data" |
|
146 | t.datetime "updated_at" |
|
146 | t.datetime "updated_at" |
|
147 | end |
|
147 | end |
|
148 |
|
148 | ||
@@ -163,14 +163,14 | |||||
|
163 | t.integer "user_id" |
|
163 | t.integer "user_id" |
|
164 | t.integer "problem_id" |
|
164 | t.integer "problem_id" |
|
165 | t.integer "language_id" |
|
165 | t.integer "language_id" |
|
166 | - t.text "source", :limit => 16777215 |
|
166 | + t.text "source" |
|
167 | t.binary "binary" |
|
167 | t.binary "binary" |
|
168 | t.datetime "submitted_at" |
|
168 | t.datetime "submitted_at" |
|
169 | t.datetime "compiled_at" |
|
169 | t.datetime "compiled_at" |
|
170 |
- t.text "compiler_message" |
|
170 | + t.text "compiler_message" |
|
171 | t.datetime "graded_at" |
|
171 | t.datetime "graded_at" |
|
172 | t.integer "points" |
|
172 | t.integer "points" |
|
173 |
- t.text "grader_comment" |
|
173 | + t.text "grader_comment" |
|
174 | t.integer "number" |
|
174 | t.integer "number" |
|
175 | t.string "source_filename" |
|
175 | t.string "source_filename" |
|
176 | t.float "max_runtime" |
|
176 | t.float "max_runtime" |
@@ -191,10 +191,10 | |||||
|
191 |
|
191 | ||
|
192 | create_table "test_pairs", :force => true do |t| |
|
192 | create_table "test_pairs", :force => true do |t| |
|
193 | t.integer "problem_id" |
|
193 | t.integer "problem_id" |
|
194 |
- t.text "input", :limit => |
|
194 | + t.text "input", :limit => 16777215 |
|
195 |
- t.text "solution", :limit => |
|
195 | + t.text "solution", :limit => 16777215 |
|
196 |
- t.datetime "created_at", |
|
196 | + t.datetime "created_at", :null => false |
|
197 |
- t.datetime "updated_at", |
|
197 | + t.datetime "updated_at", :null => false |
|
198 | end |
|
198 | end |
|
199 |
|
199 | ||
|
200 | create_table "test_requests", :force => true do |t| |
|
200 | create_table "test_requests", :force => true do |t| |
@@ -205,13 +205,13 | |||||
|
205 | t.string "output_file_name" |
|
205 | t.string "output_file_name" |
|
206 | t.string "running_stat" |
|
206 | t.string "running_stat" |
|
207 | t.integer "status" |
|
207 | t.integer "status" |
|
208 |
- t.datetime "updated_at", |
|
208 | + t.datetime "updated_at", :null => false |
|
209 | t.datetime "submitted_at" |
|
209 | t.datetime "submitted_at" |
|
210 | t.datetime "compiled_at" |
|
210 | t.datetime "compiled_at" |
|
211 |
- t.text "compiler_message" |
|
211 | + t.text "compiler_message" |
|
212 | t.datetime "graded_at" |
|
212 | t.datetime "graded_at" |
|
213 | t.string "grader_comment" |
|
213 | t.string "grader_comment" |
|
214 |
- t.datetime "created_at", |
|
214 | + t.datetime "created_at", :null => false |
|
215 | t.float "running_time" |
|
215 | t.float "running_time" |
|
216 | t.string "exit_status" |
|
216 | t.string "exit_status" |
|
217 | t.integer "memory_usage" |
|
217 | t.integer "memory_usage" |
@@ -239,9 +239,9 | |||||
|
239 | t.boolean "activated", :default => false |
|
239 | t.boolean "activated", :default => false |
|
240 | t.datetime "created_at" |
|
240 | t.datetime "created_at" |
|
241 | t.datetime "updated_at" |
|
241 | t.datetime "updated_at" |
|
242 | - t.string "section" |
|
||
|
243 | t.boolean "enabled", :default => true |
|
242 | t.boolean "enabled", :default => true |
|
244 | t.string "remark" |
|
243 | t.string "remark" |
|
|
244 | + t.string "last_ip" | ||
|
245 | end |
|
245 | end |
|
246 |
|
246 | ||
|
247 | add_index "users", ["login"], :name => "index_users_on_login", :unique => true |
|
247 | add_index "users", ["login"], :name => "index_users_on_login", :unique => true |
@@ -61,6 +61,13 | |||||
|
61 | }, |
|
61 | }, |
|
62 |
|
62 | ||
|
63 | { |
|
63 | { |
|
|
64 | + :key => 'right.multiple_ip_login', | ||
|
|
65 | + :value_type => 'boolean', | ||
|
|
66 | + :default_value => 'true', | ||
|
|
67 | + :description => 'When change from true to false, a user can login from the first IP they logged into afterward.' | ||
|
|
68 | + }, | ||
|
|
69 | + | ||
|
|
70 | + { | ||
|
64 | :key => 'right.user_view_submission', |
|
71 | :key => 'right.user_view_submission', |
|
65 | :value_type => 'boolean', |
|
72 | :value_type => 'boolean', |
|
66 | :default_value => 'false', |
|
73 | :default_value => 'false', |
You need to be logged in to leave comments.
Login now