| Server IP : 37.9.174.138 / Your IP : 216.73.216.117 Web Server : Apache System : Linux vps6.backend.sk 6.12.100+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.100-1 (2026-07-30) x86_64 User : ftpuser ( 1001) PHP Version : 8.4.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/backend-accounting.sk/app/admin/api/ |
Upload File : |
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of ApiClass
*
* @author Maroš
*/
namespace admin\api;
class Users extends \app\classes\AdminApiClass {
public function __construct() {
$this->requiresAuth = false;
parent::__construct();
}
/**
* @includeInDoc false
* @requestMethod "POST"
* @RequiredPostParameters ["email", "password", "first_name", "last_name", "password_retype", "g-recaptcha-response"]
*/
public function register() {
try {
$this->restApi->verifyCaptcha($this->urlReader->getPost("g-recaptcha-response"));
$user = \app\classes\AdminUser::newUser($this->urlReader->getPost());
$this->restApi->setCustomMessage("Registrácia prebehla úspešne.");
} catch (\Exception $ex) {
if ($ex->getCode() === 1062) {
$this->restApi->setCode(\app\constants\ResponseCodes::ALREADY_EXISTS);
$this->restApi->setHttpResponseCode(\app\constants\ResponseCodes::ALREADY_EXISTS);
$this->restApi->setCustomMessage("Administrátor s touto e-mailovou adresou už existuje.");
} else {
throw new \Exception($ex->getMessage(), $ex->getCode(), $ex->getPrevious());
}
}
}
/**
* @includeInDoc false
* @requestMethod "POST"
* @RequiredPostParameters ["email", "password", "g-recaptcha-response"]
*/
public function login() {
try {
$this->restApi->verifyCaptcha($this->urlReader->getPost("g-recaptcha-response"));
$user = new \app\classes\AdminUser($this->urlReader->getPost("email"));
$login = $user->login($this->urlReader->getPost("password"));
if ($login === false) {
throw new \Exception("Login failed");
}
$this->restApi->ajaxResponse(array("logged" => true));
} catch (\Exception $ex) {
$this->restApi->setCode(\app\constants\ResponseCodes::LOGIN_FAILED);
$this->restApi->setHttpResponseCode(\app\constants\ResponseCodes::LOGIN_FAILED);
$this->restApi->ajaxResponse(array("logged" => false));
}
}
/**
* @includeInDoc false
* @requestMethod "POST"
* @RequiredPostParameters ["email"]
*/
public function forgottenPassword() {
try {
$this->restApi->verifyCaptcha($this->urlReader->getPost("g-recaptcha-response"));
$user = new \app\classes\AdminUser($this->urlReader->getPost("email"));
$domain = $this->app->getConfig(\app\constants\Config::DOMAIN);
$translator = \app\classes\Translator::getInstance();
$header = array(
'From: "' . $domain . '" <forgotten.password@' . $domain . '>',
'Reply-To: "No Reply" <noreply@' . $domain . '>',
"MIME-Version: 1.0",
"Content-type:text/html;charset=UTF-8"
);
$headers = implode("\r\n", $header);
$msg = $translator->convertVarsText($translator->_get("email-admin_forgotten_password_confirmation"), array(
"link" => array(
"translate" => false,
"value" => $this->app->getBaseUrl() . "admin/forgotten-password/" . $user->_get("email") . "/" . md5($user->_get("last_login") . $this->app->getSecret() . $user->_get("email")) . md5($user->_get("secret") . $this->app->getSecret()) . "/"
)
));
// if (strlen(trim($user->_get("email_override"))) > 0) {
$this->app->sendEmailNative($user->_get("email"), $translator->_get("Admin - forgotten password"), $msg, $headers);
// }
$this->restApi->ajaxResponse();
} catch (\Exception $ex) {
$this->restApi->ajaxResponse();
}
}
/**
* @includeInDoc false
* @requestMethod "POST"
* @RequiredPostParameters []
*/
public function forgottenPasswordConfirm() {
try {
$this->restApi->verifyCaptcha($this->urlReader->getPost("g-recaptcha-response"));
$user = new \app\classes\AdminUser($this->urlReader->getPost("email"));
if ($this->urlReader->getPost("email") === false || $this->urlReader->getPost("token") === false || md5($user->_get("last_login") . $this->app->getSecret() . $user->_get("email")) . md5($user->_get("secret") . $this->app->getSecret()) !== $this->urlReader->getPost("token")) {
throw new \Exception(\app\constants\ResponseCodes::UNAUTHORIZED, \app\constants\ResponseCodes::UNAUTHORIZED);
}
$password = generateRandomString(12) . rand(0, 9) . rand(0, 9);
$user->update(array(
"password" => password_hash($password, PASSWORD_BCRYPT),
"secret" => generateRandomString(40)
));
$domain = $this->app->getConfig(\app\constants\Config::DOMAIN);
$translator = \app\classes\Translator::getInstance();
$header = array(
'From: "' . $domain . '" <forgotten.password@' . $domain . '>',
'Reply-To: "No Reply" <noreply@' . $domain . '>',
"MIME-Version: 1.0",
"Content-type:text/html;charset=UTF-8"
);
$headers = implode("\r\n", $header);
$msg = $translator->convertVarsText($translator->_get("email-admin_new_password"), array(
"password" => array(
"translate" => false,
"value" => $password
)
));
if (strlen(trim($user->_get("email_override"))) > 0) {
$this->app->sendEmailNative($user->_get("email"), $translator->_get("Admin - new password"), $msg, $headers);
}
$this->restApi->ajaxResponse();
} catch (\Exception $ex) {
$this->restApi->setHttpResponseCode(\app\constants\HttpReponseCodes::HTTP_UNAUTHORIZED);
$this->restApi->setCode(\app\constants\HttpReponseCodes::HTTP_UNAUTHORIZED);
$this->restApi->setErrorReason("Error");
$this->restApi->setCustomMessage("Odkaz pre obnovenie hesla je neplatný. Heslo sa nepodarilo obnoviť. Opätovne požiadajte o zmenu hesla a skúste znova.");
$this->restApi->ajaxResponse();
}
}
}