Class: QueueIt::UserInQueueStateCookieRepository
- Inherits:
-
Object
- Object
- QueueIt::UserInQueueStateCookieRepository
- Defined in:
- lib/queueit_knownuserv3/user_in_queue_state_cookie_repository.rb
Constant Summary collapse
- QUEUEIT_DATA_KEY =
"QueueITAccepted-SDFrts345E-V3"
Class Method Summary collapse
Instance Method Summary collapse
- #cancelQueueCookie(eventId, cookieDomain) ⇒ Object
- #createCookieValue(queueId, isStateExtendable, expirationTime, secretKey) ⇒ Object
- #extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, secretKey) ⇒ Object
- #getCookieNameValueMap(cookieValue) ⇒ Object
- #getState(eventId, secretKey) ⇒ Object
-
#initialize(cookieManager) ⇒ UserInQueueStateCookieRepository
constructor
A new instance of UserInQueueStateCookieRepository.
- #isCookieValid(cookieNameValueMap, secretKey) ⇒ Object
- #store(eventId, queueId, isStateExtendable, cookieValidityMinute, cookieDomain, secretKey) ⇒ Object
Constructor Details
#initialize(cookieManager) ⇒ UserInQueueStateCookieRepository
Returns a new instance of UserInQueueStateCookieRepository.
9 10 11 |
# File 'lib/queueit_knownuserv3/user_in_queue_state_cookie_repository.rb', line 9 def initialize() = end |
Class Method Details
.getCookieKey(eventId) ⇒ Object
26 27 28 |
# File 'lib/queueit_knownuserv3/user_in_queue_state_cookie_repository.rb', line 26 def self.getCookieKey(eventId) return QUEUEIT_DATA_KEY + '_' + eventId end |
Instance Method Details
#cancelQueueCookie(eventId, cookieDomain) ⇒ Object
13 14 15 16 |
# File 'lib/queueit_knownuserv3/user_in_queue_state_cookie_repository.rb', line 13 def cancelQueueCookie(eventId, ) = self.class.getCookieKey(eventId) .setCookie(, nil, -1, ) end |
#createCookieValue(queueId, isStateExtendable, expirationTime, secretKey) ⇒ Object
30 31 32 33 34 |
# File 'lib/queueit_knownuserv3/user_in_queue_state_cookie_repository.rb', line 30 def createCookieValue(queueId, isStateExtendable, expirationTime, secretKey) hashValue = OpenSSL::HMAC.hexdigest('sha256', secretKey, queueId + isStateExtendable + expirationTime) = "QueueId=" + queueId + "&IsCookieExtendable=" + isStateExtendable + "&Expires=" + expirationTime + "&Hash=" + hashValue return end |
#extendQueueCookie(eventId, cookieValidityMinute, cookieDomain, secretKey) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/queueit_knownuserv3/user_in_queue_state_cookie_repository.rb', line 79 def extendQueueCookie(eventId, , , secretKey) = self.class.getCookieKey(eventId) = .getCookie() if (.nil?) return end = getCookieNameValueMap() if (!isCookieValid(, secretKey)) return end expirationTime = (Time.now.getutc.tv_sec + ( * 60)).to_s = createCookieValue(["QueueId"], ["IsCookieExtendable"], expirationTime, secretKey) .setCookie(, , Time.now + (24*60*60), ) end |
#getCookieNameValueMap(cookieValue) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/queueit_knownuserv3/user_in_queue_state_cookie_repository.rb', line 36 def getCookieNameValueMap() result = Hash.new = .split("&") if (.length != 4) return result end .each do |item| arr = item.split("=") if(arr.length == 2) result[arr[0]] = arr[1] end end return result end |
#getState(eventId, secretKey) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/queueit_knownuserv3/user_in_queue_state_cookie_repository.rb', line 95 def getState(eventId, secretKey) = = self.class.getCookieKey(eventId) if (.getCookie().nil?) return StateInfo.new(false, nil, false, 0) end = getCookieNameValueMap(.getCookie()) if (!isCookieValid(, secretKey)) return StateInfo.new(false, nil, false,0) end return StateInfo.new( true, ["QueueId"], ["IsCookieExtendable"] == 'true', Integer(["Expires"])) end |
#isCookieValid(cookieNameValueMap, secretKey) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/queueit_knownuserv3/user_in_queue_state_cookie_repository.rb', line 52 def isCookieValid(, secretKey) begin if (!.key?("IsCookieExtendable")) return false end if (!.key?("Expires")) return false end if (!.key?("Hash")) return false end if (!.key?("QueueId")) return false end hashValue = OpenSSL::HMAC.hexdigest('sha256', secretKey, ["QueueId"] + ["IsCookieExtendable"] + ["Expires"]) if (hashValue != ["Hash"]) return false end if(Integer(["Expires"]) < Time.now.getutc.tv_sec) return false end return true rescue return false end end |
#store(eventId, queueId, isStateExtendable, cookieValidityMinute, cookieDomain, secretKey) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/queueit_knownuserv3/user_in_queue_state_cookie_repository.rb', line 18 def store(eventId, queueId, isStateExtendable, , , secretKey) = self.class.getCookieKey(eventId) expirationTime = (Time.now.getutc.tv_sec + ( * 60)).to_s isStateExtendableString = (isStateExtendable) ? 'true' : 'false' = createCookieValue(queueId, isStateExtendableString, expirationTime, secretKey) .setCookie(, , Time.now + (24*60*60), ) end |