Use own exception class

This commit is contained in:
Ivan Diaz 2018-11-20 19:41:00 -03:00
parent 77a388e225
commit ace895a4a2
51 changed files with 80 additions and 76 deletions

View File

@ -55,7 +55,7 @@ class EditArticleController extends Controller {
if (!$newArticleTopic->isNull()) { if (!$newArticleTopic->isNull()) {
$article->topic = $newArticleTopic; $article->topic = $newArticleTopic;
} else { } else {
Response::respondError(ERRORS::INVALID_TOPIC); throw new RequestException(ERRORS::INVALID_TOPIC);
return; return;
} }
} }

View File

@ -97,7 +97,7 @@ class AddStaffController extends Controller {
return; return;
} }
Response::respondError(ERRORS::ALREADY_A_STAFF); throw new RequestException(ERRORS::ALREADY_A_STAFF);
} }
public function storeRequestData() { public function storeRequestData() {

View File

@ -54,22 +54,22 @@ class AssignStaffController extends Controller {
$this->staffToAssign = Staff::getDataStore($staffId, 'id'); $this->staffToAssign = Staff::getDataStore($staffId, 'id');
if($this->staffToAssign->isNull()) { if($this->staffToAssign->isNull()) {
throw new Exception(ERRORS::INVALID_STAFF); throw new RequestException(ERRORS::INVALID_STAFF);
} }
if(!$this->staffToAssign->sharedDepartmentList->includesId($this->ticket->department->id)) { if(!$this->staffToAssign->sharedDepartmentList->includesId($this->ticket->department->id)) {
throw new Exception(ERRORS::INVALID_DEPARTMENT); throw new RequestException(ERRORS::INVALID_DEPARTMENT);
} }
} else { } else {
$this->staffToAssign = Controller::getLoggedUser(); $this->staffToAssign = Controller::getLoggedUser();
} }
if($this->ticket->owner) { if($this->ticket->owner) {
throw new Exception(ERRORS::TICKET_ALREADY_ASSIGNED); throw new RequestException(ERRORS::TICKET_ALREADY_ASSIGNED);
} }
if(!$this->ticketHasStaffDepartment()) { if(!$this->ticketHasStaffDepartment()) {
throw new Exception(ERRORS::INVALID_DEPARTMENT); throw new RequestException(ERRORS::INVALID_DEPARTMENT);
} else { } else {
$this->staffToAssign->sharedTicketList->add($this->ticket); $this->staffToAssign->sharedTicketList->add($this->ticket);
$this->ticket->owner = $this->staffToAssign; $this->ticket->owner = $this->staffToAssign;

View File

@ -46,7 +46,7 @@ class DeleteStaffController extends Controller {
$staff = Staff::getDataStore($staffId); $staff = Staff::getDataStore($staffId);
if($staffId === Controller::getLoggedUser()->id) { if($staffId === Controller::getLoggedUser()->id) {
Response::respondError(ERRORS::INVALID_STAFF); throw new RequestException(ERRORS::INVALID_STAFF);
return; return;
} }

View File

@ -63,11 +63,11 @@ class EditStaffController extends Controller {
$this->staffInstance = Staff::getDataStore($staffId, 'id'); $this->staffInstance = Staff::getDataStore($staffId, 'id');
if($this->staffInstance->isNull()) { if($this->staffInstance->isNull()) {
Response::respondError(ERRORS::INVALID_STAFF); throw new RequestException(ERRORS::INVALID_STAFF);
return; return;
} }
} else { } else {
Response::respondError(ERRORS::NO_PERMISSION); throw new RequestException(ERRORS::NO_PERMISSION);
return; return;
} }

View File

@ -65,7 +65,7 @@ class UnAssignStaffController extends Controller {
$ticket->store(); $ticket->store();
Response::respondSuccess(); Response::respondSuccess();
} else { } else {
throw new Exception(ERRORS::NO_PERMISSION); throw new RequestException(ERRORS::NO_PERMISSION);
} }
} }
} }

View File

