public function testCompressSign() { $my_string = str_repeat('AAAAABBBBBCCCCCDDDDD', 20); $signed = Sign::dumps($my_string, 'my-key'); $this->assertEquals('.', substr($signed, 0, 1)); $recover = Sign::loads($signed, 'my-key'); $this->assertEquals($my_string, $recover); }
/** * Build the header string of the cookies. */ public static function build($cookies, $key) { $c = $cookies->getAll(); if (0 === count($c)) { return ''; } $headers = ''; foreach ($c as $ck) { foreach ($ck['cookies'] as $name => $val) { $ck['cookies'][$name] = \photon\crypto\Sign::dumps($val, $key); } $headers .= 'Set-Cookie: ' . http_build_cookie($ck) . "\r\n"; } return $headers; }
/** * The $request object is used to know what the post login * redirect url should be. * * If the action url of the login page is not set, it will try to * get the url from the login view from the 'login_view' * configuration key. * * @param Request The request object of the current page. * @param string The full url of the login page (null) */ function __construct($request, $loginurl = null) { $redirect = array('_redirect_after' => \photon\crypto\Sign::dumps($request->path, Conf::f('secret_key'))); if ($loginurl !== null) { $url = URL::generate($loginurl, $redirect, false); $encoded = URL::generate($loginurl, $redirect); } else { $url = URL::forView(Conf::f('login_view', 'login_view'), array(), $redirect, false); $encoded = URL::forView(Conf::f('login_view', 'login_view'), array(), $redirect); } $content = sprintf(__('<a href="%s">Please, click here to be redirected</a>.'), $encoded); parent::__construct($content); $this->headers['Location'] = $url; $this->status_code = 302; }