Usuario.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "Usuario".
  6. *
  7. * @property string $id
  8. * @property string $correo
  9. * @property string $clave
  10. * @property string $nombre
  11. * @property int|null $estatus 0:inactivo, 1:activo
  12. * @property string $telefono
  13. * @property string|null $alias
  14. * @property string|null $foto
  15. * @property string $rol
  16. * @property string|null $creado
  17. * @property string|null $modificado
  18. * @property string|null $eliminado
  19. *
  20. * @property Media[] $media
  21. */
  22. class Usuario extends ModeloBase {
  23. public const ACTIVO = 1;
  24. public const INACTIVO = 0;
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public static function tableName() {
  29. return 'Usuario';
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function rules() {
  35. return [
  36. [['id', 'correo', 'clave', 'nombre', 'telefono', 'rol'], 'required'],
  37. [['estatus'], 'default', 'value' => null],
  38. [['estatus'], 'integer'],
  39. [['creado', 'modificado', 'eliminado'], 'safe'],
  40. [['id'], 'string', 'max' => 36],
  41. [['correo', 'clave', 'nombre', 'telefono', 'alias', 'rol'], 'string', 'max' => 100],
  42. [['foto'], 'string', 'max' => 300],
  43. [['id'], 'unique'],
  44. ];
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function attributeLabels() {
  50. return [
  51. 'id' => 'ID',
  52. 'correo' => 'Correo',
  53. 'clave' => 'Clave',
  54. 'nombre' => 'Nombre',
  55. 'estatus' => 'Estatus',
  56. 'telefono' => 'Telefono',
  57. 'alias' => 'Alias',
  58. 'foto' => 'Foto',
  59. 'rol' => 'Rol',
  60. 'creado' => 'Creado',
  61. 'modificado' => 'Modificado',
  62. 'eliminado' => 'Eliminado',
  63. ];
  64. }
  65. /**
  66. * Gets query for [[media]].
  67. *
  68. * @return \yii\db\ActiveQuery
  69. */
  70. public function getMedia() {
  71. return $this->hasMany(Media::class, ['idUsuario' => 'id']);
  72. }
  73. public function agregarClave($pwd) {
  74. $this->clave = Yii::$app->getSecurity()->generatePasswordHash($pwd);
  75. }
  76. public function validarClave($pwd) {
  77. return Yii::$app->getSecurity()->validatePassword($pwd, $this->clave);
  78. }
  79. }