예제 #1
0
 /**
  * @param User $user
  * @param Response $response
  * @return Response
  */
 public function login(User $user, Response $response = null)
 {
     if ($response === null) {
         $response = new Response();
     }
     $payload = array(self::FIELD_PAYLOAD_USERNAME => $user->getUsername(), self::FIELD_PAYLOAD_TOKEN => $this->helper->createPasswordToken($user), self::FIELD_CREATION_TIME => time());
     $data = array(self::FIELD_PAYLOAD => $payload, self::FIELD_SIGNATURE => $this->sign($payload));
     $base64 = base64_encode(json_encode($data));
     $expireTime = 0;
     //at the end of the session
     $cookie = new Cookie(self::COOKIE_NAME, $base64, $expireTime, $this->cookiePath);
     $response->headers->setCookie($cookie);
     return $response;
 }