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; }
public function beforeLogout(PwUserBo $bo) { if (!$bo->isExists()) { return true; } $onlineTime = intval(Wekit::C('site', 'onlinetime')); if ($onlineTime <= 0) { return true; } $newLastVisit = $bo->info['lastvisit'] - $onlineTime * 60; Wind::import('SRV:user.dm.PwUserInfoDm'); $dm = new PwUserInfoDm($bo->uid); $dm->setLastvisit($newLastVisit); /* @var $userDs PwUser */ $userDs = Wekit::load('user.PwUser'); $userDs->editUser($dm, PwUser::FETCH_DATA); return true; }
/** * 执行第三方授权登录后的注册动作 * */ public function doThirdRegistAction() { //第三方登录注册不校验验证码 /* if(Wekit::load("verify.srv.PwCheckVerifyService")->checkVerify($this->getInput('code')) != true){ $this->showError('USER:verifycode.error','index.php?m=u&c=login'); } */ //post参数中获取用户注册信息、第三方授权获取的信息通过hidden标签保存 $username = $this->getInput('username', 'post'); $password = $this->getInput('password', 'post'); $email = $this->getInput('email', 'post'); $gender = $this->getInput('gender', 'post'); $uid = $this->getInput('uid', 'post'); $type = $this->getInput('type', 'post'); $avatar = $this->getInput('avatar', 'post'); //执行注册 Wind::import('SRC:service.user.dm.PwUserInfoDm'); $userDm = new PwUserInfoDm(); $userDm->setUsername($username); $userDm->setPassword($password); $userDm->setEmail($email); $userDm->setGender($gender); $userDm->setRegdate(Pw::getTime()); $userDm->setLastvisit(Pw::getTime()); $userDm->setRegip(Wind::getComponent('request')->getClientIp()); $userDm->setStatus(0); Wind::import('SRV:user.srv.PwRegisterService'); $registerService = new PwRegisterService(); $registerService->setUserDm($userDm); // [u_regsiter]:插件扩展 $this->runHook('c_register', $registerService); if (($info = $registerService->register()) instanceof PwError) { $this->showError($info->getError()); } // 这里取了lastInsertId,但已经指定了主键的值,所以返回false表示成功。。 if ($this->_getUserOpenAccountDs()->addUser($info['uid'], $uid, $type) == false) { $this->downloadThirdPlatformAvatar($info['uid'], $avatar); } // 以便后面登录用到 $acctRelationData = array('uid' => $info['uid']); //继续登录 $login = new PwLoginService(); $this->runHook('c_login_dorun', $login); Wind::import('SRV:user.srv.PwRegisterService'); $registerService = new PwRegisterService(); $info = $registerService->sysUser($acctRelationData['uid']); if (!$info) { $this->showError('USER:user.syn.error'); } $identity = PwLoginService::createLoginIdentify($info); $identity = base64_encode($identity . '|' . $this->getInput('backurl') . '|' . '0'); $this->forwardRedirect(WindUrlHelper::createUrl('u/login/welcome', array('_statu' => $identity))); }
/** * 获取注册的信息 * * @return PwUserInfoDm */ private function _getUserDm() { list($username, $password, $repassword, $email, $aliww, $qq, $msn, $mobile, $mobileCode, $hometown, $location, $question, $answer, $regreason, $code) = $this->getInput(array('username', 'password', 'repassword', 'email', 'aliww', 'qq', 'msn', 'mobile', 'mobileCode', 'hometown', 'location', 'question', 'answer', 'regreason', 'code'), 'post'); // 验证输入 Wind::import('Wind:utility.WindValidator'); $config = $this->_getRegistConfig(); if (!$username) { $this->showError('USER:user.error.-1', 'u/register/run'); } if (!$password) { $this->showError('USER:pwd.require', 'u/register/run'); } if (!$email) { $this->showError('USER:user.error.-6', 'u/register/run'); } if (!WindValidator::isEmail($email)) { $this->showError('USER:user.error.-7', 'u/register/run'); } foreach ($config['active.field'] as $field) { if (!$this->getInput($field, 'post')) { $this->showError('USER:register.error.require.needField.' . $field, 'u/register/run'); } } if ($config['active.check'] && !$regreason) { $this->showError('USER:register.error.require.regreason', 'u/register/run'); } if ($config['active.phone']) { !PwUserValidator::isMobileValid($mobile) && $this->showError('USER:error.mobile', 'u/register/run'); if (($mobileCheck = Wekit::load('mobile.srv.PwMobileService')->checkVerify($mobile, $mobileCode)) instanceof PwError) { $this->showError($mobileCheck->getError()); } } if ($repassword != $password) { $this->showError('USER:user.error.-20', 'u/register/run'); } if (in_array('register', (array) Wekit::C('verify', 'showverify'))) { $veryfy = Wekit::load("verify.srv.PwCheckVerifyService"); if (false === $veryfy->checkVerify($code)) { $this->showError('USER:verifycode.error', 'u/register/run'); } } Wind::import('SRC:service.user.dm.PwUserInfoDm'); $userDm = new PwUserInfoDm(); $userDm->setUsername($username); $userDm->setPassword($password); $userDm->setEmail($email); $userDm->setRegdate(Pw::getTime()); $userDm->setLastvisit(Pw::getTime()); $userDm->setRegip(Wind::getComponent('request')->getClientIp()); $userDm->setAliww($aliww); $userDm->setQq($qq); $userDm->setMsn($msn); $userDm->setMobile($mobile); $userDm->setMobileCode($mobileCode); $userDm->setQuestion($question, $answer); $userDm->setRegreason($regreason); $areaids = array($hometown, $location); if ($areaids) { $srv = WindidApi::api('area'); $areas = $srv->fetchAreaInfo($areaids); $userDm->setHometown($hometown, isset($areas[$hometown]) ? $areas[$hometown] : ''); $userDm->setLocation($location, isset($areas[$location]) ? $areas[$location] : ''); } return $userDm; }
/** * 生成UserDM对象 * @param string $mail * @param string $nick * @return object UserDM */ function _UserDMUserName($nickname) { Wind::import('SRC:service.user.dm.PwUserInfoDm'); $userDm = new PwUserInfoDm(); $password = substr(md5(rand() . '123456'), 0, 15); $userDm->setUsername($nickname); $userDm->setPassword($password); $userDm->setRegdate(Pw::getTime()); $userDm->setLastvisit(Pw::getTime()); $userDm->setRegip(Wekit::app()->clientIp); return $userDm; }
/** * 初始话当前用户 */ protected function _initUser() { $_cOnlinetime = Wekit::C('site', 'onlinetime') * 60; if (!($lastvisit = Pw::getCookie('lastvisit'))) { $this->onlinetime = 0; $this->lastvisit = WEKIT_TIMESTAMP; $this->lastRequestUri = ''; } else { list($this->onlinetime, $this->lastvisit, $this->lastRequestUri) = explode("\t", $lastvisit); ($onlinetime = WEKIT_TIMESTAMP - $this->lastvisit) < $_cOnlinetime && ($this->onlinetime += $onlinetime); } $user = $this->getLoginUser(); if ($user->isExists() && WEKIT_TIMESTAMP - $user->info['lastvisit'] > min(1800, $_cOnlinetime)) { Wind::import('SRV:user.dm.PwUserInfoDm'); $dm = new PwUserInfoDm($user->uid); $dm->setLastvisit(WEKIT_TIMESTAMP)->setLastActiveTime(WEKIT_TIMESTAMP); if ($this->onlinetime > 0) { $dm->addOnline($this->onlinetime > $_cOnlinetime * 1.2 ? $_cOnlinetime : $this->onlinetime); } Wekit::load('user.PwUser')->editUser($dm, PwUser::FETCH_DATA); $this->onlinetime = 0; } Pw::setCookie('lastvisit', $this->onlinetime . "\t" . WEKIT_TIMESTAMP . "\t" . $this->requestUri, 31536000); }
/** * 更新用户登录信息 * * @param int $uid 用户ID * @param string $ip 用户IP * @return boolean */ public function updateLastLoginData($uid, $ip) { /* 更新用户登录信息 */ $dm = new PwUserInfoDm($uid); $dm->setLastvisit(Pw::getTime())->setLastloginip($ip); return $this->_getUserDs()->editUser($dm, PwUser::FETCH_DATA); }
/** * 初始话当前用户 */ protected function _initUser() { $requestUri = Wind::getComponent('request')->getRequestUri(); $_cOnlinetime = Wekit::C('site', 'onlinetime') * 60; if (!($lastvisit = Pw::getCookie('lastvisit'))) { $onlinetime = 0; $lastvisit = WEKIT_TIMESTAMP; $lastRequestUri = ''; } else { list($onlinetime, $lastvisit, $lastRequestUri) = explode("\t", $lastvisit); ($thistime = WEKIT_TIMESTAMP - $lastvisit) < $_cOnlinetime && ($onlinetime += $thistime); } $user = $this->getLoginUser(); if ($user->isExists()) { $today = Pw::str2time(Pw::time2str(Pw::getTime(), 'Y-m-d')); if ($user->info['lastvisit'] && $today > $user->info['lastvisit']) { /* @var $loginSrv PwLoginService */ $loginSrv = Wekit::load('SRV:user.srv.PwLoginService'); $loginSrv->welcome($user, Wind::getComponent('request')->getClientIp()); } elseif (WEKIT_TIMESTAMP - $user->info['lastvisit'] > min(1800, $_cOnlinetime)) { Wind::import('SRV:user.dm.PwUserInfoDm'); $dm = new PwUserInfoDm($user->uid); $dm->setLastvisit(WEKIT_TIMESTAMP)->setLastActiveTime(WEKIT_TIMESTAMP); if ($onlinetime > 0) { $dm->addOnline($onlinetime > $_cOnlinetime * 1.2 ? $_cOnlinetime : $onlinetime); } Wekit::load('user.PwUser')->editUser($dm, PwUser::FETCH_DATA); $onlinetime = 0; } } Pw::setCookie('lastvisit', $onlinetime . "\t" . WEKIT_TIMESTAMP . "\t" . $requestUri, 31536000); $obj = new stdClass(); $obj->lastvisit = $lastvisit; $obj->requestUri = $requestUri; $obj->lastRequestUri = $lastRequestUri; Wekit::setV('lastvist', $obj); }
private function _UserDM($mobile, $password, $username = '') { Wind::import('SRC:service.user.dm.PwUserInfoDm'); $userDm = new PwUserInfoDm(); $userDm->setUsername(empty($username) ? $mobile : $username); $userDm->setMobile($mobile); $userDm->setPassword($password); $userDm->setRegdate(Pw::getTime()); $userDm->setLastvisit(Pw::getTime()); $userDm->setRegip(Wekit::app()->clientIp); return $userDm; }
/** * 生成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; }
/** * 开放帐号注册到本系统内 * * @access public * @return void * @example <pre> os可以是android或者ios <br> post: access_token&platformname&native_name&username&email&sex </pre> */ public function openAccountRegisterAction() { // if($this->_getUserOpenAccountDs()->addUser(56,56,56)==false){ // if(true){ // echo "true"; // $this->downloadThirdPlatformAvatar(59,"http://q.qlogo.cn/qqapp/1104230675/A773C383D93AAF2986157BA34965A5CD/100"); // }else{ // echo "false"; // } // exit; $accountData = $this->authThirdPlatform(); // list($username, $email, $sex) = $this->getInput(array('username', 'email', 'sex')); //随机密码 $password = substr(str_shuffle('abcdefghigklmnopqrstuvwxyz1234567890~!@#$%^&*()'), 0, 7); // Wind::import('SRC:service.user.dm.PwUserInfoDm'); $userDm = new PwUserInfoDm(); $userDm->setUsername($username); $userDm->setPassword($password); $userDm->setEmail($email); $userDm->setGender($sex); $userDm->setRegdate(Pw::getTime()); $userDm->setLastvisit(Pw::getTime()); $userDm->setRegip(Wind::getComponent('request')->getClientIp()); // $registerService = new PwRegisterService(); $registerService->setUserDm($userDm); /*[u_regsiter]:插件扩展*/ $this->runHook('c_register', $registerService); if (($info = $registerService->register()) instanceof PwError) { $this->showError($info->getError()); } else { // 这里注册成功,要把第三方帐号的头像下载下来并处理 // 这里取了lastInsertId,但已经指定了主键的值,所以返回false表示成功 if ($this->_getUserOpenAccountDs()->addUser($info['uid'], $accountData['uid'], $accountData['type']) == false) { $this->downloadThirdPlatformAvatar($info['uid'], $accountData['avatar']); $laiwangOK = PwLaiWangSerivce::registerUser($info['uid'], $info['username'], $info['password'], Pw::getAvatar($info['uid'], 'big'), $accountData['gender']); // 重置uid $this->uid = $info['uid']; $userdata = $this->_getUserInfo($laiwangOK); $this->setOutput($userdata, 'data'); $this->showMessage('USER:register.success'); } } }