public function getResponseInfo()
 {
     $result = $this->checkStatus();
     if ($result !== true) {
         return new PwError($result);
     }
     $sessionId = Pw::getCookie($this->_getLoginSessionService()->getCookieName());
     $sessionInfo = App_Account_LoginSessionBo::getInstance($sessionId)->getSession();
     if (!$sessionId || !$sessionInfo) {
         return new PwError('验证会话失败,请重试');
     }
     //计算得出通知验证结果
     if (!$this->_verifyReturn()) {
         return new PwError('验证会话失败,请重试');
     }
     //支付宝用户号
     $user_id = intval($_GET['user_id']);
     //授权令牌
     $token = trim($_GET['token']);
     $real_name = trim($_GET['real_name']);
     if (!$user_id) {
         return new PwError('获取用户信息失败,请重试');
     }
     //更新数据库
     $dm = new App_Account_AlipayUserInfoDm();
     $dm->setUserId($user_id)->setRealName($real_name)->setCreateAt(Pw::getTime());
     $this->_getAlipayUserInfoDs()->replace($dm);
     //更新session
     $this->updateSession($user_id, $real_name, 'alipay');
     return true;
 }
 /**
  * 获取淘宝响应信息 如果oauth2正常流程,可以走curl_init
  */
 public function getResponseInfo()
 {
     $result = $this->checkStatus();
     if ($result !== true) {
         return new PwError($result);
     }
     $sessionId = Pw::getCookie($this->_getLoginSessionService()->getCookieName());
     $sessionInfo = App_Account_LoginSessionBo::getInstance($sessionId)->getSession();
     if (!$sessionId || !$sessionInfo) {
         return new PwError('验证会话失败,请重试');
     }
     list($top_parameters, $top_sign) = array(trim($_REQUEST['top_parameters']), trim($_REQUEST['top_sign']));
     if ($this->_checkSign() === false) {
         return new PwError('与淘宝通信失败,请重试');
     }
     $userInfo = $this->_getUserInfo();
     if ($userInfo === false) {
         return new PwError('获取用户信息失败,请重试');
     }
     list($user_id, $nick) = $userInfo;
     //更新数据库
     $info = $this->_getTaobaoUserInfoDs()->get($user_id);
     if (!$info) {
         $dm = new App_Account_TaobaoUserInfoDm();
         $dm->setUserId($user_id)->setNick($nick)->setCreateAt(Pw::getTime());
         $this->_getTaobaoUserInfoDs()->add($dm);
     }
     //更新session
     $this->updateSession($user_id, $nick, 'taobao');
     return true;
 }
 /**
  * 获取回调响应
  */
 public function getResponseInfo()
 {
     $result = $this->checkStatus();
     if ($result !== true) {
         return new PwError($result);
     }
     $sessionId = Pw::getCookie($this->_getLoginSessionService()->getCookieName());
     $sessionInfo = App_Account_LoginSessionBo::getInstance($sessionId)->getSession();
     if (!$sessionId || !$sessionInfo) {
         return new PwError('验证会话失败,请重试');
     }
     if ($_REQUEST['state'] == $sessionInfo['sessiondata']['state']) {
         //step 2 通过Authorization Code获取Access Token
         $token = $this->_getAccessToken();
         if ($token === false) {
             return new PwError('验证会话失败,请重试');
         }
         list($accessToken, $uid) = $token;
         //step 2 获取用户信息
         $userInfo = $this->_getUserInfo($uid, $accessToken);
         if (!$userInfo) {
             return new PwError('获取用户信息失败,请重试');
         }
         //更新数据库
         $this->_updateDb($uid, $userInfo);
         //更新session
         $this->updateSession($uid, $userInfo['screen_name'], 'sinaweibo');
         return true;
     }
 }
 public function deleteByExpire($expire)
 {
     $expire = intval($expire);
     if ($expire < 1) {
         return false;
     }
     App_Account_LoginSessionBo::unsetInstance();
     return $this->_loadDao()->deleteByExpire($expire);
 }
 /**
  * unset一个bo
  * @param unknown_type $sessionId
  * @return boolean
  */
 public static function unsetInstance($sessionId = null)
 {
     if ($sessionId == null) {
         self::$_bo = null;
     }
     if (!isset(self::$_bo[$sessionId])) {
         return false;
     }
     self::$_bo[$sessionId] = null;
     return true;
 }
 /**
  * 获取QQ回调响应
  */
 public function getResponseInfo()
 {
     $result = $this->checkStatus();
     if ($result !== true) {
         return new PwError($result);
     }
     $params = array_merge($_GET, $_POST);
     $sessionId = Pw::getCookie($this->_getLoginSessionService()->getCookieName());
     $sessionInfo = App_Account_LoginSessionBo::getInstance($sessionId)->getSession();
     if (!$sessionId || !$sessionInfo) {
         return new PwError('验证会话失败,请重试');
     }
     if ($params['state'] == $sessionInfo['sessiondata']['state']) {
         //step 2 通过Authorization Code获取Access Token
         $accessToken = $this->_getAccessToken();
         if ($accessToken === false) {
             return new PwError('验证会话失败,请重试');
         }
         /*
          * step3:使用Access Token来获取用户的OpenID
          * openid 用户唯一标识
          */
         $openId = $this->_getOpenIdByAccessToken($accessToken);
         if ($openId === false) {
             return new PwError('验证会话失败,请重试');
         }
         //step4: 使用openid获取用户信息
         $userInfo = $this->_getUserInfo($openId, $accessToken);
         if ($userInfo === false || !$userInfo) {
             return new PwError('获取用户信息失败,请重试');
         }
         //更新数据库
         $userId = $this->_updateDb($openId, $userInfo);
         if ($userId === false || $userId < 1) {
             return new PwError('更新数据库失败');
         }
         //更新session
         $this->updateSession($userId, $userInfo['nickname'], 'qzone');
         return true;
     }
 }
 public function updateLoginSession($sessionId, $sessionData)
 {
     if ('' == $sessionId) {
         return false;
     }
     $this->_collectLoginSessionGarbage();
     $sessionInfo = App_Account_LoginSessionBo::getInstance($sessionId)->getSession();
     $sessionInfoOld = $sessionInfo;
     $sessionInfo['sessiondata'] = is_array($sessionInfo['sessiondata']) ? $sessionInfo['sessiondata'] : array();
     $sessionData = is_array($sessionData) ? $sessionData : array();
     $sessionData = array_merge($sessionInfo['sessiondata'], $sessionData);
     if ($sessionInfoOld) {
         $dm = new App_Account_LoginSessionDm($sessionId);
         $dm->setSessionData(serialize($sessionData));
         return $this->_getLoginSessionDs()->update($dm);
     } else {
         $dm = new App_Account_LoginSessionDm();
         $dm->setSessionId($sessionId)->setExpire($this->cookieExpire + Pw::getTime())->setSessionData(serialize($sessionData));
         return $this->_getLoginSessionDs()->add($dm);
     }
 }
