-
/*
- *
- * @copyright 2011
- * @version $Id$
- * @access public
- * @version $Id$
- * @access public
- * @property string $id
- * @property string $account
- * @property string $pwd
- * @property string $lastquesttime
- * @property string $lastip
- * @property int regtime
- * @property int $accounttype
- * @property string $oldaccount
- * @property int $logintimes
- * @property string $currentIP
- * @property intcidclass Resposity extends AdminActiveRecord {
- public $connectionPrefix = 'passport';
- protected $list = null;
- protected $passportConfig = null;
- public_account = protected; > /**
- * 傳回指定 AR 類別的靜態模型。
- * @return Resposity 靜態模型類別
- */
- 公用靜態函式模型($className = __class__) {
- returnparent::model ( $className );
- }
-
- /**
- * 如果需要請修改它。
- * @return 混合了primaryKey。
- */
- public function PrimaryKey() {
- return 'id';
- }
-
- /**
- * @return 模型屬性的陣列驗證規則。
- */
- public function Rules() {
- 根據主帳號取得使用者資訊
- * // 注意:您應該只為
- // 將接收使用者輸入的屬性定義規則。 '帳戶類型', 'in', '範圍' => array ('0', '1', '2', '3', '4', '5', '6', '7' ) ),
- array ('currentIP', 'ip')
- );
- }
- /**根據子帳號取得使用者資訊**/
- protected function getUserInfoByMainAccount($account,$cid){
- $account=strtolower($account);
- $cacheKey = hash ( 'md5', $account.'^]'.$cid.'^]'.'0' );
- $user=UtilD: :getCache('resposity',$cacheKey);
- if(is_array($user)){
- UtilD::clearNullOrEmptyValue ( $user );
- }else{
- $user=array() ;
- }
- if(count($user) )){
- return $user;
- }else{
- $model = $this->find ( 'account=:account AND cid =:cid', array (':帳戶' =>; $account,':cid' => $cid ) );
- if($model){
- $user=$model->getAttributes();
- unset($model);
- }
- UtilD::setCache('resposity',$cacheKey,$user);
- return $user;
- }
- }
- /**根據帳號類型取得使用者資料**/
- protected function getUserInfoByChildAccount($subaccount,$cid,$accounttype){
- if(!$ this->validate(array('accounttype'), true)){
- return -1000;
- }
- $subaccount=strtolower($subaccount);
- $cacheKey = hash ( 'md5 ' , $subaccount.'^]'.$cid.'^]'.$accounttype );
- $userAccounts=UtilD::getCache('resposity',$cacheKey);
- if(is_array($userAccounts) )){
- UtilD::clearNullOrEmptyValue($userAccounts);
- }else{
- $userAccounts=array();
- }
- if(!count($userAccounts));
- }
- if(!count($userAccounts)){ $accountRefer=new AccountRefer();
- $model=$accountRefer->find ( 'subaccount=:subaccount AND cid=:cid AND accounttype=:accounttype', array (':subaccount' => $subaccount ,' :cid' => $this->cid,':accounttype'=> $accounttype) );
- if($model){
- $userAccounts=$model->getAttributes() ;
- UtilD: :setCache('resposity',$cacheKey,$userAccounts);
- }
- }
- if(isset($userAccounts['account'])){
- return $ this->getUserInfoByMainAccount($ userAccounts['account'],$userAccounts['cid']);
- }
- return array();
- }
- /**
- * 透過主帳號取得子帳號
- */
- public function getUserInfoByAccount(>*/
- public function getUserInfoByAccount(>*/
- public function getUserInfoByAccount(>*/
- public function getUserInfoByAccount(>*/
- public function getUserInfoByAccount( ){
- if($this->accounttype==0){
-
- return $this->getUserInfoByMainAccount($this->account,$this-> ;cid);
- }else{
- return $this->getUserInfoByChildAccount($this->account,$this->cid,$this->accounttype);
- }
- }
- /**
- 取得目前商家的操作等級
- 1 對自己新增的使用者有完全權限,對其它機構新增的使用者無權限
- 2 對自己新增的使用者有完全權限,對accsessids指定機構的使用者有查詢權限
- **/
- public function getSubAccountByMainAccount(){
- $c=new CDbCriteria();
- $c->addCondition('cid=:cid AND account= :account', 'AND');
- $c- >params=array(':cid'=>$this->cid, ':account'=>$this->account);
- $refer=new AccountRefer();
- $result=$refer->getListByPage(1, 30, $c);
- $data=array();
- if($result[ ' count']>0){
- foreach($result['data'] as $row){
- $data[$row['accounttype']]=$row['subaccount'];
- }
- }
- return $data;
- }
- /***/
- public function getAccess(){
- if ($this->passportConfig = == null ) {
- $this->passportConfig = PassportConfig::model ()->getItemConfigById ( $this->cid ); }
- $ip=Yii::app ()->request->getUserHostAddress();
- $ips=CJSON::decode($passportConfig['iprouters']);
- if(!in_array ($ip,$ips)){
- throw new CHttpException(403, '이 페이지에 액세스할 수 있는 권한이 없습니다!');
- }
- }
- /**유명 브랜드 사용자의 개인정보 수정**/
- 공개 함수 saveUserAttributes($tickets,array $attributes){
- try{
- $user=$this ->getUserAttributes($tickets);
- if(empty($user) || !is_array($user)){
- return -1001;
- }
- $data=array();
- if($user[WebUserD::STORAGE_KEY]!=='[]'){
- $data=CJSON::decode($user[WebUserD::STORAGE_KEY]);
- }
- if(!is_array($data)){
- $data=array();
- }
- $attributes=array_change_key_case($attributes);
- foreach($attributes as $key=>$ 값){
- if(!is_array($value)){
- $data[$key]=$value;
- }else{
- if(!isset($data[$key]) ){
- $data[$key]=array();
- }
- $data[$key]=array_merge($data[$key],$attributes[$key]);
- }
- }
- $user[WebUserD::STORAGE_KEY]=CJSON::encode($data);
- $user['lastquesttime']=$_SERVER['REQUEST_TIME'];
- $user ['data']=CJSON::encode($data);
- $this->setAttributes($user,false);
- !$this->currentIP && $this->currentIP=' 127.0.0.1';
- !$this->lastip && $this->lastip=$this->currentIP;
-
-
- !$this->logintimes && $this- >logintimes = 0;
- $this->setIsNewRecord ( false );
- if($this->save()){
- UtilD::setCache('resposity', $tickets, $ user);
- }else{
- return -1003;
- }
- }catch(Exception $ex){
- return -1004;
- }
- }
- / **계정 개인 데이터 수정**/
- 공개 함수 saveUserAttributesByName( array $attributes){
- $user=$this->getUserInfoByMainAccount($this->account,$this->cid);
- if(empty($user)){
- return -1001;
- }
- $cacheKey = hash ( 'md5', $user['account'].'^]'.$user['cid '].'^]'.'0' );
- return $this-> saveUserAttributes($cacheKey,$attributes);
-
- }
- /**
- @return 배열
- 토큰을 기반으로 모든 계정 데이터 가져오기
- **/
- 공개 함수 getUserAttributes($tickets){
- $t = hash ( 'md5', $tickets . $this->currentIP . $this->cid );
- $ft=UtilD::getCache('resposity) ', $t);
- if (! $ft) {
- $ft = 0;
- } else {
- if ($ft > 4) { //如果1个ip 1分钟内连续5次获取失败
- return -1005;
- }
- }
- $user=UtilD::getCache('respososity',$tickets);
- if(!$user){
- $ft ;
- UtilD::setCache('respososity', $t,$ft,60);
- return -1001;
- }
- $user['lastquesttime']=$ _SERVER['REQUEST_TIME'];
- UtilD::setCache('respoosity',$tickets,$user);
- return $user;
- }
- /**기본 계정 추가**/
- 공개 함수 add(){
- 시도{
- if($this->accounttype!=0){
- return -1000;
- }
- $this->account=strtolower ($this->account);
- //检查主帐号是否存재
- $user=$this->getUserInfoByAccount();
- if(is_array($user) && count($user) ){
- return -1006;
- }
- //开始保存数据
- $this->setIsNewRecord ( true );
- $this->lastquesttime=$_SERVER['REQUEST_TIME' ];
- $this->regtime=$_SERVER['REQUEST_TIME'];
- $this->data='[]';
- $this->pwd=hash('sha256' ,$this->pwd);
-
- if(!$this->save()){
- return -1007;
- }else{
- $user=$this- >getAttributes();
- $cacheKey = hash ( 'md5',$this->account.'^]'.$this->cid.'^]'.$this->accounttype );
- UtilD::setCache('resposity', $cacheKey, $user);
- }
- }catch(Exception $ex){
- return -1004;
- }
- }
- /**연결된 하위 계정**/
- 공용 함수 addChild($subaccount){
- try{
- //检查子是否유동이름이 있는 帐号与主账号关联
- $subaccount=strtolower( $subaccount);
- $user=$this->getUserInfoByChildAccount($subaccount,$this->cid,$this->accounttype);
- if($user){
- return -1008 ;
- }
- $user=$this->getUserInfoByMainAccount($this->account,$this->cid);
- if(!$user){
- return -1001;
- }
- //유효한 정보 제공
- $accountRefer=new AccountRefer();
- $model=$accountRefer->find('pid=:pid AND cid =:cid AND 계정 유형=:accounttype', 배열 (':pid'=>$user['id'],':cid'=>$this->cid,':accounttype'=>$this ->계정 유형));
- if($model){
- return -1009;
- }
- $this->account=strtolower($this->account);
- $accountRefer->cid=$this->cid;
- $accountRefer->setIsNewRecord (true );
- $accountRefer->pid=$user['id'];
- $accountRefer->account=$user['account'];
- $accountRefer->subaccount=$subaccount;
- $
- $ accountRefer->accounttype=$this->accounttype;
- if($accountRefer->save()){
- $cacheKey = hash ( 'md5',$accountRefer->subaccount. '^]'.$accountRefer ->cid.'^]'.$accountRefer->accounttype );
- UtilD::setCache('resposity', $cacheKey, $accountRefer->getAttributes());
- }else{
- return -1010;
- }
- }catch(Exception $ex){
- return -1004;
- }
- }
- /**修改密碼**/
- public function changePassword(){
- try{
- $user=$this->getUserInfoByAccount();//檢查主帳號是否存在
- if(!$user){
- return -1001;
- }
- $this->setIsNewRecord ( false );
- $this->pwd=hash('sha256',$this->pwd);
- if($ this->pwd!==$user['pwd']){
- $this->setIsNewRecord ( false );
- $user['pwd']=$this->; pwd;
- $this->setAttributes($user,false);
- if($this->save()){
- $cacheKey = hash ( 'md5', $user['帳號'] .'^]'.$user['cid'].'^]'.'0' );
- UtilD::setCache('resposity', $cacheKey, $user);
- }else {
- return -1011;
- }
- }
- }catch(異常$ex){
- return -1004;
- }
- }
- /**修改子帳號** /
- public function repickAccount(){
- try{
- $accounts=$this->getUserInfoByChildAccount($this->oldaccount,$this->cid,$this->accounttype );
- if
- if (!$accounts){
- return -1001;
- }
- $cacheKey = hash ( 'md5',$this->oldaccount.'^]'.$this->cid.'^]' .$this->accounttype );
- $user=UtilD::getCache('resposity', $cacheKey);
- if($this->oldaccount!== $this->account){
- $accountRefer=new AccountRefer();
- $accountRefer->setIsNewRecord ( false );
- $accountRefer->setAttributes($user,false);
- $accountRefer->subaccount=$this->count;
- if($accountRefer->save()){
- $user['subaccount']=$this->account;
- UtilD::setCache('resposity', $cacheKey,array()) ;
- $cacheKey= hash ( 'md5',$user['子帳號'].'^]'.$this->cid. '^]'.$this->accounttype );
- UtilD::setCache('resposity', $cacheKey,$user);
- }else{
- return -1012;
- }
- }
- }catch(Exception $ex){
- return -1004;
- }
- }
- /**
- 刪除主帳號
- **/
- public function deleteMainAccount(🎝>*/
- public function deleteMainAccount(){ 嘗試{
- $user=$this->getUserInfoByMainAccount($this->account,$this->cid);
- if(!$user){
- return -1001;
- }
- //檢查是否有子帳號
- $accountRefer=new AccountRefer();
- $models=$accountRefer->findAll('pid=:pid', array (':pid' =>$user[ 'id']));
- if(is_array($models)&&count($models)){
- foreach($models as $model){
- $k= hash ( 'md5', $model ->subaccount.'^]'.$model->cid.'^]'.$model->accounttype );//刪除子帳號硬碟
- UtilD::setCache( 'resposity', $k,false) ;
- unset($model);
- }
- unset($models);
- }
- // 刪除主帳號伺服器
- $cacheKey = hash ( 'md5', $this ->account.'^]'.$this->cid.'^]'.'0' );
- if($this->deleteByPk($user ['id'])){
- UtilD ::setCache('resposity', $cacheKey,false);
- }else{
- return -1013;
- }
- }catch(異常$ex){
- return -1004;
- }
- }
- /**刪除子帳號**/
- public function deleteChildAccount(){
- try{
- $user= $this->getUserInfoByChildAccount($this->account, $this->cid,$this->accounttype);
- if(!$user){
- return -1014;
- }
- //刪除伺服器
- $cacheKey = hash ( ' md5', $this->account.'^]'.$this->cid.'^]'.$this->accounttype ) ;
- $child=UtilD::getCache('resposity',$cacheKey) ;
- $accountRefer=new AccountRefer();
- if($accountRefer->deleteByPk($child['id']) )){
- UtilD::setCache('resposity', $cacheKey,false );
- }else{
- 回傳-1014;
- }
- }catch(異常$ex){
- return -1004;
- }
- }
- 公用函數登入(){
- try{
- if(empty($this->currentIP)){
- return -1017 ;
- }
- $tickets=hash ( 'md5', $this- >account.'^]'.$this->cid.'^]'.$this->accounttype );
- $t = hash ( 'md5', $tickets . '&' 。 ;
- if (! $ft) {
- $ft = 0;
- } else {
- if ($ft > 4) { //如果1個ip 1分鐘內連續5次獲取失敗
- 回傳-1015;
- } }
- $user=$this->getUserInfoByAccount();
- if(!$user){
- $ft ;
- UtilD::setCache('resposity', $t,$ft,60 );
- return -1001;
- }
- $this->pwd=hash('sha256',$this->pwd);
- if($user['pwd']! ==$this->pwd){
- $ft ;
- UtilD::setCache('resposity', $t,$ft,60);
- return -1016;
- }
- $tickets=hash ( 'md5', $user['account'].'^]'.$user['cid'].'^]'.'0' );
- //새로운 버전으로 전환最后请求时间
- if(!isset($user['currentIP'])){
- $user['currentIP']=$this->currentIP;
- }
- $user[' lastip']=$user['currentIP'];
- $user['currentIP']=$this->currentIP;
- if(!isset($user['logintimes'])){
- $user['logintimes']=0;
- }
- $user['logintimes'] ;
- $user['lastquesttime']=$_SERVER['REQUEST_TIME'];
- $this ->setAttributes($user,false);
- if($this->save()){
- UtilD::setCache('resposity', $tickets,$user);
- 배열 반환 ('tickets'=>$tickets);
- }else{
- return -1017;
- }
- }catch(Exception $ex){
- return -1004;
- }
- }
- }
-
复제대码
|