opensupports/server/controllers/user/verify.php

67 lines
1.6 KiB
PHP
Raw Normal View History

<?php
use Respect\Validation\Validator as DataValidator;
2017-04-16 07:35:04 +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
*
* @apiName Verify email
2017-04-16 07:35:04 +02:00
*
* @apiGroup User
*
* @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.
* @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
*
*/
class VerifyController extends Controller{
const PATH = '/verify';
const METHOD = 'POST';
public function validations() {
return [
'permission' => 'any',
'requestData' => [
'email' => [
'validation' => DataValidator::email(),
'error' => ERRORS::INVALID_EMAIL
]
]
];
}
public function handler() {
if(!Controller::isUserSystemEnabled()) {
2018-11-20 23:41:00 +01:00
throw new RequestException(ERRORS::USER_SYSTEM_DISABLED);
}
2018-09-28 00:46:30 +02: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);
}
2018-09-28 00:46:30 +02:00
if($userRow->verificationToken !== $token) {
2018-11-20 23:41:00 +01:00
throw new RequestException(ERRORS::INVALID_TOKEN);
}
2018-09-28 00:46:30 +02:00
$userRow->verificationToken = null;
$userRow->store();
2018-09-28 00:46:30 +02:00
Response::respondSuccess();
}
2018-09-28 00:46:30 +02:00
}