示例#8
0
 /**
  * 结果分析路由
  */
 public function routeAction()
 {
     $sessionId = Pw::getCookie($this->_getLoginSessionService()->getCookieName());
     $sessionInfo = App_Account_LoginSessionBo::getInstance($sessionId)->getSession();
     $sessionData = $sessionInfo['sessiondata'];
     $refer = $sessionData['httpReferer'] ? $sessionData['httpReferer'] : $this->hostInfo;
     if (!$this->_getAccountTypeService()->checkType($sessionData['type'])) {
         $this->showError('登录类型错误,请重试');
     }
     if (!$sessionId || !$sessionInfo || !$sessionData['data']['user_id'] || !$sessionData['action']) {
         $this->showError('验证失败,请重试');
     }
     $url = $refer ? $refer : $this->hostInfo . Wind::getComponent('request')->getScriptUrl();
     $type_name = $this->_getAccountTypeService()->getTypeName($sessionData['type']);
     $msg_info = '使用' . $type_name . '账号认证通过(窗口将自动关闭)';
     if ($sessionData['action'] == 'bind') {
         //绑定流程
         $result = $this->_getAccountBindService()->bind($this->uid, $sessionData['data']['user_id'], $sessionData['type']);
         if ($result instanceof PwError) {
             $this->showError($result->getError());
         }
     } elseif ($sessionData['data']['isBound'] == 0 && $sessionData['action'] == 'login') {
         $sign = $sessionData['data']['sign'];
         //没有绑定社区账号 注册或者绑定
         $config = Wekit::C()->getValues('register');
         if ($config['type'] == 0) {
             //关闭注册,跳转到绑定设置页面
             $url = WindUrlHelper::createUrl('app/login/run', array('app' => 'account', 'sign' => $sign));
         } else {
             $url = WindUrlHelper::createUrl('app/register/run', array('app' => 'account', 'sign' => $sign));
         }
     } elseif ($sessionData['data']['isBound'] == 1 && $sessionData['action'] == 'login') {
         //进入登录 用户校验
         $uid = intval($sessionData['data']['bbs_uid']);
         Wind::import('SRV:user.bo.PwUserBo');
         $userBo = PwUserBo::getInstance($uid);
         if (!$userBo->isExists()) {
             //用户不存在
             $this->_getAccountBindDs()->deleteByUid($uid);
             $this->showError('绑定用户在站点已删除,请重试');
         }
         $pattern = '/m=u&c=login/i';
         if (preg_match($pattern, $url)) {
             $url = $this->_getCommonService()->getHost();
         }
         $userService = Wekit::load('user.srv.PwUserService');
         $userService->createIdentity($userBo->uid, $userBo->info['password']);
     }
     $this->setOutput($msg_info, 'msg_info');
     $this->setOutput($url, 'jumpurl');
     $this->setOutput(Wekit::app()->charset, 'charset');
     $this->setTemplate('login_notice');
 }
 /**
  * 钩子---用户退出触发
  */
 public function logout($loginUser)
 {
     return true;
     $uid = intval($loginUser->uid);
     if ($uid < 1) {
         return false;
     }
     $sessionId = Pw::getCookie($this->_getLoginSessionService()->getCookieName());
     if (!$sessionId) {
         return false;
     }
     $sessionInfo = App_Account_LoginSessionBo::getInstance($sessionId)->getSession();
     $sessionData = $sessionInfo['sessiondata'];
     $type = $sessionData['type'];
     if (!$sessionData || !$this->_getAccountTypeService()->checkType($type)) {
         return false;
     }
     if (!$this->_getAccountBindDs()->getByUidAndType($uid, $type)) {
         return false;
     }
     $host = $this->getHost();
     return $this->_getAccountService($type)->logout($host);
 }
