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,
|
'enabled' => true,
|
||||||
'apiRoot' => $this->urlGenerator->linkTo(
|
'apiRoot' => $this->urlGenerator->linkTo(
|
||||||
'', 'ocs/v1.php/apps/registration/api/v1/'),
|
'', 'ocs/v2.php/apps/registration/api/v1/'),
|
||||||
'apiLevel' => 'v1'
|
'apiLevel' => 'v1'
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -49,16 +49,16 @@ class ApiController extends OCSController {
|
||||||
/** @var Defaults */
|
/** @var Defaults */
|
||||||
private $defaults;
|
private $defaults;
|
||||||
|
|
||||||
|
const OCS_STATUS_PENDING = 101;
|
||||||
|
const OCS_STATUS_RESENT = 102;
|
||||||
|
|
||||||
public function __construct($appName,
|
public function __construct($appName,
|
||||||
IRequest $request,
|
IRequest $request,
|
||||||
$corsMethods = 'PUT, POST, GET, DELETE, PATCH',
|
|
||||||
$corsAllowedHeaders = 'Authorization, Content-Type, Accept',
|
|
||||||
$corsMaxAge = 1728000,
|
|
||||||
RegistrationService $registrationService,
|
RegistrationService $registrationService,
|
||||||
MailService $mailService,
|
MailService $mailService,
|
||||||
IL10N $l10n,
|
IL10N $l10n,
|
||||||
Defaults $defaults) {
|
Defaults $defaults) {
|
||||||
parent::__construct($appName, $request, $corsMethods, $corsAllowedHeaders, $corsMaxAge);
|
parent::__construct($appName, $request);
|
||||||
$this->registrationService = $registrationService;
|
$this->registrationService = $registrationService;
|
||||||
$this->mailService = $mailService;
|
$this->mailService = $mailService;
|
||||||
$this->l10n = $l10n;
|
$this->l10n = $l10n;
|
||||||
|
|
@ -69,9 +69,9 @@ class ApiController extends OCSController {
|
||||||
* @PublicPage
|
* @PublicPage
|
||||||
* @AnonRateThrottle(limit=5, period=1)
|
* @AnonRateThrottle(limit=5, period=1)
|
||||||
*
|
*
|
||||||
* @param $username
|
* @param string $username
|
||||||
* @param $displayname
|
* @param string $displayname
|
||||||
* @param $email
|
* @param string $email
|
||||||
* @throws OCSException
|
* @throws OCSException
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
|
|
@ -93,9 +93,10 @@ class ApiController extends OCSController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @PublicPage
|
* @PublicPage
|
||||||
|
* @AnonRateThrottle(limit=10, period=1)
|
||||||
*
|
*
|
||||||
* @param $registrationToken
|
* @param string $registrationToken
|
||||||
* @param $clientSecret
|
* @param string $clientSecret
|
||||||
* @throws OCSException
|
* @throws OCSException
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
|
|
@ -105,10 +106,7 @@ class ApiController extends OCSController {
|
||||||
/** @var Registration $registration */
|
/** @var Registration $registration */
|
||||||
$registration = $this->registrationService->getRegistrationForToken($registrationToken);
|
$registration = $this->registrationService->getRegistrationForToken($registrationToken);
|
||||||
if(!$registration->getEmailConfirmed()) {
|
if(!$registration->getEmailConfirmed()) {
|
||||||
$data = [
|
throw new OCSException($this->l10n->t('Your registration is pending. Please confirm your email address.'), self::OCS_STATUS_PENDING);
|
||||||
'status' => Registration::STATUS_PENDING,
|
|
||||||
'message' => $this->l10n->t('Your registration is pending. Please confirm your email address.')
|
|
||||||
];
|
|
||||||
} else {
|
} else {
|
||||||
// create account if email confirmed and not already created
|
// create account if email confirmed and not already created
|
||||||
$user = $this->registrationService->getUserAccount($registration);
|
$user = $this->registrationService->getUserAccount($registration);
|
||||||
|
|
@ -135,10 +133,10 @@ class ApiController extends OCSController {
|
||||||
/**
|
/**
|
||||||
* @PublicPage
|
* @PublicPage
|
||||||
*
|
*
|
||||||
* @param $username
|
* @param string $username
|
||||||
* @param $displayname
|
* @param string $displayname
|
||||||
* @param $email
|
* @param string $email
|
||||||
* @param $password
|
* @param string $password
|
||||||
* @throws OCSException
|
* @throws OCSException
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
|
|
@ -156,7 +154,7 @@ class ApiController extends OCSController {
|
||||||
} else {
|
} else {
|
||||||
$this->registrationService->generateNewToken($registration);
|
$this->registrationService->generateNewToken($registration);
|
||||||
$this->mailService->sendTokenByMail($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.');
|
$data['message'] = $this->l10n->t('Your registration is pending. Please confirm your email address.');
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
|
* @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 Julius Härtl <jus@bitgrid.net>
|
||||||
|
* @author Pellaeon Lin <pellaeon@hs.ntnu.edu.tw>
|
||||||
*
|
*
|
||||||
* @license GNU AGPL version 3 or any later version
|
* @license GNU AGPL version 3 or any later version
|
||||||
*
|
*
|
||||||
|
|
@ -61,12 +63,21 @@ class MailService {
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $email
|
||||||
|
* @throws RegistrationException
|
||||||
|
*/
|
||||||
public function validateEmail($email) {
|
public function validateEmail($email) {
|
||||||
if ( !$this->mailer->validateMailAddress($email) ) {
|
if ( !$this->mailer->validateMailAddress($email) ) {
|
||||||
throw new RegistrationException($this->l10n->t('The email address you entered is not valid'));
|
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) {
|
public function sendTokenByMail(Registration $registration) {
|
||||||
return true;
|
return true;
|
||||||
$link = $this->urlGenerator->linkToRoute('registration.register.verifyToken', array('token' => $registration->getToken()));
|
$link = $this->urlGenerator->linkToRoute('registration.register.verifyToken', array('token' => $registration->getToken()));
|
||||||
|
|
@ -94,6 +105,9 @@ class MailService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $userId
|
||||||
|
*/
|
||||||
public function notifyAdmins($userId) {
|
public function notifyAdmins($userId) {
|
||||||
// Notify admin
|
// Notify admin
|
||||||
$admin_users = $this->groupManager->get('admin')->getUsers();
|
$admin_users = $this->groupManager->get('admin')->getUsers();
|
||||||
|
|
|
||||||
|
|
@ -27,16 +27,22 @@ class RegistrationException extends \Exception {
|
||||||
|
|
||||||
protected $hint;
|
protected $hint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RegistrationException constructor.
|
||||||
|
*
|
||||||
|
* @param string $message
|
||||||
|
* @param string $hint
|
||||||
|
*/
|
||||||
public function __construct($message, $hint = "") {
|
public function __construct($message, $hint = "") {
|
||||||
parent::__construct($message);
|
parent::__construct($message);
|
||||||
$this->setHint($hint);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setHint($hint) {
|
|
||||||
$this->hint = $hint;
|
$this->hint = $hint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function getHint() {
|
public function getHint() {
|
||||||
return $this->hint;
|
return $this->hint;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
|
* @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 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
|
* @license GNU AGPL version 3 or any later version
|
||||||
*
|
*
|
||||||
|
|
@ -104,6 +108,9 @@ class RegistrationService {
|
||||||
$this->crypto = $crypto;
|
$this->crypto = $crypto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Registration $registration
|
||||||
|
*/
|
||||||
public function confirmEmail(Registration &$registration) {
|
public function confirmEmail(Registration &$registration) {
|
||||||
$registration->setEmailConfirmed(true);
|
$registration->setEmailConfirmed(true);
|
||||||
$this->registrationMapper->update($registration);
|
$this->registrationMapper->update($registration);
|
||||||
|
|
@ -117,7 +124,7 @@ class RegistrationService {
|
||||||
$this->registrationMapper->update($registration);
|
$this->registrationMapper->update($registration);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param $email
|
* @param string $email
|
||||||
* @param string $username
|
* @param string $username
|
||||||
* @param string $password
|
* @param string $password
|
||||||
* @param string $displayname
|
* @param string $displayname
|
||||||
|
|
@ -139,7 +146,7 @@ class RegistrationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $email
|
* @param string $email
|
||||||
* @return Registration
|
* @return Registration
|
||||||
* @throws RegistrationException
|
* @throws RegistrationException
|
||||||
*/
|
*/
|
||||||
|
|
@ -171,7 +178,7 @@ class RegistrationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $displayname
|
* @param string $displayname
|
||||||
* @throws RegistrationException
|
* @throws RegistrationException
|
||||||
*/
|
*/
|
||||||
public function validateDisplayname($displayname) {
|
public function validateDisplayname($displayname) {
|
||||||
|
|
@ -181,7 +188,7 @@ class RegistrationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $username
|
* @param string $username
|
||||||
* @throws RegistrationException
|
* @throws RegistrationException
|
||||||
*/
|
*/
|
||||||
public function validateUsername($username) {
|
public function validateUsername($username) {
|
||||||
|
|
@ -193,7 +200,7 @@ class RegistrationService {
|
||||||
/**
|
/**
|
||||||
* check if email domain is allowed
|
* check if email domain is allowed
|
||||||
*
|
*
|
||||||
* @param $email
|
* @param string $email
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function checkAllowedDomains($email) {
|
public function checkAllowedDomains($email) {
|
||||||
|
|
@ -226,7 +233,7 @@ class RegistrationService {
|
||||||
/**
|
/**
|
||||||
* Find registration entity for token
|
* Find registration entity for token
|
||||||
*
|
*
|
||||||
* @param $token
|
* @param string $token
|
||||||
* @return string
|
* @return string
|
||||||
* @throws RegistrationException
|
* @throws RegistrationException
|
||||||
*/
|
*/
|
||||||
|
|
@ -240,8 +247,8 @@ class RegistrationService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $registration
|
* @param $registration
|
||||||
* @param null $username
|
* @param string $username
|
||||||
* @param null $password
|
* @param string $password
|
||||||
* @return \OCP\IUser
|
* @return \OCP\IUser
|
||||||
* @throws RegistrationException
|
* @throws RegistrationException
|
||||||
*/
|
*/
|
||||||
|
|
@ -334,7 +341,7 @@ class RegistrationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $uid
|
* @param string $uid
|
||||||
* @return string
|
* @return string
|
||||||
* @throws RegistrationException
|
* @throws RegistrationException
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue