/** * 检查是否登录 */ function check_auth() { // 如果配置中管理员用户名密码为空则说明不用验证 if (Config\Config::$adminName == '' && Config\Config::$adminPassword == '') { return true; } // 进入验证流程 $response = \Core\Response::getInstance()->response(); $session = \Core\Session::getInstance($response); $session->start(); if (!isset($_SESSION['admin'])) { if (!isset($_POST['admin_name']) || !isset($_POST['admin_password'])) { include ST_ROOT . '/Views/login.tpl.php'; return _exit(); } else { $admin_name = $_POST['admin_name']; $admin_password = $_POST['admin_password']; if ($admin_name != Config\Config::$adminName || $admin_password != Config\Config::$adminPassword) { $msg = "用户名或者密码不正确"; include ST_ROOT . '/Views/login.tpl.php'; return _exit(); } $_SESSION['admin'] = $admin_name; $_GET['fn'] = 'main'; } } $session->save(); return true; }
/** * @test * 已经登陆的Seesion状态 */ public function user_has_login() { $request = new Simple('Get', 'Index', 'Login', 'Status'); \Core\Session::getInstance()->login = 1; $this->getApplication()->getDispatcher()->dispatch($request); $this->assertEquals(1, $this->getView()->login); }
function logout($module, $interface, $date, $start_time, $offset, $count) { $response = \Core\Response::getInstance()->response(); $session = \Core\Session::getInstance($response); $session->delete(); include ST_ROOT . '/Views/login.tpl.php'; }
/** * 判断验证码是否正确 * @param $code * @param string $id * @return bool */ public function check($code, $id = '') { $key = $this->authcode($this->key) . $id; //验证码不能为空 $session = \Core\Session::getInstance(); $res_code = $session->get($key); if (empty($code) || empty($res_code)) { return false; } //session过期 if (time() - $res_code['verify_time'] > $this->expire) { $session->set($key, null); return false; } //判断验证码是否正确 if ($this->authcode(strtoupper($code)) == $res_code['verify_code']) { $this->reset && $session->set($key, null); return true; } return false; }
/** * 查看session中是否登陆 * @url http://yourdomain/login/status */ public function StatusAction() { $this->getView()->assign('login', \Core\Session::getInstance()->get('login') ? 1 : 0); }
<?php \Core\DI::bind("App\\Models\\Game\\GameModelInterface", function () { $db = \Core\DB::getInstance(); return new \App\Models\Game\GameModel(new \App\Domain\Logic\GameLogic(new \App\Domain\Factories\ShipFactory()), new \App\Domain\Repository\Game\GameRepository(new App\Persistence\Database\GamePersistence($db), new App\Persistence\Database\ShotPersistence($db)), \Core\Session::getInstance()); });
public function getAll() { return App::getDataBase()->prepare('SELECT * FROM users WHERE usr_id != :id ORDER BY usr_login', ['id' => Session::getInstance()->read('auth')], __CLASS__); }