Ejemplo n.º 1
0
 private function __construct()
 {
     self::$curUser = new User();
     if (Service::request()->post('token')) {
         self::loadByToken(Service::request()->post('token'));
     }
 }
Ejemplo n.º 2
0
 protected function loginAction()
 {
     $user = AuthUser::getInstance();
     $request = Service::request();
     $token = $user->login($request->post('login'), $request->post('password'));
     return $token ? ['state' => true, 'token' => $token] : ['state' => false, 'msg' => 'Неверные логин/пароль'];
 }
Ejemplo n.º 3
0
<?
header('Content-Type: text/html; charset=utf-8');
require_once './src/Base/AutoLoader/AutoLoader.php';
header('Content-Type: application/json');

set_exception_handler(function (Exception $error) {
    echo json_encode(['state' => false, 'msg' => $error->getMessage()]);
});

use Base\AutoLoader\AutoLoader;
use Services\Service;

AutoLoader::init();

//минироутинг
echo \Api\Router\Router::run(Service::request()->post('action'));
Ejemplo n.º 4
0
 /**
  * Проверка типов создаваемых/редактируемых пользователей
  * @return bool
  * @throws \Exception
  */
 protected function checkUserType()
 {
     $accessTypes = [];
     $userData = Service::request()->post('userData');
     $userType = isset($userData['permission']) ? $userData['permission'] : null;
     if (Service::user()->isSuperAdmin()) {
         array_push($accessTypes, User::USER, User::ADMIN);
     } elseif (Service::user()->isAdmin()) {
         $accessTypes[] = User::USER;
     }
     if ($userType !== null && !in_array($userType, $accessTypes)) {
         throw new \Exception('Не корректные права пользователя');
     }
 }