Guillermo - add path /user/verify [skip ci]

This commit is contained in:
AntonyAntonio 2016-12-22 03:07:06 -03:00
parent 70a341176f
commit 5c2f482c10
6 changed files with 49 additions and 4 deletions

View File

@ -14,6 +14,7 @@ include 'user/delete.php';
include 'user/ban.php';
include 'user/un-ban.php';
include 'user/list-ban.php';
include 'user/verify.php';
$userControllers = new ControllerGroup();
$userControllers->setGroupPath('/user');
@ -33,4 +34,5 @@ $userControllers->addController(new DeleteUserController);
$userControllers->addController(new BanUserController);
$userControllers->addController(new UnBanUserController);
$userControllers->addController(new ListBanUserController);
$userControllers->addController(new VerifyController);
$userControllers->finalize();

View File

@ -26,7 +26,7 @@ class LoginController extends Controller {
$this->userInstance->lastLogin = Date::getCurrentDate();
$this->userInstance->store();
}
Response::respondSuccess($this->getUserData());
} else {
Response::respondError(ERRORS::INVALID_CREDENTIALS);

View File

@ -68,13 +68,16 @@ class SignUpController extends Controller {
public function createNewUserAndRetrieveId() {
$userInstance = new User();
$token = Hashing::generateRandomToken();
$userInstance->setProperties([
'name' => $this->userName,
'signupDate' => Date::getCurrentDate(),
'tickets' => 0,
'email' => $this->userEmail,
'password' => Hashing::hashPassword($this->userPassword)
'password' => Hashing::hashPassword($this->userPassword),
'verificationToken' => $token
]);
return $userInstance->store();

View File

@ -0,0 +1,38 @@
<?php
use Respect\Validation\Validator as DataValidator;
class VerifyController extends Controller{
const PATH = '/verify';
public function validations() {
return [
'permission' => 'any',
'requestData' => [
'email' => [
'validation' => DataValidator::email(),
'error' => ERRORS::INVALID_EMAIL
]
]
];
}
public function handler() {
$email = Controller::request('email');
$token = Controller::request('token');
$userRow = User::getDataStore($email, 'email');
if(!$userRow) {
Response::respondError(ERRORS::INVALID_EMAIL);
return;
}
if($userRow->verificationToken !== $token) {
Response::respondError(ERRORS::INVALID_TOKEN);
return;
}
$userRow->verificationToken = null;
$userRow->store();
Response::respondSuccess();
}
}

View File

@ -30,4 +30,5 @@ class ERRORS {
const ALREADY_A_STAFF = 'ALREADY_A_STAFF';
const INVALID_STAFF = 'INVALID_STAFF';
const SAME_DEPARTMENT = 'SAME_DEPARTMENT';
const INVALID_TOKEN = 'INVALID_TOKEN';
}

View File

@ -17,7 +17,8 @@ class User extends DataStore {
'name',
'signupDate',
'tickets',
'sharedTicketList'
'sharedTicketList',
'verificationToken'
];
}