Exemplo n.º 1
0
 public function registerTmpUser($from = 1, $key = '')
 {
     //need to check if registered user exists or not
     if (empty($key) == false) {
         //if has key, then check if this key has user or not
         $tmpFound = $this->getbyKey($from, $key);
         if (empty($tmpFound) == false) {
             //if has user info, then return user's information
             $userid = $tmpFound['userid'];
             return Windid::load('user.WindidUser')->getUserByUid($userid, WindidUser::FETCH_MAIN);
         }
     }
     Wind::import('SRC:service.user.dm.PwUserInfoDm');
     $userDm = new PwUserInfoDm();
     $password = substr(md5(rand() . '123456'), 0, 15);
     //order number: 13 number and 3 random number
     $currentTimeStamp = strtotime("+0 day");
     $prefix = 'tmp';
     if ($from == 1) {
         $prefix = 'web';
     } else {
         if ($from == 2) {
             $prefix = 'app';
         } else {
             if ($from == 3) {
                 $prefix = 'wx';
             }
         }
     }
     $username = $prefix . rand(10, 99) . $currentTimeStamp;
     $userDm->setUsername($username);
     $userDm->setPassword($password);
     $userDm->setRegdate(Pw::getTime());
     $userDm->setLastvisit(Pw::getTime());
     $userDm->setRegip(Wekit::app()->clientIp);
     Wind::import('SRV:user.srv.PwRegisterService');
     Wind::import('APPS:u.service.helper.PwUserHelper');
     Wind::import('SRV:user.validator.PwUserValidator');
     Wind::import('Wind:utility.WindValidator');
     Wind::import('SRV:user.srv.PwLoginService');
     $registerService = new PwRegisterService();
     $registerService->setUserDm($userDm);
     $info = $registerService->register();
     $userService = Wekit::load('user.srv.PwUserService');
     $userService->updateLastLoginData($info['uid'], Wekit::app()->clientIp);
     $userService->createIdentity($info['uid'], $password);
     $dm = new App_Tmpuser_Dm();
     $dm->setUserId($info['uid']);
     $dm->setFrom($from);
     $dm->setKey($key);
     $this->add($dm);
     return $info;
 }
Exemplo n.º 2
0
 /**
  * 在 PHPWind 中注册用户、绑定用户的QQ、并返回新的Uid
  * @param string $mail
  * @param string $nick
  * @param &$error 传引用,如果不为空则发生了错误
  * @return int uid
  */
 function register_username($nickname, &$error = false)
 {
     !session_id() && session_start();
     if (empty($_SESSION['qq_oauth_openid']) || empty($_SESSION['qq_oauth_access_token']) || empty($_SESSION['qq_oauth_figureurl_2'])) {
         $error = '会话丢失,请重新绑定。';
         return;
     } else {
         $this->openid = $_SESSION['qq_oauth_openid'];
         $this->access_token = $_SESSION['qq_oauth_access_token'];
     }
     Wind::import('SRV:user.srv.PwRegisterService');
     Wind::import('APPS:u.service.helper.PwUserHelper');
     Wind::import('SRV:user.validator.PwUserValidator');
     Wind::import('Wind:utility.WindValidator');
     $registerService = new PwRegisterService();
     $UserDM = $this->_UserDMUserName($nickname);
     $registerService->setUserDm($UserDM);
     if (($info = $registerService->register()) instanceof PwError) {
         $error = $info->getError(false);
     } else {
         if (!empty($_SESSION['qq_oauth_figureurl_2'])) {
             $this->restore_avatar($info['uid'], $_SESSION['qq_oauth_figureurl_2']);
         }
         return $info['uid'];
     }
 }
