2016-12-22 07:07:06 +01:00
|
|
|
<?php
|
|
|
|
use Respect\Validation\Validator as DataValidator;
|
|
|
|
|
2017-04-16 07:35:04 +02:00
|
|
|
/**
|
2017-05-12 06:58:40 +02:00
|
|
|
* @api {post} /user/verify Verify email
|
2019-10-08 01:21:43 +02:00
|
|
|
* @apiVersion 4.5.0
|
2017-04-16 07:35:04 +02:00
|
|
|
*
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiName Verify email
|
2017-04-16 07:35:04 +02:00
|
|
|
*
|
|
|
|
* @apiGroup User
|
|
|
|
*
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiDescription This path verifies the email of a new user.
|
2017-04-16 07:35:04 +02:00
|
|
|
*
|
|
|
|
* @apiPermission any
|
|
|
|
*
|
2017-04-21 08:09:24 +02:00
|
|
|
* @apiParam {String} email The email of the user.
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiParam {String} token The validation token sent by email to the user.
|
2017-04-16 07:35:04 +02:00
|
|
|
*
|
2017-04-21 08:09:24 +02:00
|
|
|
* @apiUse INVALID_EMAIL
|
|
|
|
* @apiUse USER_SYSTEM_DISABLED
|
|
|
|
* @apiUse INVALID_TOKEN
|
2017-04-16 07:35:04 +02:00
|
|
|
*
|
2017-04-22 03:33:17 +02:00
|
|
|
* @apiSuccess {Object} data Empty object
|
2017-04-16 07:35:04 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-12-22 07:07:06 +01:00
|
|
|
class VerifyController extends Controller{
|
|
|
|
const PATH = '/verify';
|
2017-02-08 19:09:15 +01:00
|
|
|
const METHOD = 'POST';
|
2016-12-22 07:07:06 +01:00
|
|
|
|
|
|
|
public function validations() {
|
|
|
|
return [
|
|
|
|
'permission' => 'any',
|
|
|
|
'requestData' => [
|
|
|
|
'email' => [
|
|
|
|
'validation' => DataValidator::email(),
|
|
|
|
'error' => ERRORS::INVALID_EMAIL
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handler() {
|
2017-01-16 20:07:53 +01:00
|
|
|
if(!Controller::isUserSystemEnabled()) {
|
2018-11-20 23:41:00 +01:00
|
|
|
throw new RequestException(ERRORS::USER_SYSTEM_DISABLED);
|
2017-01-16 20:07:53 +01:00
|
|
|
}
|
2018-09-28 00:46:30 +02:00
|
|
|
|
2016-12-22 07:07:06 +01:00
|
|
|
$email = Controller::request('email');
|
|
|
|
$token = Controller::request('token');
|
|
|
|
|
|
|
|
$userRow = User::getDataStore($email, 'email');
|
|
|
|
|
|
|
|
if(!$userRow) {
|
2018-11-20 23:41:00 +01:00
|
|
|
throw new RequestException(ERRORS::INVALID_EMAIL);
|
2016-12-22 07:07:06 +01:00
|
|
|
}
|
2018-09-28 00:46:30 +02:00
|
|
|
|
2016-12-22 07:07:06 +01:00
|
|
|
if($userRow->verificationToken !== $token) {
|
2018-11-20 23:41:00 +01:00
|
|
|
throw new RequestException(ERRORS::INVALID_TOKEN);
|
2016-12-22 07:07:06 +01:00
|
|
|
}
|
2018-09-28 00:46:30 +02:00
|
|
|
|
2016-12-22 07:07:06 +01:00
|
|
|
$userRow->verificationToken = null;
|
|
|
|
$userRow->store();
|
2018-09-28 00:46:30 +02:00
|
|
|
|
2016-12-22 07:07:06 +01:00
|
|
|
Response::respondSuccess();
|
|
|
|
}
|
2018-09-28 00:46:30 +02:00
|
|
|
}
|