You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					62 lines
				
				1.0 KiB
			
		
		
			
		
	
	
					62 lines
				
				1.0 KiB
			| 
								 
											13 years ago
										 
									 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								namespace app\models;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class User extends \yii\base\Object implements \yii\web\Identity
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
									public $id;
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
									public $username;
							 | 
						||
| 
								 | 
							
									public $password;
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
									public $authKey;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									private static $users = array(
							 | 
						||
| 
								 | 
							
										'100' => array(
							 | 
						||
| 
								 | 
							
											'id' => '100',
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
											'username' => 'admin',
							 | 
						||
| 
								 | 
							
											'password' => 'admin',
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
											'authKey' => 'test100key',
							 | 
						||
| 
								 | 
							
										),
							 | 
						||
| 
								 | 
							
										'101' => array(
							 | 
						||
| 
								 | 
							
											'id' => '101',
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
											'username' => 'demo',
							 | 
						||
| 
								 | 
							
											'password' => 'demo',
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
											'authKey' => 'test101key',
							 | 
						||
| 
								 | 
							
										),
							 | 
						||
| 
								 | 
							
									);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									public static function findIdentity($id)
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
										return isset(self::$users[$id]) ? new self(self::$users[$id]) : null;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
									public static function findByUsername($username)
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
										foreach (self::$users as $user) {
							 | 
						||
| 
								 | 
							
											if (strcasecmp($user['username'], $username) === 0) {
							 | 
						||
| 
								 | 
							
												return new self($user);
							 | 
						||
| 
								 | 
							
											}
							 | 
						||
| 
								 | 
							
										}
							 | 
						||
| 
								 | 
							
										return null;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
									public function getId()
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
										return $this->id;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									public function getAuthKey()
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
										return $this->authKey;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									public function validateAuthKey($authKey)
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
										return $this->authKey === $authKey;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
									public function validatePassword($password)
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
										return $this->password === $password;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
								}
							 |