Fix copyright, comments, phpdoc and OCS status codes
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
parent
8f192c49fe
commit
c17398dede
|
|
@ -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'
|
||||
]
|
||||
];
|
||||
|
|
|
|||
|
|
@ -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.');
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
|
||||
* @copyright Copyright (c) 2017 Pellaeon Lin <pellaeon@hs.ntnu.edu.tw>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
* @author Pellaeon Lin <pellaeon@hs.ntnu.edu.tw>
|
||||
*
|
||||
* @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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +1,12 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
|
||||
* @copyright Copyright (c) 2017 Pellaeon Lin <pellaeon@hs.ntnu.edu.tw>
|
||||
* @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
* @author Pellaeon Lin <pellaeon@hs.ntnu.edu.tw>
|
||||
* @author Lukas Reschke <lukas@statuscode.ch>
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue