찾다

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


성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
로드 밸런싱이 세션 관리에 어떤 영향을 미치는지 설명하고 해결 방법을 설명하십시오.로드 밸런싱이 세션 관리에 어떤 영향을 미치는지 설명하고 해결 방법을 설명하십시오.Apr 29, 2025 am 12:42 AM

로드 밸런싱은 세션 관리에 영향을 미치지 만 세션 복제, 세션 끈적임 및 중앙 집중식 세션 스토리지로 해결할 수 있습니다. 1. 세션 복제 복사 서버 간의 세션 데이터. 2. 세션 끈은 사용자 요청을 동일한 서버로 안내합니다. 3. 중앙 집중식 세션 스토리지는 Redis와 같은 독립 서버를 사용하여 세션 데이터를 저장하여 데이터 공유를 보장합니다.

세션 잠금의 개념을 설명하십시오.세션 잠금의 개념을 설명하십시오.Apr 29, 2025 am 12:39 AM

SessionLockingIsateChniqueSureDureauser의 SessionLockingSsessionRemainSexclusivetoOneuseratatime.itiscrucialforpreptingdatacorruptionandsecurityBreachesInmulti-userApplications.sessionLockingSogingSompletEdusingserVerver-sidelockingMegynisms, unrasprantlockinj

PHP 세션에 대한 대안이 있습니까?PHP 세션에 대한 대안이 있습니까?Apr 29, 2025 am 12:36 AM

PHP 세션의 대안에는 쿠키, 토큰 기반 인증, 데이터베이스 기반 세션 및 Redis/Memcached가 포함됩니다. 1. Cookies는 클라이언트에 데이터를 저장하여 세션을 관리합니다. 이는 단순하지만 보안이 적습니다. 2. Token 기반 인증은 토큰을 사용하여 사용자를 확인합니다. 이는 매우 안전하지만 추가 논리가 필요합니다. 3. Database 기반 세션은 데이터베이스에 데이터를 저장하여 확장 성이 좋지만 성능에 영향을 줄 수 있습니다. 4. Redis/Memcached는 분산 캐시를 사용하여 성능 및 확장 성을 향상하지만 추가 일치가 필요합니다.

PHP의 맥락에서 '세션 납치'라는 용어를 정의하십시오.PHP의 맥락에서 '세션 납치'라는 용어를 정의하십시오.Apr 29, 2025 am 12:33 AM

SessionHijacking은 사용자의 SessionID를 얻음으로써 사용자를 가장하는 공격자를 말합니다. 예방 방법은 다음과 같습니다. 1) HTTPS를 사용한 의사 소통 암호화; 2) SessionID의 출처를 확인; 3) 보안 세션 생성 알고리즘 사용; 4) 정기적으로 SessionID를 업데이트합니다.

PHP의 전체 형태는 무엇입니까?PHP의 전체 형태는 무엇입니까?Apr 28, 2025 pm 04:58 PM

이 기사는 PHP에 대해 설명하고, 전체 형식, 웹 개발의 주요 용도, Python 및 Java와의 비교 및 ​​초보자를위한 학습 용이성을 자세히 설명합니다.

PHP는 양식 데이터를 어떻게 처리합니까?PHP는 양식 데이터를 어떻게 처리합니까?Apr 28, 2025 pm 04:57 PM

PHP는 유효성 검사, 소독 및 보안 데이터베이스 상호 작용을 통해 보안을 보장하면서 $ \ _ post 및 $ \ _를 사용하여 데이터 양식 데이터를 처리합니다.

PHP와 ASP.NET의 차이점은 무엇입니까?PHP와 ASP.NET의 차이점은 무엇입니까?Apr 28, 2025 pm 04:56 PM

이 기사는 PHP와 ASP.NET을 비교하여 대규모 웹 응용 프로그램, 성능 차이 및 보안 기능에 대한 적합성에 중점을 둡니다. 둘 다 대규모 프로젝트에서는 실용적이지만 PHP는 오픈 소스 및 플랫폼 독립적이며 ASP.NET,

PHP는 사례에 민감한 언어입니까?PHP는 사례에 민감한 언어입니까?Apr 28, 2025 pm 04:55 PM

PHP의 사례 감도는 다양합니다. 함수는 무감각하고 변수와 클래스는 민감합니다. 모범 사례에는 일관된 이름 지정 및 비교를위한 사례 감수 기능 사용이 포함됩니다.

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

에디트플러스 중국어 크랙 버전

에디트플러스 중국어 크랙 버전

작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

VSCode Windows 64비트 다운로드

VSCode Windows 64비트 다운로드

Microsoft에서 출시한 강력한 무료 IDE 편집기

SecList

SecList

SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.

ZendStudio 13.5.1 맥

ZendStudio 13.5.1 맥

강력한 PHP 통합 개발 환경