Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace app\models;
- use Yii;
- use yii\web\IdentityInterface;
- use yii\db\ActiveRecord;
- /**
- * This is the model class for table "aza_users".
- *
- * @property int $id
- * @property string $login
- * @property string $pass
- * @property string $email
- * @property string $name
- */
- class UserModel extends ActiveRecord implements IdentityInterface
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'aza_users';
- }
- /**
- * Finds an identity by the given ID.
- *
- * @param string|int $id the ID to be looked for
- * @return IdentityInterface|null the identity object that matches the given ID.
- */
- public static function findIdentity($id)
- {
- return static::findOne($id);
- }
- /**
- * Finds an identity by the given token.
- *
- * @param string $token the token to be looked for
- * @return IdentityInterface|null the identity object that matches the given token.
- */
- public static function findIdentityByAccessToken($token, $type = null)
- {
- return static::findOne(['access_token' => $token]);
- }
- /**
- * @return int|string current user ID
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * @return string current user auth key
- */
- public function getAuthKey()
- {
- return $this->auth_key;
- }
- public function validateAuthKey($authKey)
- {
- return $this->getAuthKey() === $authKey;
- }
- public function validatePassword($password)
- {
- return Yii::$app->getSecurity()->validatePassword($password,$this->pass);
- }
- public static function SingUp ($model)
- {
- $RegUser=new UserModel();
- $RegUser->login=$model->login;
- $RegUser->pass= Yii::$app->getSecurity()->generatePasswordHash($model->pass);
- $RegUser->email=$model->email;
- $RegUser->name= $model->name;
- return $RegUser->save();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement