/** * Attempt to change current authenticated AuthAccess email identity if available * @param string $sAuthAccessEmailIdentity * @throws \InvalidArgumentException * @return \BoilerAppAccessControl\Service\AuthAccessService */ public function changeAuthenticatedAuthAccessEmailIdentity($sAuthAccessEmailIdentity) { if (!is_string($sAuthAccessEmailIdentity)) { throw new \InvalidArgumentException('AuthAccess email identity expects string, "' . gettype($sAuthAccessEmailIdentity) . '" given'); } if (!filter_var($sAuthAccessEmailIdentity, FILTER_VALIDATE_EMAIL)) { throw new \InvalidArgumentException('AuthAccess email identity expects valid email, "' . $sAuthAccessEmailIdentity . '" given'); } $oAuthAccessRepository = $this->getServiceLocator()->get('BoilerAppAccessControl\\Repository\\AuthAccessRepository'); if (!$oAuthAccessRepository->isEmailIdentityAvailable($sAuthAccessEmailIdentity)) { throw new \InvalidArgumentException('AuthAccess email identity "' . $sAuthAccessEmailIdentity . '" is not available'); } //Update AuthAcces public key $oAuthAccess = $this->getServiceLocator()->get('AccessControlService')->getAuthenticatedAuthAccess(); $oAuthAccessRepository->update($oAuthAccess->setAuthAccessPublicKey($this->getServiceLocator()->get('Encryptor')->create($sPublicKey = $this->getServiceLocator()->get('AccessControlService')->generateAuthAccessPublicKey()))); //Create email view body $oView = new \Zend\View\Model\ViewModel(array('auth_access_email_identity' => $sAuthAccessEmailIdentity, 'auth_access_public_key' => $sPublicKey)); //Retrieve Messenger service $oMessengerService = $this->getServiceLocator()->get('MessengerService'); //Send email confirmation to user $oMessage = new \BoilerAppMessenger\Message\Message(); $oMessengerService->sendMessage($oMessage->setFrom($oMessengerService->getSystemUser())->setTo($oAuthAccess->getAuthAccessUser())->setSubject($this->getServiceLocator()->get('translator')->translate('confirm_change_email'))->setBody($oView->setTemplate('mail/auth-access/confirm-change-email-identity')), \BoilerAppMessenger\Media\Mail\MailMessageRenderer::MEDIA); return $this; }
/** * @param string $sAuthAccessIdentity * @throws \InvalidArgumentException * @return \BoilerAppAccessControl\Service\RegistrationService */ public function resendConfirmationEmail($sAuthAccessIdentity) { if (empty($sAuthAccessIdentity) || !is_string($sAuthAccessIdentity)) { throw new \InvalidArgumentException(sprintf('AuthAccess identity expects a not empty string, "%s" given', is_scalar($sAuthAccessIdentity) ? $sAuthAccessIdentity : gettype($sAuthAccessIdentity))); } $oAccessControlService = $this->getServiceLocator()->get('AccessControlService'); if (!($oAuthAccess = $oAccessControlService->getAuthAccessFromIdentity($sAuthAccessIdentity))) { throw new \LogicException(sprintf('AuthAccess with identity "%s" does not exist', $sAuthAccessIdentity)); } //Reset public key $oAuthAccess->setAuthAccessPublicKey($this->getServiceLocator()->get('Encryptor')->create($sPublicKey = $oAccessControlService->generateAuthAccessPublicKey())); $this->getServiceLocator()->get('BoilerAppAccessControl\\Repository\\AuthAccessRepository')->update($oAuthAccess); //Create email view body $oView = new \Zend\View\Model\ViewModel(array('auth_access_public_key' => $sPublicKey, 'auth_access_email_identity' => $oAuthAccess->getAuthAccessEmailIdentity())); //Retrieve Messenger service $oMessengerService = $this->getServiceLocator()->get('MessengerService'); //Send email confirmation to user $oMessage = new \BoilerAppMessenger\Message\Message(); $oMessengerService->sendMessage($oMessage->setFrom($oMessengerService->getSystemUser())->setTo($oAuthAccess->getAuthAccessUser())->setSubject($this->getServiceLocator()->get('translator')->translate('register'))->setBody($oView->setTemplate('mail/registration/confirm-email')), \BoilerAppMessenger\Media\Mail\MailMessageRenderer::MEDIA); return $this; }
/** * @param string $sResetKey * @throws \Exception * @return \BoilerAppAccessControl\Service\AuthenticationService */ public function resetCredential($sPublicKey, $sEmailIdentity) { if (empty($sPublicKey) || !is_string($sPublicKey)) { throw new \InvalidArgumentException('Public key expects a not empty string , "' . gettype($sPublicKey) . '" given'); } if (empty($sEmailIdentity) || !is_string($sEmailIdentity)) { throw new \InvalidArgumentException('Email identity expects a not empty string , "' . gettype($sEmailIdentity) . '" given'); } if (!($oAuthAccess = $this->getServiceLocator()->get('BoilerAppAccessControl\\Repository\\AuthAccessRepository')->findOneBy(array('auth_access_email_identity' => $sEmailIdentity)))) { throw new \LogicException('AuthAccess with email identity "' . $sEmailIdentity . '" does not exist'); } //Verify public key $oEncryptor = $this->getServiceLocator()->get('Encryptor'); if (!$oEncryptor->verify($sPublicKey, $oAuthAccess->getAuthAccessPublicKey())) { throw new \LogicException(sprintf('Public key "%s" is not valid for email identity "%s"', $sPublicKey, $sEmailIdentity)); } elseif ($oAuthAccess->getAuthAccessState() !== \BoilerAppAccessControl\Repository\AuthAccessRepository::AUTH_ACCESS_ACTIVE_STATE) { throw new \LogicException(sprintf('AuthAccess "%s" is not active', $oAuthAccess->getAuthAccessId())); } //Update AuthAccess entity $this->getServiceLocator()->get('BoilerAppAccessControl\\Repository\\AuthAccessRepository')->update($oAuthAccess->setAuthAccessCredential($oEncryptor->create(md5($sCredential = md5(date('Y-m-d') . str_shuffle(uniqid())))))->setAuthAccessPublicKey($oEncryptor->create($this->getServiceLocator()->get('AccessControlService')->generateAuthAccessPublicKey()))); //Create email view body $oView = new \Zend\View\Model\ViewModel(array('auth_access_username_identity' => $oAuthAccess->getAuthAccessUsernameIdentity(), 'auth_access_credential' => $sCredential)); //Retrieve Messenger service $oMessengerService = $this->getServiceLocator()->get('MessengerService'); $oMessage = new \BoilerAppMessenger\Message\Message(); $oMessengerService->sendMessage($oMessage->setFrom($oMessengerService->getSystemUser())->setTo($oAuthAccess->getAuthAccessUser())->setSubject($this->getServiceLocator()->get('translator')->translate('reset_credential'))->setBody($oView->setTemplate('mail/authentication/credential-reset')), \BoilerAppMessenger\Media\Mail\MailMessageRenderer::MEDIA); return $this; }