Use client secret as identifier

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2017-06-30 15:55:21 +02:00
parent f4521a9d29
commit 74b5428193
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
6 changed files with 35 additions and 20 deletions

View File

@ -18,5 +18,7 @@ namespace OCA\Registration\AppInfo;
\OCP\App::registerAdmin('registration', 'admin'); \OCP\App::registerAdmin('registration', 'admin');
$app = new \OCP\AppFramework\App('registration'); if(interface_exists('\OCP\Capabilities\IPublicCapability')) {
$app->getContainer()->registerCapability(\OCA\Registration\Capabilities::class); $app = new \OCP\AppFramework\App('registration');
$app->getContainer()->registerCapability(\OCA\Registration\Capabilities::class);
}

View File

@ -42,10 +42,12 @@
<name>token</name> <name>token</name>
<type>text</type> <type>text</type>
<notnull>true</notnull> <notnull>true</notnull>
<unique>true</unique>
</field> </field>
<field> <field>
<name>client_secret</name> <name>client_secret</name>
<type>text</type> <type>text</type>
<unique>true</unique>
</field> </field>
<field> <field>
<name>requested</name> <name>requested</name>

View File

@ -24,9 +24,10 @@
namespace OCA\Registration; namespace OCA\Registration;
use OCP\Capabilities\ICapability; use OCP\Capabilities\ICapability;
use OCP\Capabilities\IPublicCapability;
use OCP\IURLGenerator; use OCP\IURLGenerator;
class Capabilities implements ICapability { class Capabilities implements IPublicCapability {
/** @var IURLGenerator */ /** @var IURLGenerator */
private $urlGenerator; private $urlGenerator;

View File

@ -49,8 +49,8 @@ class ApiController extends OCSController {
/** @var Defaults */ /** @var Defaults */
private $defaults; private $defaults;
const OCS_STATUS_PENDING = 101; const OCS_STATUS_PENDING = 403;
const OCS_STATUS_RESENT = 102; const OCS_STATUS_RESENT = 403;
public function __construct($appName, public function __construct($appName,
IRequest $request, IRequest $request,
@ -95,18 +95,19 @@ class ApiController extends OCSController {
* @PublicPage * @PublicPage
* @AnonRateThrottle(limit=10, period=1) * @AnonRateThrottle(limit=10, period=1)
* *
* @param string $registrationToken
* @param string $clientSecret * @param string $clientSecret
* @throws OCSException * @throws OCSException
* @return DataResponse * @return DataResponse
*/ */
public function status($registrationToken, $clientSecret=null) { public function status($clientSecret) {
$data = [];
try { try {
/** @var Registration $registration */ /** @var Registration $registration */
$registration = $this->registrationService->getRegistrationForToken($registrationToken); $registration = $this->registrationService->getRegistrationForSecret($clientSecret);
if(!$registration->getEmailConfirmed()) { if(!$registration->getEmailConfirmed()) {
throw new OCSException($this->l10n->t('Your registration is pending. Please confirm your email address.'), self::OCS_STATUS_PENDING); throw new OCSException(
$this->l10n->t('Your registration is pending. Please confirm your email address.'),
self::OCS_STATUS_PENDING
);
} 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);
@ -115,16 +116,13 @@ class ApiController extends OCSController {
} }
$this->registrationService->loginUser($user->getUID(), $registration->getUsername(), $registration->getPassword(), true); $this->registrationService->loginUser($user->getUID(), $registration->getUsername(), $registration->getPassword(), true);
$appPassword = $this->registrationService->generateAppPassword($user->getUID()); $appPassword = $this->registrationService->generateAppPassword($user->getUID());
if ($clientSecret === $registration->getClientSecret()) { $data = [
$data = [ 'appPassword' => $appPassword,
'status' => Registration::STATUS_FINISHED, 'cloudUrl' => $this->defaults->getBaseUrl()
'appPassword' => $appPassword, ];
'cloudUrl' => $this->defaults->getBaseUrl() $this->registrationService->deleteRegistration($registration);
]; return new DataResponse($data, Http::STATUS_OK);
$this->registrationService->deleteRegistration($registration);
}
} }
return new DataResponse($data, Http::STATUS_OK);
} catch (DoesNotExistException $e) { } catch (DoesNotExistException $e) {
throw new OCSNotFoundException('No pending registration.'); throw new OCSNotFoundException('No pending registration.');
} }
@ -158,7 +156,6 @@ class ApiController extends OCSController {
} }
$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.');
$data['token'] = $registration->getToken();
$data['status'] = Registration::STATUS_PENDING; $data['status'] = Registration::STATUS_PENDING;
if($secret !== null) { if($secret !== null) {
$data['secret'] = $secret; $data['secret'] = $secret;

View File

@ -46,6 +46,11 @@ class RegistrationMapper extends Mapper {
return $this->findEntity('SELECT * FROM `*PREFIX*registration` WHERE `token` = ? ', [$token]); return $this->findEntity('SELECT * FROM `*PREFIX*registration` WHERE `token` = ? ', [$token]);
} }
public function findBySecret($secret) {
return $this->findEntity('SELECT * FROM `*PREFIX*registration` WHERE `client_secret` = ? ', [$secret]);
}
/** /**
* @param $email * @param $email
* @return Registration|Entity * @return Registration|Entity

View File

@ -309,6 +309,14 @@ class RegistrationService {
return $this->registrationMapper->findByToken($token); return $this->registrationMapper->findByToken($token);
} }
/**
* @param $secret
* @return Registration
*/
public function getRegistrationForSecret($secret) {
return $this->registrationMapper->findBySecret($secret);
}
/** /**
* @param Registration $registation * @param Registration $registation
* @return null|\OCP\IUser * @return null|\OCP\IUser