diff --git a/capabilities.php b/capabilities.php index 035ad97..58021e5 100644 --- a/capabilities.php +++ b/capabilities.php @@ -41,7 +41,7 @@ class Capabilities implements ICapability { [ 'enabled' => true, 'apiRoot' => $this->urlGenerator->linkTo( - '', 'ocs/v1.php/apps/registration/api/v1/'), + '', 'ocs/v2.php/apps/registration/api/v1/'), 'apiLevel' => 'v1' ] ]; diff --git a/controller/apicontroller.php b/controller/apicontroller.php index 32bc2d0..bd04ca1 100644 --- a/controller/apicontroller.php +++ b/controller/apicontroller.php @@ -49,16 +49,16 @@ class ApiController extends OCSController { /** @var Defaults */ private $defaults; + const OCS_STATUS_PENDING = 101; + const OCS_STATUS_RESENT = 102; + public function __construct($appName, IRequest $request, - $corsMethods = 'PUT, POST, GET, DELETE, PATCH', - $corsAllowedHeaders = 'Authorization, Content-Type, Accept', - $corsMaxAge = 1728000, RegistrationService $registrationService, MailService $mailService, IL10N $l10n, Defaults $defaults) { - parent::__construct($appName, $request, $corsMethods, $corsAllowedHeaders, $corsMaxAge); + parent::__construct($appName, $request); $this->registrationService = $registrationService; $this->mailService = $mailService; $this->l10n = $l10n; @@ -69,9 +69,9 @@ class ApiController extends OCSController { * @PublicPage * @AnonRateThrottle(limit=5, period=1) * - * @param $username - * @param $displayname - * @param $email + * @param string $username + * @param string $displayname + * @param string $email * @throws OCSException * @return DataResponse */ @@ -93,9 +93,10 @@ class ApiController extends OCSController { /** * @PublicPage + * @AnonRateThrottle(limit=10, period=1) * - * @param $registrationToken - * @param $clientSecret + * @param string $registrationToken + * @param string $clientSecret * @throws OCSException * @return DataResponse */ @@ -105,10 +106,7 @@ class ApiController extends OCSController { /** @var Registration $registration */ $registration = $this->registrationService->getRegistrationForToken($registrationToken); if(!$registration->getEmailConfirmed()) { - $data = [ - 'status' => Registration::STATUS_PENDING, - 'message' => $this->l10n->t('Your registration is pending. Please confirm your email address.') - ]; + throw new OCSException($this->l10n->t('Your registration is pending. Please confirm your email address.'), self::OCS_STATUS_PENDING); } else { // create account if email confirmed and not already created $user = $this->registrationService->getUserAccount($registration); @@ -135,10 +133,10 @@ class ApiController extends OCSController { /** * @PublicPage * - * @param $username - * @param $displayname - * @param $email - * @param $password + * @param string $username + * @param string $displayname + * @param string $email + * @param string $password * @throws OCSException * @return DataResponse */ @@ -156,7 +154,7 @@ class ApiController extends OCSController { } else { $this->registrationService->generateNewToken($registration); $this->mailService->sendTokenByMail($registration); - throw new RegistrationException($this->l10n->t('There is already a pending registration with this email, a new verification email has been sent to the address.')); + throw new OCSException($this->l10n->t('There is already a pending registration with this email, a new verification email has been sent to the address.'), self::OCS_STATUS_RESENT); } $data['message'] = $this->l10n->t('Your registration is pending. Please confirm your email address.'); diff --git a/service/mailservice.php b/service/mailservice.php index 0b23008..7122b21 100644 --- a/service/mailservice.php +++ b/service/mailservice.php @@ -1,8 +1,10 @@ + * @copyright Copyright (c) 2017 Pellaeon Lin * * @author Julius Härtl + * @author Pellaeon Lin * * @license GNU AGPL version 3 or any later version * @@ -61,12 +63,21 @@ class MailService { $this->logger = $logger; } + /** + * @param string $email + * @throws RegistrationException + */ public function validateEmail($email) { if ( !$this->mailer->validateMailAddress($email) ) { throw new RegistrationException($this->l10n->t('The email address you entered is not valid')); } } + /** + * @param Registration $registration + * @return bool + * @throws RegistrationException + */ public function sendTokenByMail(Registration $registration) { return true; $link = $this->urlGenerator->linkToRoute('registration.register.verifyToken', array('token' => $registration->getToken())); @@ -94,6 +105,9 @@ class MailService { } } + /** + * @param string $userId + */ public function notifyAdmins($userId) { // Notify admin $admin_users = $this->groupManager->get('admin')->getUsers(); diff --git a/service/registrationexception.php b/service/registrationexception.php index 48d6e2c..1035811 100644 --- a/service/registrationexception.php +++ b/service/registrationexception.php @@ -27,16 +27,22 @@ class RegistrationException extends \Exception { protected $hint; + /** + * RegistrationException constructor. + * + * @param string $message + * @param string $hint + */ public function __construct($message, $hint = "") { parent::__construct($message); - $this->setHint($hint); - } - - public function setHint($hint) { $this->hint = $hint; } + /** + * @return string + */ public function getHint() { return $this->hint; } + } \ No newline at end of file diff --git a/service/registrationservice.php b/service/registrationservice.php index 1dba483..d9e2398 100644 --- a/service/registrationservice.php +++ b/service/registrationservice.php @@ -1,8 +1,12 @@ + * @copyright Copyright (c) 2017 Pellaeon Lin + * @copyright Copyright (c) 2017 Lukas Reschke * * @author Julius Härtl + * @author Pellaeon Lin + * @author Lukas Reschke * * @license GNU AGPL version 3 or any later version * @@ -104,6 +108,9 @@ class RegistrationService { $this->crypto = $crypto; } + /** + * @param Registration $registration + */ public function confirmEmail(Registration &$registration) { $registration->setEmailConfirmed(true); $this->registrationMapper->update($registration); @@ -117,7 +124,7 @@ class RegistrationService { $this->registrationMapper->update($registration); } /** - * @param $email + * @param string $email * @param string $username * @param string $password * @param string $displayname @@ -139,7 +146,7 @@ class RegistrationService { } /** - * @param $email + * @param string $email * @return Registration * @throws RegistrationException */ @@ -171,7 +178,7 @@ class RegistrationService { } /** - * @param $displayname + * @param string $displayname * @throws RegistrationException */ public function validateDisplayname($displayname) { @@ -181,7 +188,7 @@ class RegistrationService { } /** - * @param $username + * @param string $username * @throws RegistrationException */ public function validateUsername($username) { @@ -193,7 +200,7 @@ class RegistrationService { /** * check if email domain is allowed * - * @param $email + * @param string $email * @return bool */ public function checkAllowedDomains($email) { @@ -226,7 +233,7 @@ class RegistrationService { /** * Find registration entity for token * - * @param $token + * @param string $token * @return string * @throws RegistrationException */ @@ -240,8 +247,8 @@ class RegistrationService { /** * @param $registration - * @param null $username - * @param null $password + * @param string $username + * @param string $password * @return \OCP\IUser * @throws RegistrationException */ @@ -334,7 +341,7 @@ class RegistrationService { } /** - * @param $uid + * @param string $uid * @return string * @throws RegistrationException */