示例#10
0
 /**
  * 执行用户注册
  */
 public function dorunAction()
 {
     //new add
     //验证
     $sign = $this->getInput('sign', 'get');
     $sessionId = Pw::getCookie($this->_getLoginSessionService()->getCookieName());
     $sessionInfo = App_Account_LoginSessionBo::getInstance($sessionId)->getSession();
     $sessionData = $sessionInfo['sessiondata'];
     $app_uid = $sessionData['data']['user_id'];
     $type = $sessionData['type'];
     if (!$sessionId || !$this->_getAccountTypeService()->checkType($type) || $sessionData['data']['sign'] != $sign || !$app_uid) {
         $this->showError("非法访问");
     }
     $this->setOutput('注册', 'title');
     $registerService = new PwRegisterService();
     $registerService->setUserDm($this->_getUserDm());
     /*[u_regsiter]:插件扩展*/
     $this->runHook('c_register', $registerService);
     if (($info = $registerService->register()) instanceof PwError) {
         $this->showError($info->getError());
     } else {
         $identity = PwRegisterService::createRegistIdentify($info['uid'], $info['password']);
         //绑定 new add
         Wekit::load('EXT:account.service.srv.App_Account_BindService')->bind($info['uid'], $app_uid, $type);
         if (1 == Wekit::C('register', 'active.mail')) {
             $this->forwardAction('u/register/sendActiveEmail', array('_statu' => $identity), true);
         } else {
             $this->forwardAction('u/register/welcome', array('_statu' => $identity), true);
         }
     }
 }
示例#11
0
 /**
  * 页面登录
  */
 public function dorunAction()
 {
     //new  add
     $sign = $this->getInput('sign', 'get');
     $sessionId = Pw::getCookie($this->_getLoginSessionService()->getCookieName());
     $sessionInfo = App_Account_LoginSessionBo::getInstance($sessionId)->getSession();
     $sessionData = $sessionInfo['sessiondata'];
     $app_uid = $sessionData['data']['user_id'];
     $type = $sessionData['type'];
     if (!$sessionId || !$this->_getAccountTypeService()->checkType($type) || $sessionData['data']['sign'] != $sign || !$app_uid) {
         $this->showError("非法访问");
     }
     $refer = $sessionData['httpReferer'];
     $backUrl = $refer ? $refer : $this->getRequest()->getHostInfo();
     $userForm = $this->_getLoginForm();
     /* [验证验证码是否正确] */
     if ($this->_showVerify()) {
         $veryfy = $this->_getVerifyService();
         if ($veryfy->checkVerify($userForm['code']) !== true) {
             $this->showError('USER:verifycode.error');
         }
     }
     $question = $userForm['question'];
     if ($question == -4) {
         $question = $this->getInput('myquestion', 'post');
     }
     /* [验证用户名和密码是否正确] */
     $login = new PwLoginService();
     $this->runHook('c_login_dorun', $login);
     $isSuccess = $login->login($userForm['username'], $userForm['password'], $this->getRequest()->getClientIp(), $question, $userForm['answer']);
     if ($isSuccess instanceof PwError) {
         $this->showError($isSuccess->getError());
     }
     $config = Wekit::C('site');
     if ($config['windid'] != 'local') {
         $localUser = $this->_getUserDs()->getUserByUid($isSuccess['uid'], PwUser::FETCH_MAIN);
         if ($userForm['username'] != $localUser['username']) {
             $this->showError('USER:user.syn.error');
         }
     }
     //绑定 new add
     Wekit::load('EXT:account.service.srv.App_Account_BindService')->bind($isSuccess['uid'], $app_uid, $type);
     Wind::import('SRV:user.srv.PwRegisterService');
     $registerService = new PwRegisterService();
     $info = $registerService->sysUser($isSuccess['uid']);
     $identity = PwLoginService::createLoginIdentify($info);
     //$identity = base64_encode($identity . '|' . $this->getInput('backurl'));
     $identity = base64_encode($identity . '|' . $backUrl);
     /* [是否需要设置安全问题] */
     /* @var $userService PwUserService */
     $userService = Wekit::load('user.srv.PwUserService');
     if (empty($isSuccess['safecv']) && $userService->mustSettingSafeQuestion($info['uid'])) {
         $this->addMessage(array('url' => WindUrlHelper::createUrl('u/login/setquestion', array('v' => 1, '_statu' => $identity))), 'check');
     }
     $this->showMessage('', 'u/login/welcome?_statu=' . $identity);
 }