@ -57,7 +57,7 @@ class AddAPIKeyController extends Controller {
$apiInstance->store(); $apiInstance->store();
Response::respondSuccess($token); Response::respondSuccess($token);
} else { } else {
Response::respondError(ERRORS::NAME_ALREADY_USED); throw new RequestException(ERRORS::NAME_ALREADY_USED);
} }
} }

View File

@ -31,7 +31,7 @@ class CheckRequirementsController extends Controller {
public function handler() { public function handler() {
if(InstallationDoneController::isInstallationDone()) { if(InstallationDoneController::isInstallationDone()) {
throw new Exception(ERRORS::INIT_SETTINGS_DONE); throw new RequestException(ERRORS::INIT_SETTINGS_DONE);
} }
Response::respondSuccess([ Response::respondSuccess([

View File

@ -36,7 +36,7 @@ class CSVImportController extends Controller {
$fileUploader = $this->uploadFile(true); $fileUploader = $this->uploadFile(true);
if(!$fileUploader instanceof FileUploader) { if(!$fileUploader instanceof FileUploader) {
throw new Exception(ERRORS::INVALID_FILE); throw new RequestException(ERRORS::INVALID_FILE);
} }
$file = fopen($fileUploader->getFullFilePath(),'r'); $file = fopen($fileUploader->getFullFilePath(),'r');

View File

@ -37,7 +37,7 @@ class DeleteAllUsersController extends Controller {
$password = Controller::request('password'); $password = Controller::request('password');
if(!Hashing::verifyPassword($password, Controller::getLoggedUser()->password)) { if(!Hashing::verifyPassword($password, Controller::getLoggedUser()->password)) {
Response::respondError(ERRORS::INVALID_PASSWORD); throw new RequestException(ERRORS::INVALID_PASSWORD);
return; return;
} }

View File

@ -44,7 +44,7 @@ class DeleteAPIKeyController extends Controller {
$keyInstance = APIKey::getDataStore($name, 'name'); $keyInstance = APIKey::getDataStore($name, 'name');
if($keyInstance->isNull()) { if($keyInstance->isNull()) {
Response::respondError(ERRORS::INVALID_NAME); throw new RequestException(ERRORS::INVALID_NAME);
return; return;
} }

View File

@ -53,7 +53,7 @@ class DeleteDepartmentController extends Controller {
$this->transferDepartmentId = Controller::request('transferDepartmentId'); $this->transferDepartmentId = Controller::request('transferDepartmentId');
if ($this->departmentId === $this->transferDepartmentId) { if ($this->departmentId === $this->transferDepartmentId) {
Response::respondError(ERRORS::SAME_DEPARTMENT); throw new RequestException(ERRORS::SAME_DEPARTMENT);
return; return;
} }

View File

@ -36,7 +36,7 @@ class DisableRegistrationController extends Controller {
$password = Controller::request('password'); $password = Controller::request('password');
if(!Hashing::verifyPassword($password, Controller::getLoggedUser()->password)) { if(!Hashing::verifyPassword($password, Controller::getLoggedUser()->password)) {
Response::respondError(ERRORS::INVALID_PASSWORD); throw new RequestException(ERRORS::INVALID_PASSWORD);
return; return;
} }

View File

@ -37,12 +37,12 @@ class DisableUserSystemController extends Controller {
$password = Controller::request('password'); $password = Controller::request('password');
if(!Hashing::verifyPassword($password, Controller::getLoggedUser()->password)) { if(!Hashing::verifyPassword($password, Controller::getLoggedUser()->password)) {
throw new Exception(ERRORS::INVALID_PASSWORD); throw new RequestException(ERRORS::INVALID_PASSWORD);
} }
if(!Controller::isUserSystemEnabled()) { if(!Controller::isUserSystemEnabled()) {
throw new Exception(ERRORS::SYSTEM_USER_IS_ALREADY_DISABLED); throw new RequestException(ERRORS::SYSTEM_USER_IS_ALREADY_DISABLED);
} }
$userSystemEnabled = Setting::getSetting('user-system-enabled'); $userSystemEnabled = Setting::getSetting('user-system-enabled');

View File

@ -74,7 +74,7 @@ class EditMailTemplateController extends Controller {
$mailTemplate = MailTemplate::findOne(' language = ? AND template = ?', [$this->language, $this->templateType]); $mailTemplate = MailTemplate::findOne(' language = ? AND template = ?', [$this->language, $this->templateType]);
if($mailTemplate->isNull()) { if($mailTemplate->isNull()) {
throw new Exception(ERRORS::INVALID_TEMPLATE); throw new RequestException(ERRORS::INVALID_TEMPLATE);
} }
$this->validateReplacements(); $this->validateReplacements();
@ -96,21 +96,21 @@ class EditMailTemplateController extends Controller {
$this->getReplacementStrings($originalText[1]), $this->getReplacementStrings($originalText[1]),
$this->getReplacementStrings($this->texts[0]) $this->getReplacementStrings($this->texts[0])
)) { )) {
throw new Exception(ERRORS::INVALID_TEXT_1); throw new RequestException(ERRORS::INVALID_TEXT_1);
} }
if(!$this->includes( if(!$this->includes(
$this->getReplacementStrings($originalText[2]), $this->getReplacementStrings($originalText[2]),
$this->getReplacementStrings($this->texts[1]) $this->getReplacementStrings($this->texts[1])
)) { )) {
throw new Exception(ERRORS::INVALID_TEXT_2); throw new RequestException(ERRORS::INVALID_TEXT_2);
} }
if(!$this->includes( if(!$this->includes(
$this->getReplacementStrings($originalText[3]), $this->getReplacementStrings($originalText[3]),
$this->getReplacementStrings($this->texts[2]) $this->getReplacementStrings($this->texts[2])
)) { )) {
throw new Exception(ERRORS::INVALID_TEXT_3); throw new RequestException(ERRORS::INVALID_TEXT_3);
} }
} }

View File

@ -75,7 +75,7 @@ class EditSettingsController extends Controller {
$supported = json_decode(Controller::request('supportedLanguages')); $supported = json_decode(Controller::request('supportedLanguages'));
if (array_diff($supported, $allowed)) { if (array_diff($supported, $allowed)) {
throw new Exception(ERRORS::INVALID_SUPPORTED_LANGUAGES); throw new RequestException(ERRORS::INVALID_SUPPORTED_LANGUAGES);
} }
foreach(Language::LANGUAGES as $languageCode) { foreach(Language::LANGUAGES as $languageCode) {

View File

@ -37,7 +37,7 @@ class EnableRegistrationController extends Controller {
$password = Controller::request('password'); $password = Controller::request('password');
if(!Hashing::verifyPassword($password,Controller::getLoggedUser()->password)) { if(!Hashing::verifyPassword($password,Controller::getLoggedUser()->password)) {
Response::respondError(ERRORS::INVALID_PASSWORD); throw new RequestException(ERRORS::INVALID_PASSWORD);
return; return;
} }

View File

@ -37,12 +37,12 @@ class EnableUserSystemController extends Controller {
$password = Controller::request('password'); $password = Controller::request('password');
if(!Hashing::verifyPassword($password, Controller::getLoggedUser()->password)) { if(!Hashing::verifyPassword($password, Controller::getLoggedUser()->password)) {
throw new Exception(ERRORS::INVALID_PASSWORD); throw new RequestException(ERRORS::INVALID_PASSWORD);
} }
if(Controller::isUserSystemEnabled()) { if(Controller::isUserSystemEnabled()) {
throw new Exception(ERRORS::SYSTEM_USER_IS_ALREADY_ENABLED); throw new RequestException(ERRORS::SYSTEM_USER_IS_ALREADY_ENABLED);
} }
$userSystemEnabled = Setting::getSetting('user-system-enabled'); $userSystemEnabled = Setting::getSetting('user-system-enabled');

View File

@ -49,7 +49,7 @@ class GetMailTemplateController extends Controller {
$mailTemplate = MailTemplate::findOne(' language = ? AND template = ?', [$language, $type]); $mailTemplate = MailTemplate::findOne(' language = ? AND template = ?', [$language, $type]);
if($mailTemplate->isNull()) { if($mailTemplate->isNull()) {
throw new Exception(ERRORS::INVALID_TEMPLATE); throw new RequestException(ERRORS::INVALID_TEMPLATE);
} }
Response::respondSuccess($mailTemplate->toArray()); Response::respondSuccess($mailTemplate->toArray());

View File

@ -48,7 +48,7 @@ class GetStatsController extends Controller {
if($staffId) { if($staffId) {
if($staffId !== Controller::getLoggedUser()->id && !Controller::isStaffLogged(3)) { if($staffId !== Controller::getLoggedUser()->id && !Controller::isStaffLogged(3)) {
Response::respondError(ERRORS::NO_PERMISSION); throw new RequestException(ERRORS::NO_PERMISSION);
return; return;
} }

View File

@ -53,7 +53,7 @@ class InitAdminController extends Controller {
public function handler() { public function handler() {
if(!Staff::isTableEmpty()) { if(!Staff::isTableEmpty()) {
throw new Exception(ERRORS::INIT_SETTINGS_DONE); throw new RequestException(ERRORS::INIT_SETTINGS_DONE);
} }
$staff = new Staff(); $staff = new Staff();

View File

@ -40,7 +40,7 @@ class InitDatabaseController extends Controller {
public function handler() { public function handler() {
if(defined('MYSQL_HOST')) { if(defined('MYSQL_HOST')) {
throw new Exception(ERRORS::INIT_SETTINGS_DONE); throw new RequestException(ERRORS::INIT_SETTINGS_DONE);
} }
$dbHost = Controller::request('dbHost'); $dbHost = Controller::request('dbHost');
@ -56,7 +56,7 @@ class InitDatabaseController extends Controller {
RedBean::selectDatabase($dbName); RedBean::selectDatabase($dbName);
if(!RedBean::testConnection()) { if(!RedBean::testConnection()) {
throw new Exception(ERRORS::DATABASE_CONNECTION); throw new RequestException(ERRORS::DATABASE_CONNECTION);
} }
} else { } else {
$dbName = 'opensupports_' . Hashing::generateRandomNumber(100, 999); $dbName = 'opensupports_' . Hashing::generateRandomNumber(100, 999);
@ -65,7 +65,7 @@ class InitDatabaseController extends Controller {
RedBean::selectDatabase($dbName); RedBean::selectDatabase($dbName);
if(!RedBean::testConnection()) { if(!RedBean::testConnection()) {
throw new Exception(ERRORS::DATABASE_CREATION); throw new RequestException(ERRORS::DATABASE_CREATION);
} }
} }

View File

@ -59,7 +59,7 @@ class InitSettingsController extends Controller {
Response::respondSuccess(); Response::respondSuccess();
} else { } else {
Response::respondError(ERRORS::INIT_SETTINGS_DONE); throw new RequestException(ERRORS::INIT_SETTINGS_DONE);
} }
} }

View File

@ -51,7 +51,7 @@ class RecoverMailTemplateController extends Controller {
$mailTemplate = MailTemplate::findOne(' language = ? AND template = ?', [$language, $templateType]); $mailTemplate = MailTemplate::findOne(' language = ? AND template = ?', [$language, $templateType]);
if($mailTemplate->isNull()) { if($mailTemplate->isNull()) {
throw new Exception(ERRORS::INVALID_TEMPLATE); throw new RequestException(ERRORS::INVALID_TEMPLATE);
} }
$mailTexts = MailTexts::getTexts()[$language][$templateType]; $mailTexts = MailTexts::getTexts()[$language][$templateType];

View File

@ -48,7 +48,7 @@ class TestSMTPController extends Controller {
if($mailSender->isConnected()) { if($mailSender->isConnected()) {
Response::respondSuccess(); Response::respondSuccess();
} else { } else {
throw new Exception(ERRORS::SMTP_CONNECTION); throw new RequestException(ERRORS::SMTP_CONNECTION);
} }
} }
} }

View File

@ -53,7 +53,7 @@ class ChangeDepartmentController extends Controller {
$user = Controller::getLoggedUser(); $user = Controller::getLoggedUser();
if($ticket->owner && $ticket->owner->id !== $user->id && $user->level == 1){ if($ticket->owner && $ticket->owner->id !== $user->id && $user->level == 1){
throw new Exception(ERRORS::NO_PERMISSION); throw new RequestException(ERRORS::NO_PERMISSION);
} }
$event = Ticketevent::getEvent(Ticketevent::DEPARTMENT_CHANGED); $event = Ticketevent::getEvent(Ticketevent::DEPARTMENT_CHANGED);

View File

@ -65,7 +65,7 @@ class ChangePriorityController extends Controller {
Log::createLog('PRIORITY_CHANGED', $ticket->ticketNumber); Log::createLog('PRIORITY_CHANGED', $ticket->ticketNumber);
Response::respondSuccess(); Response::respondSuccess();
} else { } else {
Response::respondError(ERRORS::NO_PERMISSION); throw new RequestException(ERRORS::NO_PERMISSION);
} }
} }

View File

@ -55,7 +55,7 @@ class CheckTicketController extends Controller {
public function handler() { public function handler() {
if (Controller::isUserSystemEnabled() || Controller::isStaffLogged()) { if (Controller::isUserSystemEnabled() || Controller::isStaffLogged()) {
throw new Exception(ERRORS::NO_PERMISSION); throw new RequestException(ERRORS::NO_PERMISSION);
} }
$email = Controller::request('email'); $email = Controller::request('email');
@ -70,7 +70,7 @@ class CheckTicketController extends Controller {
'ticketNumber' => $ticket->ticketNumber 'ticketNumber' => $ticket->ticketNumber
]); ]);
} else { } else {
throw new Exception(ERRORS::NO_PERMISSION); throw new RequestException(ERRORS::NO_PERMISSION);
} }
} }
} }

View File

@ -67,7 +67,7 @@ class CloseController extends Controller {
!$this->ticket->isOwner(Controller::getLoggedUser()) && !$this->ticket->isOwner(Controller::getLoggedUser()) &&
!$this->ticket->isAuthor(Controller::getLoggedUser()) !$this->ticket->isAuthor(Controller::getLoggedUser())
) { ) {
throw new Exception(ERRORS::NO_PERMISSION); throw new RequestException(ERRORS::NO_PERMISSION);
} }
$this->markAsUnread(); $this->markAsUnread();

View File

@ -83,7 +83,7 @@ class CommentController extends Controller {
$isOwner = $this->ticket->isOwner(Controller::getLoggedUser()); $isOwner = $this->ticket->isOwner(Controller::getLoggedUser());
if((Controller::isUserSystemEnabled() || Controller::isStaffLogged()) && !$isOwner && !$isAuthor) { if((Controller::isUserSystemEnabled() || Controller::isStaffLogged()) && !$isOwner && !$isAuthor) {
throw new Exception(ERRORS::NO_PERMISSION); throw new RequestException(ERRORS::NO_PERMISSION);
} }
$this->storeComment(); $this->storeComment();

View File

@ -45,15 +45,15 @@ class DeleteController extends Controller {
$ticketAuthor = $ticket->authorToArray(); $ticketAuthor = $ticket->authorToArray();
if($ticket->owner) { if($ticket->owner) {
throw new Exception(ERRORS::NO_PERMISSION); throw new RequestException(ERRORS::NO_PERMISSION);
} }
if(Controller::isStaffLogged() && $user->level < 3) { if(Controller::isStaffLogged() && $user->level < 3) {
throw new Exception(ERRORS::NO_PERMISSION); throw new RequestException(ERRORS::NO_PERMISSION);
} }
if(!Controller::isStaffLogged() && ($user->email !== $ticketAuthor['email'] || $ticketAuthor['staff'])) { if(!Controller::isStaffLogged() && ($user->email !== $ticketAuthor['email'] || $ticketAuthor['staff'])) {
throw new Exception(ERRORS::NO_PERMISSION); throw new RequestException(ERRORS::NO_PERMISSION);
} }
$ticket->delete(); $ticket->delete();

View File

@ -65,7 +65,7 @@ class TicketGetController extends Controller {
if(Controller::isUserSystemEnabled() || Controller::isStaffLogged()) { if(Controller::isUserSystemEnabled() || Controller::isStaffLogged()) {
if ($this->shouldDenyPermission()) { if ($this->shouldDenyPermission()) {
throw new Exception(ERRORS::NO_PERMISSION); throw new RequestException(ERRORS::NO_PERMISSION);
} else { } else {
Response::respondSuccess($this->ticket->toArray()); Response::respondSuccess($this->ticket->toArray());
} }

View File

@ -44,7 +44,7 @@ class ReOpenController extends Controller {
$this->ticket = Ticket::getByTicketNumber(Controller::request('ticketNumber')); $this->ticket = Ticket::getByTicketNumber(Controller::request('ticketNumber'));
if($this->shouldDenyPermission()) { if($this->shouldDenyPermission()) {
Response::respondError(ERRORS::NO_PERMISSION); throw new RequestException(ERRORS::NO_PERMISSION);
return; return;
} }

View File

@ -45,7 +45,7 @@ class SeenController extends Controller {
$ticket = Ticket::getByTicketNumber($ticketnumber); $ticket = Ticket::getByTicketNumber($ticketnumber);
if(!$ticket->isOwner($user) && !$ticket->isAuthor($user)) { if(!$ticket->isOwner($user) && !$ticket->isAuthor($user)) {
throw new Exception(ERRORS::NO_PERMISSION); throw new RequestException(ERRORS::NO_PERMISSION);
} }
if ($ticket->isOwner($user)) { if ($ticket->isOwner($user)) {

View File

@ -55,7 +55,7 @@ class BanUserController extends Controller {
Response::respondSuccess(); Response::respondSuccess();
} else { } else {
Response::respondError(ERRORS::ALREADY_BANNED); throw new RequestException(ERRORS::ALREADY_BANNED);
} }
} }
} }

View File

@ -44,7 +44,7 @@ class DeleteUserController extends Controller {
public function handler() { public function handler() {
if(!Controller::isUserSystemEnabled()) { if(!Controller::isUserSystemEnabled()) {
throw new Exception(ERRORS::USER_SYSTEM_DISABLED); throw new RequestException(ERRORS::USER_SYSTEM_DISABLED);
} }
$userId = Controller::request('userId'); $userId = Controller::request('userId');

View File

@ -41,7 +41,7 @@ class DisableUserController extends Controller {
public function handler() { public function handler() {
$user = User::getDataStore(Controller::request('userId')); $user = User::getDataStore(Controller::request('userId'));
if($user->disabled) { if($user->disabled) {
throw new Exception(ERRORS::ALREADY_DISABLED); throw new RequestException(ERRORS::ALREADY_DISABLED);
} }
$user->disabled = 1; $user->disabled = 1;

View File

@ -58,7 +58,7 @@ class EditPassword extends Controller {
Response::respondSuccess(); Response::respondSuccess();
} else{ } else{
Response::respondError(ERRORS::INVALID_OLD_PASSWORD); throw new RequestException(ERRORS::INVALID_OLD_PASSWORD);
} }
} }
} }

View File

@ -42,7 +42,7 @@ class EnableUserController extends Controller {
$user = User::getDataStore(Controller::request('userId')); $user = User::getDataStore(Controller::request('userId'));
if(!$user->disabled) { if(!$user->disabled) {
throw new Exception(ERRORS::ALREADY_ENABLED); throw new RequestException(ERRORS::ALREADY_ENABLED);
} }
$user->disabled = 0; $user->disabled = 0;

View File

@ -47,7 +47,7 @@ class GetUserByIdController extends Controller {
public function handler() { public function handler() {
if(!Controller::isUserSystemEnabled()) { if(!Controller::isUserSystemEnabled()) {
throw new Exception(ERRORS::USER_SYSTEM_DISABLED); throw new RequestException(ERRORS::USER_SYSTEM_DISABLED);
} }
$userId = Controller::request('userId'); $userId = Controller::request('userId');

View File

@ -54,7 +54,7 @@ class GetUsersController extends Controller {
public function handler() { public function handler() {
if(!Controller::isUserSystemEnabled()) { if(!Controller::isUserSystemEnabled()) {
throw new Exception(ERRORS::USER_SYSTEM_DISABLED); throw new RequestException(ERRORS::USER_SYSTEM_DISABLED);
} }
$userList = $this->getUserList(); $userList = $this->getUserList();

View File

@ -39,7 +39,7 @@ class GetUserController extends Controller {
public function handler() { public function handler() {
if (Controller::isStaffLogged()) { if (Controller::isStaffLogged()) {
Response::respondError(ERRORS::INVALID_CREDENTIALS); throw new RequestException(ERRORS::INVALID_CREDENTIALS);
return; return;
} }

View File

@ -51,22 +51,22 @@ class LoginController extends Controller {
public function handler() { public function handler() {
if(!Controller::isUserSystemEnabled() && !Controller::request('staff')) { if(!Controller::isUserSystemEnabled() && !Controller::request('staff')) {
throw new Exception(ERRORS::USER_SYSTEM_DISABLED); throw new RequestException(ERRORS::USER_SYSTEM_DISABLED);
} }
if ($this->isAlreadyLoggedIn()) { if ($this->isAlreadyLoggedIn()) {
throw new Exception(ERRORS::SESSION_EXISTS); throw new RequestException(ERRORS::SESSION_EXISTS);
} }
$this->clearOldRememberTokens(); $this->clearOldRememberTokens();
if ($this->checkInputCredentials() || $this->checkRememberToken()) { if ($this->checkInputCredentials() || $this->checkRememberToken()) {
if($this->userInstance->verificationToken !== null) { if($this->userInstance->verificationToken !== null) {
throw new Exception(ERRORS::UNVERIFIED_USER); throw new RequestException(ERRORS::UNVERIFIED_USER);
} }
if($this->userInstance->disabled) { if($this->userInstance->disabled) {
throw new Exception(ERRORS::USER_DISABLED); throw new RequestException(ERRORS::USER_DISABLED);
} }
$this->createUserSession(); $this->createUserSession();
@ -78,7 +78,7 @@ class LoginController extends Controller {
Response::respondSuccess($this->getUserData()); Response::respondSuccess($this->getUserData());
} else { } else {
throw new Exception(ERRORS::INVALID_CREDENTIALS); throw new RequestException(ERRORS::INVALID_CREDENTIALS);
} }
} }

View File

@ -57,7 +57,7 @@ class RecoverPasswordController extends Controller {
public function handler() { public function handler() {
if(!Controller::isUserSystemEnabled()) { if(!Controller::isUserSystemEnabled()) {
throw new Exception(ERRORS::USER_SYSTEM_DISABLED); throw new RequestException(ERRORS::USER_SYSTEM_DISABLED);
} }
$this->requestData(); $this->requestData();
@ -90,7 +90,7 @@ class RecoverPasswordController extends Controller {
$this->sendMail(); $this->sendMail();
Response::respondSuccess(['staff' => $recoverPassword->staff]); Response::respondSuccess(['staff' => $recoverPassword->staff]);
} else { } else {
Response::respondError(ERRORS::NO_PERMISSION); throw new RequestException(ERRORS::NO_PERMISSION);
} }
} }
public function sendMail() { public function sendMail() {

View File

@ -50,7 +50,7 @@ class SendRecoverPasswordController extends Controller {
public function handler() { public function handler() {
if(!Controller::isUserSystemEnabled()) { if(!Controller::isUserSystemEnabled()) {
throw new Exception(ERRORS::USER_SYSTEM_DISABLED); throw new RequestException(ERRORS::USER_SYSTEM_DISABLED);
} }
$this->staff = Controller::request('staff'); $this->staff = Controller::request('staff');
@ -77,7 +77,7 @@ class SendRecoverPasswordController extends Controller {
Response::respondSuccess(); Response::respondSuccess();
} else { } else {
Response::respondError(ERRORS::INVALID_EMAIL); throw new RequestException(ERRORS::INVALID_EMAIL);
} }
} }

View File

@ -80,7 +80,7 @@ class SignUpController extends Controller {
public function handler() { public function handler() {
if(!Controller::isUserSystemEnabled()) { if(!Controller::isUserSystemEnabled()) {
throw new Exception(ERRORS::USER_SYSTEM_DISABLED); throw new RequestException(ERRORS::USER_SYSTEM_DISABLED);
} }
$this->storeRequestData(); $this->storeRequestData();
@ -89,16 +89,16 @@ class SignUpController extends Controller {
$existentUser = User::getUser($this->userEmail, 'email'); $existentUser = User::getUser($this->userEmail, 'email');
if (!$existentUser->isNull()) { if (!$existentUser->isNull()) {
throw new Exception(ERRORS::USER_EXISTS); throw new RequestException(ERRORS::USER_EXISTS);
} }
$banRow = Ban::getDataStore($this->userEmail,'email'); $banRow = Ban::getDataStore($this->userEmail,'email');
if (!$banRow->isNull()) { if (!$banRow->isNull()) {
throw new Exception(ERRORS::ALREADY_BANNED); throw new RequestException(ERRORS::ALREADY_BANNED);
} }
if (!Setting::getSetting('registration')->value && $apiKey->isNull() && !Controller::isStaffLogged(2) && !$this->csvImported) { if (!Setting::getSetting('registration')->value && $apiKey->isNull() && !Controller::isStaffLogged(2) && !$this->csvImported) {
throw new Exception(ERRORS::NO_PERMISSION); throw new RequestException(ERRORS::NO_PERMISSION);
} }
$userId = $this->createNewUserAndRetrieveId(); $userId = $this->createNewUserAndRetrieveId();

View File

@ -43,7 +43,7 @@ class UnBanUserController extends Controller {
$banRow = Ban::getDataStore($email,'email'); $banRow = Ban::getDataStore($email,'email');
if($banRow->isNull()) { if($banRow->isNull()) {
Response::respondError(ERRORS::INVALID_EMAIL); throw new RequestException(ERRORS::INVALID_EMAIL);
} else { } else {
$banRow->delete(); $banRow->delete();

View File

@ -42,7 +42,7 @@ class VerifyController extends Controller{
public function handler() { public function handler() {
if(!Controller::isUserSystemEnabled()) { if(!Controller::isUserSystemEnabled()) {
throw new Exception(ERRORS::USER_SYSTEM_DISABLED); throw new RequestException(ERRORS::USER_SYSTEM_DISABLED);
} }
$email = Controller::request('email'); $email = Controller::request('email');
@ -51,11 +51,11 @@ class VerifyController extends Controller{
$userRow = User::getDataStore($email, 'email'); $userRow = User::getDataStore($email, 'email');
if(!$userRow) { if(!$userRow) {
throw new Exception(ERRORS::INVALID_EMAIL); throw new RequestException(ERRORS::INVALID_EMAIL);
} }
if($userRow->verificationToken !== $token) { if($userRow->verificationToken !== $token) {
throw new Exception(ERRORS::INVALID_TOKEN); throw new RequestException(ERRORS::INVALID_TOKEN);
} }
$userRow->verificationToken = null; $userRow->verificationToken = null;

View File

@ -110,7 +110,7 @@ abstract class Controller {
$allImagesValidSize = $allImagesValidSize && $fileUploader->isSizeValid($_FILES["image_$i"]); $allImagesValidSize = $allImagesValidSize && $fileUploader->isSizeValid($_FILES["image_$i"]);
} }
if(!$allImagesValidSize) throw new Exception(ERRORS::INVALID_FILE); if(!$allImagesValidSize) throw new RequestException(ERRORS::INVALID_FILE);
$imagePaths = []; $imagePaths = [];
$url = Setting::getSetting('url')->getValue(); $url = Setting::getSetting('url')->getValue();
@ -137,7 +137,7 @@ abstract class Controller {
return $fileUploader; return $fileUploader;
} else { } else {
throw new Exception(ERRORS::INVALID_FILE); throw new RequestException(ERRORS::INVALID_FILE);
} }
} }

View File

@ -0,0 +1,2 @@
<?php
class RequestException extends Exception {}

View File

@ -1,7 +1,9 @@
<?php <?php
include_once 'libs/RequestException.php';
use Respect\Validation\Validator as DataValidator; use Respect\Validation\Validator as DataValidator;
class ValidationException extends Exception {} class ValidationException extends RequestException {}
class Validator { class Validator {