Description:
use uuid cookie
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r852:41c96ab8e589 - - 3 files changed: 20 inserted, 2 deleted
@@ -1,13 +1,15 | |||||
|
1 | require 'ipaddr' |
|
1 | require 'ipaddr' |
|
|
2 | + require "securerandom" | ||
|
2 |
|
3 | ||
|
3 | class ApplicationController < ActionController::Base |
|
4 | class ApplicationController < ActionController::Base |
|
4 | protect_from_forgery |
|
5 | protect_from_forgery |
|
5 |
|
6 | ||
|
6 | before_action :current_user |
|
7 | before_action :current_user |
|
7 | before_action :nav_announcement |
|
8 | before_action :nav_announcement |
|
|
9 | + before_action :unique_visitor_id | ||
|
8 |
|
10 | ||
|
9 | SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode' |
|
11 | SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode' |
|
10 | MULTIPLE_IP_LOGIN_CONF_KEY = 'right.multiple_ip_login' |
|
12 | MULTIPLE_IP_LOGIN_CONF_KEY = 'right.multiple_ip_login' |
|
11 | WHITELIST_IGNORE_CONF_KEY = 'right.whitelist_ignore' |
|
13 | WHITELIST_IGNORE_CONF_KEY = 'right.whitelist_ignore' |
|
12 | WHITELIST_IP_CONF_KEY = 'right.whitelist_ip' |
|
14 | WHITELIST_IP_CONF_KEY = 'right.whitelist_ip' |
|
13 |
|
15 | ||
@@ -51,12 +53,18 | |||||
|
51 | return true |
|
53 | return true |
|
52 | end |
|
54 | end |
|
53 |
|
55 | ||
|
54 | unauthorized_redirect unless GraderConfiguration["right.view_testcase"] |
|
56 | unauthorized_redirect unless GraderConfiguration["right.view_testcase"] |
|
55 | end |
|
57 | end |
|
56 |
|
58 | ||
|
|
59 | + def unique_visitor_id | ||
|
|
60 | + unless cookies[:uuid] | ||
|
|
61 | + value = SecureRandom.uuid | ||
|
|
62 | + cookies[:uuid] = { value: value, expires: 20.year } | ||
|
|
63 | + end | ||
|
|
64 | + end | ||
|
57 |
|
65 | ||
|
58 | protected |
|
66 | protected |
|
59 |
|
67 | ||
|
60 | #redirect to root (and also force logout) |
|
68 | #redirect to root (and also force logout) |
|
61 | #if the user is not logged_in or the system is in "ADMIN ONLY" mode |
|
69 | #if the user is not logged_in or the system is in "ADMIN ONLY" mode |
|
62 | def check_valid_login |
|
70 | def check_valid_login |
@@ -19,12 +19,22 | |||||
|
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 | ||
|
|
26 | + if user.last_ip.nil? | ||
|
|
27 | + user.last_ip = cookies[:uuid] | ||
|
|
28 | + else | ||
|
|
29 | + if user.last_ip != cookies[:uuid] | ||
|
|
30 | + user.last_ip =cookies[:uuid] | ||
|
|
31 | + #log different login | ||
|
|
32 | + end | ||
|
|
33 | + end | ||
|
|
34 | + | ||
|
25 | #process logging in |
|
35 | #process logging in |
|
26 | session[:user_id] = user.id |
|
36 | session[:user_id] = user.id |
|
27 | session[:admin] = user.admin? |
|
37 | session[:admin] = user.admin? |
|
28 |
|
38 | ||
|
29 | # clear forced logout flag for multicontests contest change |
|
39 | # clear forced logout flag for multicontests contest change |
|
30 | if GraderConfiguration.multicontests? |
|
40 | if GraderConfiguration.multicontests? |
@@ -35,13 +45,13 | |||||
|
35 | contest_stat.save |
|
45 | contest_stat.save |
|
36 | end |
|
46 | end |
|
37 | end |
|
47 | end |
|
38 | end |
|
48 | end |
|
39 |
|
49 | ||
|
40 | #save login information |
|
50 | #save login information |
|
41 |
- Login.create(user_id: user.id, ip_address: |
|
51 | + Login.create(user_id: user.id, ip_address: cookies[:uuid]) |
|
42 |
|
52 | ||
|
43 | redirect_to :controller => 'main', :action => 'list' |
|
53 | redirect_to :controller => 'main', :action => 'list' |
|
44 | end |
|
54 | end |
|
45 |
|
55 | ||
|
46 | def site_login |
|
56 | def site_login |
|
47 | begin |
|
57 | begin |
@@ -37,13 +37,13 | |||||
|
37 | validates_uniqueness_of :login |
|
37 | validates_uniqueness_of :login |
|
38 | validates_format_of :login, :with => /\A[\_A-Za-z0-9]+\z/ |
|
38 | validates_format_of :login, :with => /\A[\_A-Za-z0-9]+\z/ |
|
39 | validates_length_of :login, :within => 3..30 |
|
39 | validates_length_of :login, :within => 3..30 |
|
40 |
|
40 | ||
|
41 | validates_presence_of :full_name |
|
41 | validates_presence_of :full_name |
|
42 | validates_length_of :full_name, :minimum => 1 |
|
42 | validates_length_of :full_name, :minimum => 1 |
|
43 | - |
|
43 | + |
|
44 | validates_presence_of :password, :if => :password_required? |
|
44 | validates_presence_of :password, :if => :password_required? |
|
45 | validates_length_of :password, :within => 4..50, :if => :password_required? |
|
45 | validates_length_of :password, :within => 4..50, :if => :password_required? |
|
46 | validates_confirmation_of :password, :if => :password_required? |
|
46 | validates_confirmation_of :password, :if => :password_required? |
|
47 |
|
47 | ||
|
48 | validates_format_of :email, |
|
48 | validates_format_of :email, |
|
49 | :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, |
|
49 | :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, |
You need to be logged in to leave comments.
Login now