Exemple #1
0
 public function get($f3)
 {
     Ajax::header();
     $clientData = ClientDataHelper::getClientDataArray();
     if (null == $clientData) {
         $clientData = array();
     }
     echo Ajax::buildResult(null, null, json_encode($clientData));
 }
Exemple #2
0
 public function post($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['user_name'] = $validator->required('用户名不能为空')->minLength(2, '用户名最短为2个字符')->validate('user_name');
     $input['password'] = $validator->required('密码不能为空')->minLength(6, '密码最短为6个非空字符')->validate('password');
     $input['email'] = $validator->validate('email');
     $input['mobile_phone'] = $validator->digits('手机号格式不对')->validate('mobile_phone');
     $p_captcha = $validator->required('验证码不能为空')->validate('captcha');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 检查验证码是否有效
     $captchaController = new \Controller\Image\Captcha();
     if (!$captchaController->validateCaptcha($p_captcha)) {
         $this->addFlashMessage("验证码错误");
         goto out_fail;
     }
     $userService = new UserService();
     // 检查用户是否已经注册
     $isUserExist = $userService->isUserExist($input['user_name'], $input['email']);
     if ($isUserExist) {
         $this->addFlashMessage($isUserExist . '已经存在');
         goto out_fail;
     }
     // 注册用户
     $user = $userService->registerUser($input);
     if (!$user) {
         $this->addFlashMessage('用户注册失败,请稍后刷新页面重试');
         goto out_fail;
     }
     // 记录用户的登陆信息
     $userInfo = $user->toArray();
     unset($userInfo['password']);
     // 不要记录密码
     AuthHelper::saveAuthUser($userInfo, 'normal');
     // 设置用户名在网页显示
     ClientData::saveClientData(Login::$clientDataIsUserLoginKey, true);
     ClientData::saveClientData(Login::$clientDataUserNameDisplayKey, $user->user_name);
     $this->addFlashMessage("注册成功");
     // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页
     RouteHelper::jumpBack($this, '/', true);
     return;
     // 这里正常返回
     out_fail:
     // 失败,从这里出口
     $smarty->display('user_login.tpl', 'User|Register|post');
 }
Exemple #3
0
 public function afterRoute($f3)
 {
     // 使用 Cookie 输出 flash message,目的是方便页面做缓存,别把这些数据写在页面上
     if (count($this->flashMessageArray) > 0) {
         setcookie('flash_message', json_encode($this->flashMessageArray), 0, $f3->get('BASE') . '/');
     } else {
         //setcookie('flash_message', null, 0, $f3->get('BASE')); // 清除上次的旧数据
     }
     // 记录用户从什么来源到达网站的
     ReferHelper::syncOrderReferStorage($f3);
     //同步信息
     // 通知客户端数据发生了变化,让客户端主动来取数据
     ClientData::notifyClientDataChange();
     parent::afterRoute($f3);
 }
Exemple #4
0
 public function get($f3)
 {
     // 清除客户端所有数据
     ClientData::clearClientData();
     // 清除服务器端数据
     AuthHelper::removeAuthUser();
     $f3->clear('SESSION');
     $this->addFlashMessage('成功退出登陆');
     $backUrl = RouteHelper::getRefer();
     if (Utils::isBlank($backUrl)) {
         // 没有来路域名则返回首页
         $backUrl = '/';
     }
     // 刷新当前页面
     RouteHelper::reRoute($this, $backUrl, false);
 }
