function session($name, $value = null)
{
    if ($value) {
        return Session::set($name, $value);
    }
    return Session::get($name);
}
 /**
  * Gets the CSRF token of the current session
  *
  * @return string Returns the token
  */
 public static function getSessionToken() : string
 {
     try {
         $token = Session::get(self::CSRF_TOKEN_LABEL);
     } catch (\Exception $e) {
         $token = false;
     }
     return $token;
 }
Example #3
0
 public static function login_admin()
 {
     static $admin = NULL;
     if (empty($admin)) {
         $admin_id = \Core\Session::get('admin_id');
         if (!empty($admin_id)) {
             $admin = \DB\Authorize\Admin::row(array('admin_id' => $admin_id));
         }
     }
     return $admin;
 }
Example #4
0
 public function __construct()
 {
     require_once 'config.php';
     try {
         /** @var mixed $db2 Data Base settings from config.php */
         $this->connection = new PDO("mysql:host=" . $db2['host'] . ";dbname=" . $db2['name'], $db2['user'], $db2['password']);
         $this->connection->exec("SET NAMES utf8");
     } catch (PDOException $e) {
         echo $e->getMessage();
     }
     $this->cashier = Session::get('cashier');
 }
Example #5
0
 public static function login_user($user_id = null)
 {
     static $user = NULL;
     if (empty($user)) {
         if (is_null($user_id)) {
             $user_id = \Core\Session::get('user_id');
         }
         if (!empty($user_id)) {
             $user = \DB\Account\User::row(array('user_id' => $user_id));
         }
     }
     return $user;
 }
 /**
  * 验证验证码是否正确
  * @access public
  * @param string $code 用户验证码
  * @param string $id 验证码标识     
  * @return bool 用户验证码是否正确
  */
 public function check($code, $id = '')
 {
     $key = $this->authcode($this->seKey) . $id;
     // 验证码不能为空
     $secode = json_decode(Session::get($key), true);
     if (empty($code) || empty($secode)) {
         return false;
     }
     // session 过期
     if (time() - $secode['verify_time'] > $this->expire) {
         Session::delete($key);
         return false;
     }
     if ($this->authcode(strtoupper($code)) == $secode['verify_code']) {
         $this->reset && Session::delete($key);
         return true;
     }
     return false;
 }
Example #7
0
 public static function start()
 {
     try {
         $url_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
         $uri_parts = explode('/', trim($url_path, ' /'));
         $module = array_shift($uri_parts);
         empty($uri_parts[0]) ? $controllerName = 'Main' : ($controllerName = $uri_parts[0]);
         empty($uri_parts[1]) ? $action = 'index' : ($action = $uri_parts[1]);
         if (count($uri_parts) % 2) {
             throw new Exception('Неверное количество параметров запроса');
         }
         $params = null;
         for ($i = 2; $i < count($uri_parts); $i++) {
             $params[$uri_parts[$i]] = $uri_parts[++$i];
         }
         if ($params !== null) {
             $_REQUEST = array_merge($_REQUEST, $params);
         }
         Session::start();
         if (!array_key_exists('isAuthorize', $_SESSION)) {
             Session::set('isAuthorize', false);
         }
         if (!Session::get('isAuthorize')) {
             $controllerName = 'Login';
             $action = 'login';
             $_SERVER['REQUEST_URI'] = '/kassa/login';
         }
         $controllerName = 'controllers\\' . $controllerName . 'Controller';
         $action = $action . '_action';
         if (!class_exists($controllerName)) {
             throw new Exception('Запрашеваемой страницы не существует: ' . $controllerName);
         }
         $controller = new $controllerName();
         if (!method_exists($controller, $action)) {
             throw new Exception('Указаного действия не существует:' . $action);
         }
         $controller->{$action}();
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
Example #8
0
 public function changepw()
 {
     $password = \Core\URI::kv('password');
     $new_password = \Core\URI::kv('new_password');
     $repeat_password = \Core\URI::kv('repeat_password');
     $v = new \Core\Validation();
     $v->required($password)->message('密码');
     $v->required($new_password)->message('新密码不能为空');
     $v->filter_var($new_password == $repeat_password)->message('重复新密码不正确');
     if (!$v->has_error()) {
         $authorize_id = \Core\Session::get('authorize_id');
         $row = \DB\Authorize::row(array('authorize_id' => $authorize_id));
         $gen_password = \DB\Authorize::gen_password($password);
         if ($gen_password == $row->authorize_password) {
             $row->authorize_password = \DB\Authorize::gen_password($new_password);
             $row->save();
             $v->required(false)->message('密码修改成功,退出当前登录生效');
         } else {
             $v->required(false)->message('原始密码不正确');
         }
     }
     echo json_encode($v->get_error());
     exit;
 }
Example #9
0
 public static function get()
 {
     return static::findById(Session::get('id'));
 }
Example #10
0
 /**
  * Controller constructor.
  */
 public function __construct()
 {
     $this->view = new View();
     @($this->cashier = Session::get('cashier'));
 }