location() public method

Get/Set the Location header value.
public location ( null | string $url = null ) : string | null
$url null | string Either null to get the current location, or a string to set one.
return string | null When setting the location null will be returned. When reading the location a string of the current location header value (if any) will be returned.
 /**
  * Manage redirect for specific buttons that posted.
  *
  * @param Event $event
  * @param array|string $url
  * @param Response $response
  * @return bool
  */
 public function beforeRedirect(Event $event, $url, Response $response)
 {
     if ($this->request->param('prefix') == 'admin') {
         if (isset($this->request->data['apply'])) {
             $response->location(Router::url($this->request->here(false), true));
         }
     }
     return true;
 }
 /**
  * Verify one-time code. If code not provided - redirect to verifyAction. If code provided and is not valid -
  * set flash message and redirect to verifyAction. Otherwise - return true.
  *
  * @param string $secret user's secret
  * @param string $code one-time code
  * @param Response $response response instance
  * @var AuthComponent $Auth used Auth component
  * @return bool
  * @throws Exception
  */
 protected function _verifyCode($secret, $code, Response $response)
 {
     $Auth = $this->_registry->getController()->Auth;
     if (!$Auth instanceof AuthComponent) {
         throw new Exception('TwoFactorAuth.Auth component has to be used for authentication.');
     }
     $verifyAction = Router::url($Auth->config('verifyAction'), true);
     if ($code === null) {
         $response->location($verifyAction);
         return false;
     }
     if (!$Auth->verifyCode($secret, $code)) {
         $Auth->flash(__d('TwoFactorAuth', 'Invalid two-step verification code.'));
         $response->location($verifyAction);
         return false;
     }
     return true;
 }
Beispiel #3
1
 /**
  * Handles unauthenticated access attempts. Will automatically forward to the
  * requested provider's authorization URL to let the user grant access to the
  * application.
  *
  * @param \Cake\Network\Request $request Request object.
  * @param \Cake\Network\Response $response Response object.
  * @return \Cake\Network\Response|null
  */
 public function unauthenticated(Request $request, Response $response)
 {
     $provider = $this->provider($request);
     if (empty($provider) || !empty($request->query['code'])) {
         return null;
     }
     if ($this->config('options.state')) {
         $request->session()->write('oauth2state', $provider->getState());
     }
     $response->location($provider->getAuthorizationUrl());
     return $response;
 }
Beispiel #4
0
 /**
  * Test the location method.
  *
  * @return void
  */
 public function testLocation()
 {
     $response = new Response();
     $this->assertNull($response->location(), 'No header should be set.');
     $this->assertNull($response->location('http://example.org'), 'Setting a location should return null');
     $this->assertEquals('http://example.org', $response->location(), 'Reading a location should return the value.');
 }