登入認證

WBOY
發布: 2016-07-25 08:50:14
原創
1127 人瀏覽過
  1. /*
  2. *
  3. * @copyright 2011
  4. * @version $Id$
  5. * @access public
  6. * @version $Id$
  7. * @access public
  8. * @property string $id
  9. * @property string $account
  10. * @property string $pwd
  11. * @property string $lastquesttime
  12. * @property string $lastip
  13. * @property int regtime
  14. * @property int $accounttype
  15. * @property string $oldaccount
  16. * @property int $logintimes
  17. * @property string $currentIP
  18. * @property intcidclass Resposity extends AdminActiveRecord {
  19. public $connectionPrefix = 'passport';
  20. protected $list = null;
  21. protected $passportConfig = null;
  22. public_account = protected; > /**
  23. * 傳回指定 AR 類別的靜態模型。
  24. * @return Resposity 靜態模型類別
  25. */
  26. 公用靜態函式模型($className = __class__) {
  27. returnparent::model ( $className );
  28. }
  29. /**
  30. * 如果需要請修改它。
  31. * @return 混合了primaryKey。
  32. */
  33. public function PrimaryKey() {
  34. return 'id';
  35. }
  36. /**
  37. * @return 模型屬性的陣列驗證規則。
  38. */
  39. public function Rules() {
  40. 根據主帳號取得使用者資訊
  41. * // 注意:您應該只為
  42. // 將接收使用者輸入的屬性定義規則。 '帳戶類型', 'in', '範圍' => array ('0', '1', '2', '3', '4', '5', '6', '7' ) ),
  43. array ('currentIP', 'ip')
  44. );
  45. }
  46. /**根據子帳號取得使用者資訊**/
  47. protected function getUserInfoByMainAccount($account,$cid){
  48. $account=strtolower($account);
  49. $cacheKey = hash ( 'md5', $account.'^]'.$cid.'^]'.'0' );
  50. $user=UtilD: :getCache('resposity',$cacheKey);
  51. if(is_array($user)){
  52. UtilD::clearNullOrEmptyValue ( $user );
  53. }else{
  54. $user=array() ;
  55. }
  56. if(count($user) )){
  57. return $user;
  58. }else{
  59. $model = $this->find ( 'account=:account AND cid =:cid', array (':帳戶' =>; $account,':cid' => $cid ) );
  60. if($model){
  61. $user=$model->getAttributes();
  62. unset($model);
  63. }
  64. UtilD::setCache('resposity',$cacheKey,$user);
  65. return $user;
  66. }
  67. }
  68. /**根據帳號類型取得使用者資料**/
  69. protected function getUserInfoByChildAccount($subaccount,$cid,$accounttype){
  70. if(!$ this->validate(array('accounttype'), true)){
  71. return -1000;
  72. }
  73. $subaccount=strtolower($subaccount);
  74. $cacheKey = hash ( 'md5 ' , $subaccount.'^]'.$cid.'^]'.$accounttype );
  75. $userAccounts=UtilD::getCache('resposity',$cacheKey);
  76. if(is_array($userAccounts) )){
  77. UtilD::clearNullOrEmptyValue($userAccounts);
  78. }else{
  79. $userAccounts=array();
  80. }
  81. if(!count($userAccounts));
  82. }
  83. if(!count($userAccounts)){ $accountRefer=new AccountRefer();
  84. $model=$accountRefer->find ( 'subaccount=:subaccount AND cid=:cid AND accounttype=:accounttype', array (':subaccount' => $subaccount ,' :cid' => $this->cid,':accounttype'=> $accounttype) );
  85. if($model){
  86. $userAccounts=$model->getAttributes() ;
  87. UtilD: :setCache('resposity',$cacheKey,$userAccounts);
  88. }
  89. }
  90. if(isset($userAccounts['account'])){
  91. return $ this->getUserInfoByMainAccount($ userAccounts['account'],$userAccounts['cid']);
  92. }
  93. return array();
  94. }
  95. /**
  96. * 透過主帳號取得子帳號
  97. */
  98. public function getUserInfoByAccount(>*/
  99. public function getUserInfoByAccount(>*/
  100. public function getUserInfoByAccount(>*/
  101. public function getUserInfoByAccount(>*/
  102. public function getUserInfoByAccount( ){
  103. if($this->accounttype==0){
  104. return $this->getUserInfoByMainAccount($this->account,$this-> ;cid);
  105. }else{
  106. return $this->getUserInfoByChildAccount($this->account,$this->cid,$this->accounttype);
  107. }
  108. }
  109. /**
  110. 取得目前商家的操作等級
  111. 1 對自己新增的使用者有完全權限,對其它機構新增的使用者無權限
  112. 2 對自己新增的使用者有完全權限,對accsessids指定機構的使用者有查詢權限
  113. **/
  114. public function getSubAccountByMainAccount(){
  115. $c=new CDbCriteria();
  116. $c->addCondition('cid=:cid AND account= :account', 'AND');
  117. $c- >params=array(':cid'=>$this->cid, ':account'=>$this->account);
  118. $refer=new AccountRefer();
  119. $result=$refer->getListByPage(1, 30, $c);
  120. $data=array();
  121. if($result[ ' count']>0){
  122. foreach($result['data'] as $row){
  123. $data[$row['accounttype']]=$row['subaccount'];
  124. }
  125. }
  126. return $data;
  127. }
  128. /***/
  129. public function getAccess(){
  130. if ($this->passportConfig = == null ) {
  131. $this->passportConfig = PassportConfig::model ()->getItemConfigById ( $this->cid ); }
  132. $ip=Yii::app ()->request->getUserHostAddress();
  133. $ips=CJSON::decode($passportConfig['iprouters']);
  134. if(!in_array ($ip,$ips)){
  135. throw new CHttpException(403, '이 페이지에 액세스할 수 있는 권한이 없습니다!');
  136. }
  137. }
  138. /**유명 브랜드 사용자의 개인정보 수정**/
  139. 공개 함수 saveUserAttributes($tickets,array $attributes){
  140. try{
  141. $user=$this ->getUserAttributes($tickets);
  142. if(empty($user) || !is_array($user)){
  143. return -1001;
  144. }
  145. $data=array();
  146. if($user[WebUserD::STORAGE_KEY]!=='[]'){
  147. $data=CJSON::decode($user[WebUserD::STORAGE_KEY]);
  148. }
  149. if(!is_array($data)){
  150. $data=array();
  151. }
  152. $attributes=array_change_key_case($attributes);
  153. foreach($attributes as $key=>$ 값){
  154. if(!is_array($value)){
  155. $data[$key]=$value;
  156. }else{
  157. if(!isset($data[$key]) ){
  158. $data[$key]=array();
  159. }
  160. $data[$key]=array_merge($data[$key],$attributes[$key]);
  161. }
  162. }
  163. $user[WebUserD::STORAGE_KEY]=CJSON::encode($data);
  164. $user['lastquesttime']=$_SERVER['REQUEST_TIME'];
  165. $user ['data']=CJSON::encode($data);
  166. $this->setAttributes($user,false);
  167. !$this->currentIP && $this->currentIP=' 127.0.0.1';
  168. !$this->lastip && $this->lastip=$this->currentIP;
  169. !$this->logintimes && $this- >logintimes = 0;
  170. $this->setIsNewRecord ( false );
  171. if($this->save()){
  172. UtilD::setCache('resposity', $tickets, $ user);
  173. }else{
  174. return -1003;
  175. }
  176. }catch(Exception $ex){
  177. return -1004;
  178. }
  179. }
  180. / **계정 개인 데이터 수정**/
  181. 공개 함수 saveUserAttributesByName( array $attributes){
  182. $user=$this->getUserInfoByMainAccount($this->account,$this->cid);
  183. if(empty($user)){
  184. return -1001;
  185. }
  186. $cacheKey = hash ( 'md5', $user['account'].'^]'.$user['cid '].'^]'.'0' );
  187. return $this-> saveUserAttributes($cacheKey,$attributes);
  188. }
  189. /**
  190. @return 배열
  191. 토큰을 기반으로 모든 계정 데이터 가져오기
  192. **/
  193. 공개 함수 getUserAttributes($tickets){
  194. $t = hash ( 'md5', $tickets . $this->currentIP . $this->cid );
  195. $ft=UtilD::getCache('resposity) ', $t);
  196. if (! $ft) {
  197. $ft = 0;
  198. } else {
  199. if ($ft > 4) { //如果1个ip 1分钟内连续5次获取失败
  200. return -1005;
  201. }
  202. }
  203. $user=UtilD::getCache('respososity',$tickets);
  204. if(!$user){
  205. $ft ;
  206. UtilD::setCache('respososity', $t,$ft,60);
  207. return -1001;
  208. }
  209. $user['lastquesttime']=$ _SERVER['REQUEST_TIME'];
  210. UtilD::setCache('respoosity',$tickets,$user);
  211. return $user;
  212. }
  213. /**기본 계정 추가**/
  214. 공개 함수 add(){
  215. 시도{
  216. if($this->accounttype!=0){
  217. return -1000;
  218. }
  219. $this->account=strtolower ($this->account);
  220. //检查主帐号是否存재
  221. $user=$this->getUserInfoByAccount();
  222. if(is_array($user) && count($user) ){
  223. return -1006;
  224. }
  225. //开始保存数据
  226. $this->setIsNewRecord ( true );
  227. $this->lastquesttime=$_SERVER['REQUEST_TIME' ];
  228. $this->regtime=$_SERVER['REQUEST_TIME'];
  229. $this->data='[]';
  230. $this->pwd=hash('sha256' ,$this->pwd);
  231. if(!$this->save()){
  232. return -1007;
  233. }else{
  234. $user=$this- >getAttributes();
  235. $cacheKey = hash ( 'md5',$this->account.'^]'.$this->cid.'^]'.$this->accounttype );
  236. UtilD::setCache('resposity', $cacheKey, $user);
  237. }
  238. }catch(Exception $ex){
  239. return -1004;
  240. }
  241. }
  242. /**연결된 하위 계정**/
  243. 공용 함수 addChild($subaccount){
  244. try{
  245. //检查子是否유동이름이 있는 帐号与主账号关联
  246. $subaccount=strtolower( $subaccount);
  247. $user=$this->getUserInfoByChildAccount($subaccount,$this->cid,$this->accounttype);
  248. if($user){
  249. return -1008 ;
  250. }
  251. $user=$this->getUserInfoByMainAccount($this->account,$this->cid);
  252. if(!$user){
  253. return -1001;
  254. }
  255. //유효한 정보 제공
  256. $accountRefer=new AccountRefer();
  257. $model=$accountRefer->find('pid=:pid AND cid =:cid AND 계정 유형=:accounttype', 배열 (':pid'=>$user['id'],':cid'=>$this->cid,':accounttype'=>$this ->계정 유형));
  258. if($model){
  259. return -1009;
  260. }
  261. $this->account=strtolower($this->account);
  262. $accountRefer->cid=$this->cid;
  263. $accountRefer->setIsNewRecord (true );
  264. $accountRefer->pid=$user['id'];
  265. $accountRefer->account=$user['account'];
  266. $accountRefer->subaccount=$subaccount;
  267. $
  268. $ accountRefer->accounttype=$this->accounttype;
  269. if($accountRefer->save()){
  270. $cacheKey = hash ( 'md5',$accountRefer->subaccount. '^]'.$accountRefer ->cid.'^]'.$accountRefer->accounttype );
  271. UtilD::setCache('resposity', $cacheKey, $accountRefer->getAttributes());
  272. }else{
  273. return -1010;
  274. }
  275. }catch(Exception $ex){
  276. return -1004;
  277. }
  278. }
  279. /**修改密碼**/
  280. public function changePassword(){
  281. try{
  282. $user=$this->getUserInfoByAccount();//檢查主帳號是否存在
  283. if(!$user){
  284. return -1001;
  285. }
  286. $this->setIsNewRecord ( false );
  287. $this->pwd=hash('sha256',$this->pwd);
  288. if($ this->pwd!==$user['pwd']){
  289. $this->setIsNewRecord ( false );
  290. $user['pwd']=$this->; pwd;
  291. $this->setAttributes($user,false);
  292. if($this->save()){
  293. $cacheKey = hash ( 'md5', $user['帳號'] .'^]'.$user['cid'].'^]'.'0' );
  294. UtilD::setCache('resposity', $cacheKey, $user);
  295. }else {
  296. return -1011;
  297. }
  298. }
  299. }catch(異常$ex){
  300. return -1004;
  301. }
  302. }
  303. /**修改子帳號** /
  304. public function repickAccount(){
  305. try{
  306. $accounts=$this->getUserInfoByChildAccount($this->oldaccount,$this->cid,$this->accounttype );
  307. if
  308. if (!$accounts){
  309. return -1001;
  310. }
  311. $cacheKey = hash ( 'md5',$this->oldaccount.'^]'.$this->cid.'^]' .$this->accounttype );
  312. $user=UtilD::getCache('resposity', $cacheKey);
  313. if($this->oldaccount!== $this->account){
  314. $accountRefer=new AccountRefer();
  315. $accountRefer->setIsNewRecord ( false );
  316. $accountRefer->setAttributes($user,false);
  317. $accountRefer->subaccount=$this->count;
  318. if($accountRefer->save()){
  319. $user['subaccount']=$this->account;
  320. UtilD::setCache('resposity', $cacheKey,array()) ;
  321. $cacheKey= hash ( 'md5',$user['子帳號'].'^]'.$this->cid. '^]'.$this->accounttype );
  322. UtilD::setCache('resposity', $cacheKey,$user);
  323. }else{
  324. return -1012;
  325. }
  326. }
  327. }catch(Exception $ex){
  328. return -1004;
  329. }
  330. }
  331. /**
  332. 刪除主帳號
  333. **/
  334. public function deleteMainAccount(🎝>*/
  335. public function deleteMainAccount(){ 嘗試{
  336. $user=$this->getUserInfoByMainAccount($this->account,$this->cid);
  337. if(!$user){
  338. return -1001;
  339. }
  340. //檢查是否有子帳號
  341. $accountRefer=new AccountRefer();
  342. $models=$accountRefer->findAll('pid=:pid', array (':pid' =>$user[ 'id']));
  343. if(is_array($models)&&count($models)){
  344. foreach($models as $model){
  345. $k= hash ( 'md5', $model ->subaccount.'^]'.$model->cid.'^]'.$model->accounttype );//刪除子帳號硬碟
  346. UtilD::setCache( 'resposity', $k,false) ;
  347. unset($model);
  348. }
  349. unset($models);
  350. }
  351. // 刪除主帳號伺服器
  352. $cacheKey = hash ( 'md5', $this ->account.'^]'.$this->cid.'^]'.'0' );
  353. if($this->deleteByPk($user ['id'])){
  354. UtilD ::setCache('resposity', $cacheKey,false);
  355. }else{
  356. return -1013;
  357. }
  358. }catch(異常$ex){
  359. return -1004;
  360. }
  361. }
  362. /**刪除子帳號**/
  363. public function deleteChildAccount(){
  364. try{
  365. $user= $this->getUserInfoByChildAccount($this->account, $this->cid,$this->accounttype);
  366. if(!$user){
  367. return -1014;
  368. }
  369. //刪除伺服器
  370. $cacheKey = hash ( ' md5', $this->account.'^]'.$this->cid.'^]'.$this->accounttype ) ;
  371. $child=UtilD::getCache('resposity',$cacheKey) ;
  372. $accountRefer=new AccountRefer();
  373. if($accountRefer->deleteByPk($child['id']) )){
  374. UtilD::setCache('resposity', $cacheKey,false );
  375. }else{
  376. 回傳-1014;
  377. }
  378. }catch(異常$ex){
  379. return -1004;
  380. }
  381. }
  382. 公用函數登入(){
  383. try{
  384. if(empty($this->currentIP)){
  385. return -1017 ;
  386. }
  387. $tickets=hash ( 'md5', $this- >account.'^]'.$this->cid.'^]'.$this->accounttype );
  388. $t = hash ( 'md5', $tickets . '&' 。 ;
  389. if (! $ft) {
  390. $ft = 0;
  391. } else {
  392. if ($ft > 4) { //如果1個ip 1分鐘內連續5次獲取失敗
  393. 回傳-1015;
  394. } }
  395. $user=$this->getUserInfoByAccount();
  396. if(!$user){
  397. $ft ;
  398. UtilD::setCache('resposity', $t,$ft,60 );
  399. return -1001;
  400. }
  401. $this->pwd=hash('sha256',$this->pwd);
  402. if($user['pwd']! ==$this->pwd){
  403. $ft ;
  404. UtilD::setCache('resposity', $t,$ft,60);
  405. return -1016;
  406. }
  407. $tickets=hash ( 'md5', $user['account'].'^]'.$user['cid'].'^]'.'0' );
  408. //새로운 버전으로 전환最后请求时间
  409. if(!isset($user['currentIP'])){
  410. $user['currentIP']=$this->currentIP;
  411. }
  412. $user[' lastip']=$user['currentIP'];
  413. $user['currentIP']=$this->currentIP;
  414. if(!isset($user['logintimes'])){
  415. $user['logintimes']=0;
  416. }
  417. $user['logintimes'] ;
  418. $user['lastquesttime']=$_SERVER['REQUEST_TIME'];
  419. $this ->setAttributes($user,false);
  420. if($this->save()){
  421. UtilD::setCache('resposity', $tickets,$user);
  422. 배열 반환 ('tickets'=>$tickets);
  423. }else{
  424. return -1017;
  425. }
  426. }catch(Exception $ex){
  427. return -1004;
  428. }
  429. }
  430. }
复제대码


相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板