Exemple #5
0
 public function post($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['user_name'] = $validator->required('用户名不能为空')->validate('user_name');
     $input['password'] = $validator->required('密码不能为空')->validate('password');
     $p_captcha = $validator->required('验证码不能为空')->validate('captcha');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 检查验证码是否有效
     $captchaController = new \Controller\Image\Captcha();
     if (!$captchaController->validateCaptcha($p_captcha)) {
         $this->addFlashMessage("验证码错误");
         goto out_fail;
     }
     $userService = new UserService();
     // 验证用户登陆
     $user = $userService->doAuthUser($input['user_name'], $input['user_name'], $input['password']);
     if (!$user) {
         $this->addFlashMessage("登陆失败,用户名、密码错误");
         goto out_fail;
     }
     // 记录用户的登陆信息
     $userInfo = $user->toArray();
     unset($userInfo['password']);
     // 不要记录密码
     AuthHelper::saveAuthUser($userInfo, 'normal');
     // 设置用户名在网页显示
     ClientData::saveClientData(Login::$clientDataIsUserLoginKey, true);
     ClientData::saveClientData(Login::$clientDataUserNameDisplayKey, $user->user_name);
     $this->addFlashMessage("登陆成功");
     // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页
     RouteHelper::jumpBack($this, '/', true);
     return;
     // 这里正常返回
     out_fail:
     // 失败从这里入口
     $smarty->display('user_login.tpl', 'User|Login|post');
 }
Exemple #6
0
 public function post($f3)
 {
     //首先验证参数签名
     $map = $_POST;
     unset($map['Vkey']);
     //读取除了vkey外的所有参数,并且放入数组map中
     ksort($map);
     //进行按参数的升序排序
     //进行签名,注意考虑到md5加密输出的大小写问题,所有约定md5的输出均为小写
     $vkey = implode('', array_values($map));
     $md5_1 = strtolower(md5($vkey . YiqifaCpsPlugin::getOptionValue('qqcaibei_key1')));
     $vkey = strtolower(md5($md5_1 . YiqifaCpsPlugin::getOptionValue('qqcaibei_key2')));
     if ($vkey != $_POST['Vkey']) {
         // 参数签名错误
         goto out;
     }
     // 保存额外的 亿起发 参数
     $orderRefer = array();
     $orderRefer['utm_medium'] = 'QQCAIBEI';
     //设置 cookie
     ReferHelper::setOrderReferSpecific($f3, $orderRefer, YiqifaCpsPlugin::getOptionValue('yiqifacps_duration'));
     $f3->set('SESSION[yiqifa_caibei_order_refer]', ReferHelper::parseOrderRefer($f3));
     // 取得QQ彩贝传递过来的参数
     //$acct     = @$_POST['Acct'];
     $url = @$_POST['Url'];
     $openId = @$_POST['OpenId'];
     //$clubInfo = @intval($_POST['ClubInfo']); // 会员等级信息,目前没用
     $viewInfo = @$_POST['ViewInfo'];
     if (get_magic_quotes_gpc()) {
         $viewInfo = stripslashes($viewInfo);
     }
     $viewInfoArray = array();
     parse_str($viewInfo, $viewInfoArray);
     //解析 viewInfoArray 数组
     //$f3->set('SESSION[qqcaibei_viewinfoarray]', json_encode($viewInfoArray)); //放入到 session 里面
     // 设置 ClientData
     ClientData::saveClientData('qqcaibei_viewinfoarray', json_encode($viewInfoArray));
     if (empty($openId)) {
         // 没有  openId 没法登陆,直接退出
         goto out;
     }
     // 这里做 QQ彩贝 联合登陆
     $sns_login = "******";
     // 用户登陆操作
     $userBasicService = new UserBasicService();
     $authUser = $userBasicService->doAuthSnsUser($sns_login, null, null, false);
     if ($authUser) {
         goto out_login_user;
     }
     // 之前没有登陆过,自动注册用户
     $authUser = $userBasicService->doAuthSnsUser($sns_login, $openId . '@qq.com', $openId . '@qq.com', true);
     printLog('注册QQ用户:' . print_r($viewInfoArray, true), 'QQLOGIN', \Core\Log\Base::INFO);
     out_login_user:
     AuthHelper::saveAuthUser($authUser->toArray(), 'qqcaibei');
     // 设置用户名在网页显示
     ClientData::saveClientData(\Controller\User\Login::$clientDataIsUserLoginKey, true);
     ClientData::saveClientData(\Controller\User\Login::$clientDataUserNameDisplayKey, 'QQ彩贝用户:' . $viewInfoArray['NickName']);
     out:
     // 页面跳转到商品
     $redirectUrl = empty($url) ? '/' : $url;
     RouteHelper::reRoute($this, $redirectUrl);
     return;
 }
Exemple #7
0
 /**
  * QQ 登陆
  */
 public function get($f3)
 {
     global $logger;
     global $smarty;
     // 验证 state 参数,防止 csrf 攻击
     if ($_REQUEST['state'] != $f3->get('SESSION[qq_login_state]')) {
         $errorMessage = 'qq login state doest not match, GET[' . $f3->get('GET[state]') . '] SESSION[' . $f3->get('SESSION[qq_login_state]') . ']';
         $logger->addLogInfo(\Core\Log\Base::NOTICE, 'QQLOGIN', $errorMessage);
         goto out;
     }
     // 获取 access_token
     $callback = RouteHelper::makeUrl('/Thirdpart/QQAuth/Callback', null, false, true);
     $tokenUrl = "https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&" . "client_id=" . QQAuthPlugin::getOptionValue('qqauth_appid') . "&redirect_uri=" . urlencode($callback) . "&client_secret=" . QQAuthPlugin::getOptionValue('qqauth_appkey') . "&code=" . $_REQUEST["code"];
     $response = $this->get_url_contents($tokenUrl);
     if (strpos($response, "callback") !== false) {
         $lpos = strpos($response, "(");
         $rpos = strrpos($response, ")");
         $response = substr($response, $lpos + 1, $rpos - $lpos - 1);
         $msg = json_decode($response);
         if (isset($msg->error)) {
             $errorMessage = 'error [' . $msg->error . '] msg [' . $msg->error_description . ']';
             $logger->addLogInfo(\Core\Log\Base::NOTICE, 'QQLOGIN', $errorMessage);
             goto out;
         }
     }
     $params = array();
     parse_str($response, $params);
     $logger->addLogInfo(\Core\Log\Base::DEBUG, 'QQLOGIN', print_r($params, true));
     $accessToken = $params["access_token"];
     // 取得 OpenID
     $graphUrl = "https://graph.qq.com/oauth2.0/me?access_token=" . $accessToken;
     $response = $this->get_url_contents($graphUrl);
     if (strpos($response, "callback") !== false) {
         $lpos = strpos($response, "(");
         $rpos = strrpos($response, ")");
         $response = substr($response, $lpos + 1, $rpos - $lpos - 1);
     }
     $user = json_decode($response);
     if (isset($user->error)) {
         $errorMessage = 'error [' . $msg->error . '] msg [' . $msg->error_description . ']';
         goto out;
     }
     $openId = $user->openid;
     // 取得 userInfo
     $get_user_info = "https://graph.qq.com/user/get_user_info?" . "access_token=" . $accessToken . "&oauth_consumer_key=" . QQAuthPlugin::getOptionValue('qqauth_appid') . "&openid=" . $openId . "&format=json";
     $response = $this->get_url_contents($get_user_info);
     $qqUserInfo = json_decode($response, true);
     $sns_login = "******";
     // 用户登陆操作
     $userBasicService = new UserBasicService();
     $authUser = $userBasicService->doAuthSnsUser($sns_login, null, null, false);
     if ($authUser) {
         goto out_login_user;
     }
     // 之前没有登陆过,自动注册用户
     $authUser = $userBasicService->doAuthSnsUser($sns_login, $openId . '@qq.com', $openId . '@qq.com', true);
     $logger->addLogInfo(\Core\Log\Base::INFO, 'QQLOGIN', '注册QQ用户:' . print_r($qqUserInfo, true));
     out_login_user:
     AuthHelper::saveAuthUser($authUser->toArray(), 'qqlogin');
     // 设置用户名在网页显示
     ClientData::saveClientData(\Controller\User\Login::$clientDataIsUserLoginKey, true);
     ClientData::saveClientData(\Controller\User\Login::$clientDataUserNameDisplayKey, 'QQ用户:' . $qqUserInfo['nickname']);
     out:
     // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页
     RouteHelper::jumpBack($this, '/', true);
 }
Exemple #8
0
 /**
  * 360 登陆
  */
 public function get($f3)
 {
     global $logger;
     if (empty($_GET['code'])) {
         $this->addFlashMessage('360联合登陆失败,Code 不存在');
         goto out;
     }
     require_once 'sdk/QClient.php';
     // 获取access token
     $callback = RouteHelper::makeUrl('/Thirdpart/Dev360Auth/Callback', null, false, true);
     $oauth = new \QOAuth2(Dev360AuthPlugin::getOptionValue(self::$optionKeyPrefix . 'dev360auth_app_key'), Dev360AuthPlugin::getOptionValue(self::$optionKeyPrefix . 'dev360auth_app_secrect'), '');
     $token = $oauth->getAccessTokenByCode($_GET['code'], $callback);
     if (empty($token['access_token'])) {
         $this->addFlashMessage('360联合登陆失败,获取 access_token 失败');
         goto out;
     }
     // 调用API,获取用户信息
     $client = new \QClient(Dev360AuthPlugin::getOptionValue(self::$optionKeyPrefix . 'dev360auth_app_key'), Dev360AuthPlugin::getOptionValue(self::$optionKeyPrefix . 'dev360auth_app_secrect'), $token['access_token']);
     $user = $client->userMe();
     if (empty($user)) {
         $this->addFlashMessage('360联合登陆失败,用户信息为空');
         goto out;
     }
     $param = array('user_id' => $user['id'], 'username' => !empty($user['name']) ? (string) $user['name'] : '网友', 'token' => $token['access_token']);
     // put all values into $_POST[]
     $qid = $param['user_id'];
     $qname = urldecode($param['username']);
     $qmail = '';
     if (empty($qid)) {
         // 没有 qid 没法登陆
         $this->addFlashMessage('360联合登陆失败,没有 qid');
         goto out;
     }
     $sns_login = "******";
     // 用户登陆操作
     $userBasicService = new UserBasicService();
     $authUser = $userBasicService->doAuthSnsUser($sns_login, null, null, false);
     if ($authUser) {
         goto out_login_user;
     }
     // 用户不存在,自动注册一个用户
     if (empty($qmail)) {
         $qmail = '' . $qid . '@360.cn';
     }
     if (empty($qname)) {
         $qname = $qmail;
     }
     $retry = 10;
     // 重试 10 次
     $regUserName = $qname;
     while ($userBasicService->isUserExist($regUserName, null) && $retry-- > 0) {
         $regUserName = $qname . '_' . rand(10000, 99999);
     }
     if ($retry <= 0) {
         $this->addFlashMessage('360联合登陆失败,用户名已经存在,无法自动注册');
         goto out;
     }
     $authUser = $userBasicService->doAuthSnsUser($sns_login, $qname, $qmail, true);
     $logger->addLogInfo(\Core\Log\Base::INFO, 'DEV360AUTH', '注册360用户' . print_r(array('sns_login' => $sns_login, 'qname' => $qname, 'qmail' => $qmail), true));
     out_login_user:
     AuthHelper::saveAuthUser($authUser->toArray(), 'dev360auth');
     // 设置用户名在网页显示
     ClientData::saveClientData(\Controller\User\Login::$clientDataIsUserLoginKey, true);
     ClientData::saveClientData(\Controller\User\Login::$clientDataUserNameDisplayKey, '360用户:' . $authUser['user_name']);
     out:
     // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页
     RouteHelper::jumpBack($this, '/', true);
 }