changeset 262:4ac39b9e2ca4

sync
author sergey
date Sat, 29 Dec 2012 03:22:15 +0400
parents 93963ec449c5
children 0f59b2de72af
files Lib/IMPL/Web/Handler/SecureCookie.pm
diffstat 1 files changed, 9 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/Web/Handler/SecureCookie.pm	Fri Dec 28 16:43:03 2012 +0400
+++ b/Lib/IMPL/Web/Handler/SecureCookie.pm	Sat Dec 29 03:22:15 2012 +0400
@@ -32,6 +32,14 @@
     $this->salt('DeadBeef') unless $this->salt;
 }
 
+sub ValidateCookie {
+    my ($this,$sid,$cookie,$sign) = @_;
+    
+    return 1 if $sid and $cookie and $sign and $sign eq md5_hex($this->salt,$sid,$cookie,$this->salt);
+    
+    return 0;
+}
+
 sub Invoke {
     my ($this,$action,$nextHandler) = @_;
     
@@ -45,17 +53,7 @@
     my $cookie = $action->cookie('sdata',qr/(\w+)/);
     my $sign = $action->cookie('sign',qw/(\w+)/);
     
-    if (
-        $sid and
-        $cookie and
-        $sign and
-        $sign eq md5_hex(
-            $this->salt,
-            $sid,
-            $cookie,
-            $this->salt
-        )
-    ) {
+    if ( $this->ValidateCookie($sid,$cookie,$sign) ) {
         # TODO: add a DefferedProxy to deffer a request to a data source
         if ( $context = $this->_manager->GetSession($sid) ) {
             if ( eval { $context->auth->isa(AuthSimple) } ) {