'staff_1', 'requestData' => [ 'name' => [ 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), 'error' => ERRORS::INVALID_NAME ], 'email' => [ 'validation' => DataValidator::email(), 'error' => ERRORS::INVALID_EMAIL ] ] ]; $validations['requestData']['captcha'] = [ 'validation' => DataValidator::captcha(), 'error' => ERRORS::INVALID_CAPTCHA ]; return $validations; } public function handler() { $this->storeRequestData(); $existentUser = User::getUser($this->userEmail, 'email'); if (!$existentUser->isNull()) { throw new RequestException(ERRORS::USER_EXISTS); } $banRow = Ban::getDataStore($this->userEmail, 'email'); if (!$banRow->isNull()) { throw new RequestException(ERRORS::ALREADY_BANNED); } $userId = $this->createNewUserAndRetrieveId(); $this->token = Hashing::generateRandomToken(); $recoverPassword = new RecoverPassword(); $recoverPassword->setProperties(array( 'email' => $this->userEmail, 'token' => $this->token, 'staff' => false )); $recoverPassword->store(); $this->sendInvitationMail(); Response::respondSuccess([ 'userId' => $userId, 'userEmail' => $this->userEmail ]); Log::createLog('INVITE', $this->userName); } public function storeRequestData() { $this->userName = Controller::request('name', true); $this->userEmail = Controller::request('email', true); } public function createNewUserAndRetrieveId() { $userInstance = new User(); $userInstance->setProperties([ 'name' => $this->userName, 'signupDate' => Date::getCurrentDate(), 'tickets' => 0, 'email' => $this->userEmail, 'password' => Hashing::hashPassword(Hashing::generateRandomToken()), 'verificationToken' => null, 'xownCustomfieldvalueList' => $this->getCustomFieldValues() ]); return $userInstance->store(); } public function sendInvitationMail() { $mailSender = MailSender::getInstance(); $mailSender->setTemplate(MailTemplate::USER_INVITE, [ 'to' => $this->userEmail, 'name' => $this->userName, 'url' => Setting::getSetting('url')->getValue(), 'token' => $this->token ]); $mailSender->send(); } }