Example #1
0
 function login($user, $password)
 {
     include_once 'C:\\Users\\Delorian\\PhpstormProjects\\Kassa\\config.php';
     /** @var array $chaisers Массив кассиров */
     $id = null;
     for ($i = 0; $i < count($chaisers['login']); $i++) {
         if ($chaisers['login'][$i] === $user and $chaisers['password'][$i] === $password) {
             $id = $i;
             break;
         }
     }
     if ($id === null) {
         Session::set('isAuthorize', false);
         return false;
     }
     $user = [];
     $user['guid'] = $chaisers['guid'][$id];
     $user['login'] = $chaisers['login'][$id];
     $user['password'] = $chaisers['password'][$id];
     $user['fio'] = $chaisers['fio'][$id];
     $user['permissions'] = $chaisers['permissions'][$id];
     $user['groups'] = $chaisers['groups'][$id];
     /** @var array $InterfacesList */
     $user['interfacesList'] = $InterfacesList;
     $cashier = new Cashier($user);
     Session::set('cashier', $cashier);
     Session::set('isAuthorize', true);
     return true;
 }
function session($name, $value = null)
{
    if ($value) {
        return Session::set($name, $value);
    }
    return Session::get($name);
}
 public function auth()
 {
     $user = Input::get('user');
     $pasw = Input::get('password');
     $result = User::query()->where('user', '=', $user)->first();
     if (is_null($result)) {
         return Response::redirect('/login?error=login');
     }
     if ($result->password !== md5($pasw)) {
         return Response::redirect('/login?error=login');
     }
     Session::set('id', $result->id);
     return Response::redirect('/');
 }
Example #4
0
 /**
  * 微信创建账号登录
  * @see Core.Controller::initialize()
  */
 public function initialize()
 {
     $user = self::login_user();
     if (empty($user)) {
         $code = \Core\URI::kv('code');
         $v = new \Core\Validation();
         $v->required($code)->message('用户未来授权访问', 1000);
         $oauth = \WX\Platform\Oauth::init_config_params();
         if ($v->has_error()) {
             //                $oauth->to_weixin(W_DOMAIN.\Core\URI::a2p_before(), 'host_base');
             $oauth->to_weixin(W_DOMAIN . \Core\URI::a2p_before(), 'user_info');
         } else {
             $user_accesstoken = $oauth->user_accesstoken($code);
             $openid = $user_accesstoken['openid'];
             $access_token = $user_accesstoken['access_token'];
             $userinfo = $oauth->user_info();
             $row = \DB\Account\Identify::row(array('identify_name' => $openid, 'identify_type' => 4));
             if (empty($row)) {
                 $user = new \DB\Account\User();
                 $user->user_avatar = $userinfo['headimgurl'];
                 $user->user_nickname = $userinfo['nickname'];
                 $user->user_status = 1;
                 $user->user_gender = $userinfo['sex'] == 1 ? 'male' : 'female';
                 $user->create_time = W_START_TIME;
                 $user->login_time = W_START_TIME;
                 $user_id = $user->save();
                 $identify = new \DB\Account\Identify();
                 $identify->identify_name = $openid;
                 $identify->identify_level = 1;
                 $identify->create_time = W_START_TIME;
                 $identify->identify_password = $access_token;
                 $identify->user_id = $user_id;
                 $identify->identify_type = 4;
                 $identify->save();
             } else {
                 $user_id = $row->user_id;
                 $row->user->user_avatar = $userinfo['headimgurl'];
                 $row->user->user_nickname = $userinfo['nickname'];
                 $row->user->user_gender = $userinfo['sex'] == 1 ? 'male' : 'female';
                 $row->user->login_time = W_START_TIME;
                 $row->user->save();
             }
             \Core\Session::set('user_id', $user_id);
         }
     }
 }
Example #5
0
 /**
  * 登录
  */
 public function login()
 {
     $account = \Core\URI::kv('user_account');
     $password = \Core\URI::kv('user_password');
     $v = new \Core\Validation();
     $v->filter_var(filter_var($account, FILTER_VALIDATE_EMAIL))->message('邮箱帐号错误');
     if ($v->has_error()) {
         \Core\Cookie::set('error', $v->get_error('message'));
     } else {
         $gen_password = \DB\Authorize\Admin::gen_password($password);
         $row = \DB\Authorize\Admin::row(array('admin_account' => $account, 'admin_password' => $gen_password));
         //var_dump(!empty($row->admin_account));exit();
         if (!empty($row->admin_account)) {
             \Db\Log::message('登录', '', $row->admin_name);
             \Core\Session::set('admin_id', $row->admin_id);
             redirect(\Core\URI::a2p(array('order' => 'index')));
         }
     }
     redirect(\Core\URI::a2p(array('main' => 'index')));
 }
