Usuario.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "Usuario".
  6. *
  7. * @property int $id
  8. * @property string $rfc
  9. * @property string $correo
  10. * @property string $clave
  11. * @property string $nombre
  12. * @property string $apellidoPaterno
  13. * @property int|null $estatus 0:inactivo, 1:activo
  14. */
  15. class Usuario extends \yii\db\ActiveRecord {
  16. public const ACTIVO = 1;
  17. public const INACTIVO = 0;
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public static function tableName() {
  22. return 'Usuario';
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function rules() {
  28. return [
  29. [['rfc', 'correo', 'clave', 'nombre', 'apellidoPaterno'], 'required'],
  30. [['estatus'], 'default', 'value' => null],
  31. [['estatus'], 'integer'],
  32. [['rfc'], 'string', 'max' => 13],
  33. [['correo', 'clave', 'nombre', 'apellidoPaterno'], 'string', 'max' => 100],
  34. ];
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function attributeLabels() {
  40. return [
  41. 'id' => 'ID',
  42. 'rfc' => 'Rfc',
  43. 'correo' => 'Correo',
  44. 'clave' => 'Clave',
  45. 'nombre' => 'Nombre',
  46. 'apellidoPaterno' => 'Apellido Paterno',
  47. 'apellidoMaterno' => 'Apellido Materno',
  48. 'estatus' => 'Estatus',
  49. ];
  50. }
  51. public function agregarClave($pwd) {
  52. $this->clave = Yii::$app->getSecurity()->generatePasswordHash($pwd);
  53. }
  54. public function validarClave($pwd) {
  55. return Yii::$app->getSecurity()->validatePassword($pwd, $this->clave);
  56. }
  57. }