Advertisement
Guest User

Untitled

a guest
Mar 8th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. <?php
  2.  
  3. namespace app\models;
  4.  
  5. use Yii;
  6. use yii\web\IdentityInterface;
  7. use yii\db\ActiveRecord;
  8.  
  9. /**
  10. * This is the model class for table "aza_users".
  11. *
  12. * @property int $id
  13. * @property string $login
  14. * @property string $pass
  15. * @property string $email
  16. * @property string $name
  17. */
  18.  
  19.  
  20.  
  21.  
  22. class UserModel extends ActiveRecord implements IdentityInterface
  23. {
  24. /**
  25. * @inheritdoc
  26. */
  27. public static function tableName()
  28. {
  29. return 'aza_users';
  30. }
  31.  
  32.  
  33. /**
  34. * Finds an identity by the given ID.
  35. *
  36. * @param string|int $id the ID to be looked for
  37. * @return IdentityInterface|null the identity object that matches the given ID.
  38. */
  39. public static function findIdentity($id)
  40. {
  41. return static::findOne($id);
  42. }
  43.  
  44. /**
  45. * Finds an identity by the given token.
  46. *
  47. * @param string $token the token to be looked for
  48. * @return IdentityInterface|null the identity object that matches the given token.
  49. */
  50. public static function findIdentityByAccessToken($token, $type = null)
  51. {
  52. return static::findOne(['access_token' => $token]);
  53. }
  54.  
  55. /**
  56. * @return int|string current user ID
  57. */
  58. public function getId()
  59. {
  60. return $this->id;
  61. }
  62.  
  63. /**
  64. * @return string current user auth key
  65. */
  66. public function getAuthKey()
  67. {
  68. return $this->auth_key;
  69. }
  70.  
  71. public function validateAuthKey($authKey)
  72. {
  73. return $this->getAuthKey() === $authKey;
  74. }
  75.  
  76.  
  77.  
  78. public function validatePassword($password)
  79. {
  80. return Yii::$app->getSecurity()->validatePassword($password,$this->pass);
  81. }
  82.  
  83. public static function SingUp ($model)
  84. {
  85. $RegUser=new UserModel();
  86. $RegUser->login=$model->login;
  87. $RegUser->pass= Yii::$app->getSecurity()->generatePasswordHash($model->pass);
  88. $RegUser->email=$model->email;
  89. $RegUser->name= $model->name;
  90.  
  91. return $RegUser->save();
  92. }
  93.  
  94.  
  95.  
  96.  
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement