I’ve install the basic structure of Yii 2.0-alpha latest version.
And i’m trying to change the login to use the data from my database which has following field
-
uid
-
username
-
password
-
authKey
-
email
All i did it using Gii to overwrite new generated User model and did implement IdentityInterface and not forgetting to add the implemented method.
I’m also add validatePassword & findByUsername method to corresponding to the existed demo coding.
the getId method also return $this->uid since the name is different.
Unfortunately, after login complete, there is no any error show in every channel (error_log.log / yii log / browser etc.)
The browser just say, not receiving data with HTTP 302 status. and php error_log just empty.
That weird.
If anyone would have any suggestion, i’d be really appreciated.
Here is my coding in User.php file
<?php
namespace app\models;
/**
* This is the model class for table "user".
*
* @property integer $uid
* @property string $username
* @property string $password
* @property string $email
* @property string $authKey
*/
class User extends \yii\db\ActiveRecord implements \yii\web\IdentityInterface
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'user';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['username', 'password', 'email', 'authKey'], 'required'],
[['username', 'email'], 'string', 'max' => 50],
[['password', 'authKey'], 'string', 'max' => 255]
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'uid' => 'Uid',
'username' => 'Username',
'password' => 'Password',
'email' => 'Email',
'authKey' => 'Auth Key',
];
}
public function getAuthKey() {
return $this->authKey;
}
public function getId() {
return $this->uid;
}
public function validateAuthKey($authKey) {
return $this->authKey === $authKey;
}
public function validatePassword($pwd) {
return (crypt($pwd, $this->password) == $this->password);
}
public static function findByUsername($username){
$model = self::find(['username' => $username]);
if(isset($model)){
return new static($model->getAttributes());
}else{
return null;
}
}
public static function findIdentity($id) {
$model = self::find($id);
if(isset($model)){
return new static($model->getAttributes());
}else{
return null;
}
}
}