S
S
Sergey2015-03-09 19:31:56
Yii
Sergey, 2015-03-09 19:31:56

How to change the basic login to work with data from the database in yii2?

I wrote my controller and model for registration, because registration on my project is complicated, in several steps, a lot of data, different types of registration. Those. ready-made solutions could not pull.
But I would not want to bother with authorization, because. e-mail and password from the database are used for authorization.
I can’t pull ready-made solutions / modules, because registration is ready.
But it would be quite a solution to remake the basic template to work from the database.
But I don’t want to figure it out yet, because it’s not a fact that it will be faster. But I would be happy to accept a link to an article \ manual where this is implemented, so that I can read it and quickly do it. Does anyone know similar?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2015-03-13
@butteff

In general stuck with crutches in the existing code.
in the findIdentity($id) method, by this id, I look for a record about the user, form an array, as a standard one, and override it with the values ​​of this array. This method checks the logged in user.
And for validation, I did the same in findByUsername($username)
Well, in the validatePassword($password) method, I had to add md5 password generation, that's all.

S
Sergey Semenko, 2015-03-12
@abler98

class User extends ActiveRecord implements IdentityInterface {
  public static function tableName() {
    return 'users';
  }
  
  public static function findIdentity($id) {
    return static::findOne($id);
  }
  
  public static function findIdentityByAccessToken($token, $type = null) {
    return static::findOne(['access_token' => $token]);
  }
  
  public function getId() {
    return $this->getPrimaryKey();
  }
  
  public function getAuthKey() {
    return $this->auth_key;
  }
  
  public function validateAuthKey($authKey) {
    return $this->getAuthKey() === $authKey;
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question