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
r849:2290fefd2c38 - - 3 files changed: 20 inserted, 2 deleted
@@ -1,10 +1,12 | |||
|
1 | 1 | require 'ipaddr' |
|
2 | + require "securerandom" | |
|
2 | 3 | |
|
3 | 4 | class ApplicationController < ActionController::Base |
|
4 | 5 | protect_from_forgery |
|
5 | 6 | |
|
6 | 7 | before_action :current_user |
|
7 | 8 | before_action :nav_announcement |
|
9 | + before_action :unique_visitor_id | |
|
8 | 10 | |
|
9 | 11 | SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode' |
|
10 | 12 | MULTIPLE_IP_LOGIN_CONF_KEY = 'right.multiple_ip_login' |
@@ -54,6 +56,12 | |||
|
54 | 56 | unauthorized_redirect unless GraderConfiguration["right.view_testcase"] |
|
55 | 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 | 66 | protected |
|
59 | 67 |
@@ -22,6 +22,16 | |||
|
22 | 22 | return |
|
23 | 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 | 35 | #process logging in |
|
26 | 36 | session[:user_id] = user.id |
|
27 | 37 | session[:admin] = user.admin? |
@@ -38,7 +48,7 | |||
|
38 | 48 | end |
|
39 | 49 | |
|
40 | 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 | 53 | redirect_to :controller => 'main', :action => 'list' |
|
44 | 54 | end |
@@ -40,7 +40,7 | |||
|
40 | 40 | |
|
41 | 41 | validates_presence_of :full_name |
|
42 | 42 | validates_length_of :full_name, :minimum => 1 |
|
43 | - | |
|
43 | + | |
|
44 | 44 | validates_presence_of :password, :if => :password_required? |
|
45 | 45 | validates_length_of :password, :within => 4..50, :if => :password_required? |
|
46 | 46 | validates_confirmation_of :password, :if => :password_required? |
You need to be logged in to leave comments.
Login now