Ejemplo n.º 1
0
 public function formSuccess(Form $form)
 {
     try {
         $session = $this->getSession();
         list($id, $signRequests) = $session->authenticationData;
         $session->remove();
         if ($this->getUser()->isLoggedIn()) {
             throw new \Exception('User is already logged in.');
         } elseif ($id !== $this->id) {
             throw new \Exception(sprintf('User id mismatch. %s stored in session, but %s is expected.', $id, $this->id));
         }
         $data = Json::decode($form->getValues()->data);
         if (isset($data->errorCode)) {
             throw new \Exception(sprintf('User error %s.', $data->errorCode));
         }
         $this->setRegistration($this->getServer()->authenticate($signRequests, $this->getRegistrationRepository()->findRegistrations($this->id), new SignResponse(Helpers::urlSafeBase64Decode($data->keyHandle), Helpers::urlSafeBase64Decode($data->signatureData), Helpers::urlSafeBase64Decode($data->clientData))));
         $this->getRegistrationRepository()->saveRegistration($id, $this->getRegistration());
     } catch (\Exception $e) {
         $this->setRegistration();
         $this->onError($e);
     }
     $this->onResponse($this);
 }
Ejemplo n.º 2
0
 public function formSuccess(Form $form)
 {
     try {
         $session = $this->getSession();
         list($id, $registerRequest) = $session->registrationData;
         $session->remove();
         if (!$this->getUser()->isLoggedIn()) {
             throw new \Exception('User not logged in.');
         } elseif ($id !== $this->getUser()->getId()) {
             throw new \Exception(sprintf('User id mismatch. %s stored in session, but %s is logged in.', $id, $this->getUser()->getId()));
         }
         $data = Json::decode($form->getValues()->data);
         if (isset($data->errorCode)) {
             throw new \Exception(sprintf('User error %s.', $data->errorCode));
         }
         $this->setRegistration($this->getServer()->register($registerRequest, new RegisterResponse(Helpers::urlSafeBase64Decode($data->registrationData), Helpers::urlSafeBase64Decode($data->clientData))));
         $this->getRegistrationRepository()->saveRegistration($id, $this->getRegistration());
     } catch (\Exception $e) {
         $this->setRegistration();
         $this->onError($e);
     }
     $this->onResponse($this);
 }