Example #6
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 #7
0
 public function wuchao()
 {
     $user_id = \Core\URI::kv('user_id', 5);
     \Core\Session::set('user_id', $user_id);
     echo "设置测试帐号:{$user_id}";
 }
 /**
  * 输出验证码并把验证码的值保存的session中
  * 验证码保存到session的格式为: array('verify_code' => '验证码值', 'verify_time' => '验证码创建时间');
  * @access public     
  * @param string $id 要生成验证码的标识   
  * @return void
  */
 public function entry($id = '')
 {
     // 图片宽(px)
     $this->imageW || ($this->imageW = $this->length * $this->fontSize * 1.5 + $this->length * $this->fontSize / 2);
     // 图片高(px)
     $this->imageH || ($this->imageH = $this->fontSize * 2.5);
     // 建立一幅 $this->imageW x $this->imageH 的图像
     $this->_image = imagecreate($this->imageW, $this->imageH);
     // 设置背景
     imagecolorallocate($this->_image, $this->bg[0], $this->bg[1], $this->bg[2]);
     // 验证码字体随机颜色
     $this->_color = imagecolorallocate($this->_image, mt_rand(1, 150), mt_rand(1, 150), mt_rand(1, 150));
     // 验证码使用随机字体
     $ttfPath = dirname(__FILE__) . '/source/verify/' . ($this->useZh ? 'zhttfs' : 'ttfs') . '/';
     if (empty($this->fontttf)) {
         $dir = dir($ttfPath);
         $ttfs = array();
         while (false !== ($file = $dir->read())) {
             if ($file[0] != '.' && substr($file, -4) == '.ttf') {
                 $ttfs[] = $file;
             }
         }
         $dir->close();
         $this->fontttf = $ttfs[array_rand($ttfs)];
     }
     $this->fontttf = $ttfPath . $this->fontttf;
     if ($this->useImgBg) {
         $this->_background();
     }
     if ($this->useNoise) {
         // 绘杂点
         $this->_writeNoise();
     }
     if ($this->useCurve) {
         // 绘干扰线
         $this->_writeCurve();
     }
     // 绘验证码
     $code = array();
     // 验证码
     $codeNX = 0;
     // 验证码第N个字符的左边距
     if ($this->useZh) {
         // 中文验证码
         for ($i = 0; $i < $this->length; $i++) {
             $code[$i] = iconv_substr($this->zhSet, floor(mt_rand(0, mb_strlen($this->zhSet, 'utf-8') - 1)), 1, 'utf-8');
             imagettftext($this->_image, $this->fontSize, mt_rand(-40, 40), $this->fontSize * ($i + 1) * 1.5, $this->fontSize + mt_rand(10, 20), $this->_color, $this->fontttf, $code[$i]);
         }
     } else {
         for ($i = 0; $i < $this->length; $i++) {
             $code[$i] = $this->codeSet[mt_rand(0, strlen($this->codeSet) - 1)];
             $codeNX += mt_rand($this->fontSize * 1.2, $this->fontSize * 1.6);
             imagettftext($this->_image, $this->fontSize, mt_rand(-40, 40), $codeNX, $this->fontSize * 1.6, $this->_color, $this->fontttf, $code[$i]);
         }
     }
     // 保存验证码
     $key = $this->authcode($this->seKey);
     $code = $this->authcode(strtoupper(implode('', $code)));
     $secode = array();
     $secode['verify_code'] = $code;
     // 把校验码保存到session
     $secode['verify_time'] = time();
     // 验证码创建时间
     Session::set($key . $id, json_encode($secode));
     header('Cache-Control: private, max-age=0, no-store, no-cache, must-revalidate');
     header('Cache-Control: post-check=0, pre-check=0', false);
     header('Pragma: no-cache');
     header("content-type: image/png");
     // 输出图像
     imagepng($this->_image);
     imagedestroy($this->_image);
 }