Exemplo n.º 3
0
 public function mobileLoginAction()
 {
     //simulate data
     $test = array("openid" => "7E561C40E3443EC7A473DB7D6767419A", "gender" => "男", "avatar" => "http://qzapp.qlogo.cn/qzapp/100505782/7E561C40E3443EC7A473DB7D6767419A/100", "nickname" => "良品-身边", "access_token" => "602E4FD23B479E8832D39AB3DAE7E5A9");
     $result = array("Success" => 0, "ErrorMessage" => "");
     //$testtr = json_encode($test);
     //$testtr = '{"openid":"7E561C40E3443EC7A473DB7D6767419A","gender":"\u7537","avatar":"","nickname":"\u826f\u54c1-\u8eab\u8fb9","access_token":"602E4FD23B479E8832D39AB3DAE7E5A9"}';
     $qqInfo = $this->getInput("qqinfo");
     //urldecode and jsondecode
     $qqInfo = urldecode($qqInfo);
     $qqInfo = json_decode($qqInfo);
     $qqInfo = $this->class_object_to_array($qqInfo);
     //check data empty
     if (empty($qqInfo)) {
         $result['Success'] = 0;
         $result['ErrorMessage'] = "无效的数据";
         $this->output($result);
     }
     //1. openid
     //2. gender
     //3. avatar
     //4. nickname
     //5. access_token
     $openid = $qqInfo['openid'];
     $gender = $qqInfo['gender'];
     $avatar = $qqInfo['avatar'];
     $nickname = $qqInfo['nickname'];
     $access_token = $qqInfo['access_token'];
     if (empty($openid) || empty($nickname) || empty($access_token)) {
         $result['Success'] = 0;
         $result['ErrorMessage'] = "资料不全";
         $this->output($result);
     }
     //check if this openid already has user
     $qqauth = Wekit::loadDao('SRC:extensions.com_qq_login.service.dao.qq_oauth_dao');
     $fetched = $qqauth->getOne($openid);
     Wind::import('SRV:user.srv.PwRegisterService');
     Wind::import('APPS:u.service.helper.PwUserHelper');
     Wind::import('SRV:user.validator.PwUserValidator');
     Wind::import('Wind:utility.WindValidator');
     //if not registred before
     if (empty($fetched)) {
         //register user
         //need to rand nickname
         $nickname = $nickname . substr(md5(rand() . $access_token), 0, 6);
         $registerService = new PwRegisterService();
         $UserDM = $this->_UserDMUserName($nickname);
         $registerService->setUserDm($UserDM);
         if (($info = $registerService->register()) instanceof PwError) {
             $error = $info->getError(false);
             $result['Success'] = 0;
             $result['ErrorMessage'] = $error;
             $this->output($result);
         } else {
             $uid = $info['uid'];
             $qqauth->add($uid, $access_token, $nickname, $avatar, $gender, 0, 0, 0, $openid);
         }
     } else {
         $uid = $fetched['uid'];
     }
     $result['Success'] = 1;
     $result['ErrorMessage'] = "";
     $result['User'] = $this->getUserInfo($uid);
     $this->output($result);
 }
Exemplo n.º 4
0
 /** 
  * 用户注册信息
  * 
  * @return boolean|int
  */
 public function userRegister($username, $password, $email)
 {
     if (!trim($username)) {
         return $this->buildResponse(USER_INVALID_USERNAME);
     }
     if (!$password || !$email || WindValidator::isEmail($email) !== true) {
         return $this->buildResponse(USER_INVALID_PARAMS);
     }
     Wind::import('SRV:user.srv.PwRegisterService');
     Wind::import('SRC:service.user.dm.PwUserInfoDm');
     $userDm = new PwUserInfoDm();
     $userDm->setUsername($username);
     $userDm->setPassword($password);
     $userDm->setEmail($email);
     $userDm->setRegdate(Pw::getTime());
     $userDm->setRegip(Wind::getApp()->getRequest()->getClientIp());
     $registerService = new PwRegisterService();
     $registerService->setUserDm($userDm);
     $result = $registerService->register();
     if ($result instanceof PwError) {
         return $this->buildResponse(-1, $result->getError());
     }
     return $this->buildResponse(0, $result);
 }
Exemplo n.º 5
0
 /**
  * 生成UserDM对象
  * @param string $mail
  * @param string $nick
  * @return object UserDM
  */
 private function _registerTmpUser()
 {
     Wind::import('SRC:service.user.dm.PwUserInfoDm');
     $userDm = new PwUserInfoDm();
     $password = substr(md5(rand() . '123456'), 0, 15);
     //order number: 13 number and 3 random number
     $currentTimeStamp = strtotime("+0 day");
     $username = '******' . rand(10, 99) . $currentTimeStamp;
     $userDm->setUsername($username);
     $userDm->setPassword($password);
     $userDm->setRegdate(Pw::getTime());
     $userDm->setLastvisit(Pw::getTime());
     $userDm->setRegip(Wekit::app()->clientIp);
     Wind::import('SRV:user.srv.PwRegisterService');
     Wind::import('APPS:u.service.helper.PwUserHelper');
     Wind::import('SRV:user.validator.PwUserValidator');
     Wind::import('Wind:utility.WindValidator');
     Wind::import('SRV:user.srv.PwLoginService');
     $registerService = new PwRegisterService();
     $registerService->setUserDm($userDm);
     $info = $registerService->register();
     $userService = Wekit::load('user.srv.PwUserService');
     $userService->updateLastLoginData($info['uid'], Wekit::app()->clientIp);
     $userService->createIdentity($info['uid'], $password);
     return $info;
 }