403Webshell
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/app/classes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/backend-accounting.sk/app/app/classes/BasicUser.php
<?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.
 */

namespace app\classes;

/**
 * Description of BasicUser
 *
 * @author Maroš
 */
class BasicUser extends User {

    public function __construct($email, $idAsEmail = false, $allow_deleted = false, $allow_disabled = false, $types = array()) {
        parent::__construct("users", $email, $idAsEmail ? "id" : "email", $allow_deleted, $allow_disabled, $types);
        $this->uniqueColumn = array("email");
    }

    /**
     * @return \app\classes\BasicUser
     */
    public static function getLoggedUser($types = array()) {
        if (self::$loggedUser === NULL || (count($types) > 0 && !in_array(self::$loggedUser->_get("type"), $types))) {
            if (isset($_SESSION["basicUser"])) {
                self::$loggedUser = new BasicUser($_SESSION["basicUser"], false, false, false, $types);
                return self::$loggedUser;
            }

            try {
                if (!isset(getallheaders()["Authorization"])) {
                    throw new \Exception(false, \app\constants\ResponseCodes::UNAUTHORIZED);
                }
                $token = getallheaders()["Authorization"];
                $tokenParse = explode("|", $token);
                if (count($tokenParse) !== 2) {
                    throw new \Exception(false, \app\constants\ResponseCodes::INVALID_AUTH_TOKEN);
                }

                $user = new \app\classes\BasicUser($tokenParse[0]);

                if ($user->authorize($token) === false) {
                    throw new \Exception(false, \app\constants\ResponseCodes::INVALID_AUTH_TOKEN);
                }
                self::$loggedUser = $user;
            } catch (\Exception $ex) {
                throw new \Exception(false, \app\constants\ResponseCodes::INVALID_AUTH_TOKEN);
            }

            throw new \Exception(false, \app\constants\ResponseCodes::UNAUTHORIZED);
        }
        return self::$loggedUser;
    }

    /**
     * @return \app\classes\AdminUser
     */
    public static function newUser($data, $additionalData = array()) {

        if (!filter_var($data["email"], FILTER_VALIDATE_EMAIL)) {
            throw new \Exception("Neplatný e-mail", \app\constants\ResponseCodes::INVALID_EMAIL);
        }

        if (strlen($data["password"]) < 8 || !preg_match("#[0-9]+#", $data["password"]) || is_numeric($data["password"])) {
            throw new \Exception(false, \app\constants\ResponseCodes::INVALID_PASSWORD);
        }

        if ($data["password"] !== $data["password_retype"]) {
            throw new \Exception(false, \app\constants\ResponseCodes::PASSWORD_MISMATCH);
        }

        $userData["state"] = $data["state"];
        $userData["first_name"] = $data["first_name"];
        $userData["last_name"] = $data["last_name"];
        $userData["email"] = trim($data["email"]);
        $userData["type"] = $data["type"];
        $userData["registration_ip"] = get_ip_address();
        $userData["folder"] = getUniqueId();
        $userData["password"] = password_hash($data["password"], PASSWORD_BCRYPT);
        $userData["secret"] = generateRandomString(40);
        $db = PDODatabase::getInstance();
        $db->addRecord("users", $userData + $additionalData);
        return new BasicUser($userData["email"], false, false, true);
    }

    public function login($password) {
        $loginResult = parent::login($password);
        if ($loginResult !== false) {
            $_SESSION["basicUser"] = $this->_get("email");
            $_SESSION["email"] = $this->_get("email");
            $_SESSION["type"] = $this->_get("type");

            if ($this->_get("type") === \app\constants\UserType::ADMIN) {
                $_SESSION["adminUser"] = $this->_get("email");
            }
        }
        return $loginResult;
    }

    public function getEmail() {
        return $this->_get("email");
    }

    public function getType() {
        return $this->_get("type");
    }

    /**
     * Consultant role from users.role. Returns null for non-consultants and consultants without a role.
     *
     * @return string|null
     */
    public function getRole() {
        if ($this->_get("type") !== \app\constants\UserType::CONSULTANT) {
            return null;
        }

        $role = $this->_get("role");
        if ($role === null || $role === '') {
            return null;
        }

        return (string) $role;
    }

    public function getId() {
        return $this->_get("id");
    }

    public function getName($color = false, $avatar = false) {
        $name = $this->_get("last_name") . " " . $this->_get("first_name");
        if ($avatar) {
            $name = '<i class="fa fa-user"></i> ' . $name;
        }
        if ($color) {
            $name = '<span style="color: ' . $this->_get('color') . '">' . $name . '</span>';
        }

        return $name;
    }

    /**
     * @return ?\modules\quirk\code\Customer
     */
    public function getExtendedUser() {
        if (class_exists('\modules\quirk\code\ExtendedUser')) {
            return new \modules\quirk\code\ExtendedUser($this);
        }

        return null;
    }

    /**
     * @return ?\modules\quirk\code\Customer
     */
    public function getCustomer($throwEx = false) {
        if (class_exists('\modules\quirk\code\Customer') && $this->_get("type") === \app\constants\UserType::CUSTOMER) {
            return new \modules\quirk\code\Customer($this);
        }

        if ($throwEx) {
            $t = Translator::getInstance();
            throw new \Exception($t->_get('Nemáte oprávnenie na vykonanie tejto akcie!', \app\constants\HttpReponseCodes::HTTP_UNAUTHORIZED));
        }

        return null;
    }

    /**
     * @return ?\modules\quirk\code\Consultant
     */
    public function getConsultant($throwEx = false) {
        if (class_exists('\modules\quirk\code\Consultant') && $this->_get("type") === \app\constants\UserType::CONSULTANT) {
            return new \modules\quirk\code\Consultant($this);
        }

        if ($throwEx) {
            $t = Translator::getInstance();
            throw new \Exception($t->_get('Nemáte oprávnenie na vykonanie tejto akcie!', \app\constants\HttpReponseCodes::HTTP_UNAUTHORIZED));
        }

        return null;
    }   
}

Youez - 2016 - github.com/yon3zu
LinuXploit