diff --git a/composer.json b/composer.json index e5cc81f..135dc13 100644 --- a/composer.json +++ b/composer.json @@ -13,15 +13,13 @@ "require": { "yiisoft/yii2": "*", "yiisoft/yii2-authclient": "*", - "faro/core": "dev-develop" + "faro/core": "dev-feature/v20221-integracion-agro-gonza" }, "autoload": { "psr-4": { "faro\\core\\user\\": "src" } }, "extra": { - "branch-alias": { - "dev-develop": "2022.1-dev" - } + "branch-alias": {} }, "repositories": [ { diff --git a/src/controllers/AdminController.php b/src/controllers/AdminController.php index cfd873e..8f903f8 100644 --- a/src/controllers/AdminController.php +++ b/src/controllers/AdminController.php @@ -33,6 +33,8 @@ public function init() throw new ForbiddenHttpException('You are not allowed to perform this action.'); } + $this->view->params["navbar_menu_selected"] = "administracion"; + $this->view->params["ocultar_selector_fechas"] = true; parent::init(); } diff --git a/src/models/UserToken.php b/src/models/UserToken.php index 56e629b..32dfb07 100644 --- a/src/models/UserToken.php +++ b/src/models/UserToken.php @@ -46,54 +46,11 @@ class UserToken extends ActiveRecord public $module; /** - * @inheritdoc - */ - public function init() - { - if (!$this->module) { - $this->module = Yii::$app->getModule("user"); - } - } - - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'id' => Yii::t('user', 'ID'), - 'user_id' => Yii::t('user', 'User ID'), - 'type' => Yii::t('user', 'Type'), - 'token' => Yii::t('user', 'Token'), - 'data' => Yii::t('user', 'Data'), - 'created_at' => Yii::t('user', 'Created At'), - 'expired_at' => Yii::t('user', 'Expired At'), - ]; - } - - /** - * @inheritdoc - */ - public function behaviors() - { - return [ - 'timestamp' => [ - 'class' => 'yii\behaviors\TimestampBehavior', - 'updatedAtAttribute' => false, - 'value' => function ($event) { - return gmdate("Y-m-d H:i:s"); - }, - ], - ]; - } - - /** - * @return \yii\db\ActiveQuery + * @return string */ - public function getUser() + public static function tableName() { - $user = $this->module->model("User"); - return $this->hasOne($user::className(), ['id' => 'user_id']); + return "{{%core_acl_usuario_token}}"; } /** @@ -129,6 +86,18 @@ public static function generate($userId, $type, $data = null, $expireTime = null return $model; } + /** + * Find a userToken by userId + * @param int $userId + * @param array|int $type + * @param bool $checkExpiration + * @return static + */ + public static function findByUser($userId, $type, $checkExpiration = true) + { + return static::findBy("user_id", $userId, $type, $checkExpiration); + } + /** * Find a userToken by specified field/value * @param string $field @@ -139,7 +108,7 @@ public static function generate($userId, $type, $data = null, $expireTime = null */ public static function findBy($field, $value, $type, $checkExpiration) { - $query = static::find()->where([$field => $value, "type" => $type ]); + $query = static::find()->where([$field => $value, "type" => $type]); if ($checkExpiration) { $now = gmdate("Y-m-d H:i:s"); $query->andWhere("([[expired_at]] >= '$now' or [[expired_at]] is NULL)"); @@ -148,15 +117,15 @@ public static function findBy($field, $value, $type, $checkExpiration) } /** - * Find a userToken by userId - * @param int $userId + * Find a userToken by data + * @param string $data * @param array|int $type * @param bool $checkExpiration * @return static */ - public static function findByUser($userId, $type, $checkExpiration = true) + public static function findByData($data, $type, $checkExpiration = true) { - return static::findBy("user_id", $userId, $type, $checkExpiration); + return static::findBy("data", $data, $type, $checkExpiration); } /** @@ -172,14 +141,53 @@ public static function findByToken($token, $type, $checkExpiration = true) } /** - * Find a userToken by data - * @param string $data - * @param array|int $type - * @param bool $checkExpiration - * @return static + * @inheritdoc */ - public static function findByData($data, $type, $checkExpiration = true) + public function init() { - return static::findBy("data", $data, $type, $checkExpiration); + if (!$this->module) { + $this->module = Yii::$app->getModule("user"); + } + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => Yii::t('user', 'ID'), + 'user_id' => Yii::t('user', 'User ID'), + 'type' => Yii::t('user', 'Type'), + 'token' => Yii::t('user', 'Token'), + 'data' => Yii::t('user', 'Data'), + 'created_at' => Yii::t('user', 'Created At'), + 'expired_at' => Yii::t('user', 'Expired At'), + ]; + } + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + 'timestamp' => [ + 'class' => 'yii\behaviors\TimestampBehavior', + 'updatedAtAttribute' => false, + 'value' => function ($event) { + return gmdate("Y-m-d H:i:s"); + }, + ], + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getUser() + { + $user = $this->module->model("User"); + return $this->hasOne($user::className(), ['id' => 'user_id']); } } \ No newline at end of file diff --git a/src/views/admin/index.php b/src/views/admin/index.php index 17122d0..90e8ff6 100644 --- a/src/views/admin/index.php +++ b/src/views/admin/index.php @@ -1,6 +1,8 @@ model("Role"); $this->title = Yii::t('user', 'Users'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Administración'), 'url' => ['/faro/admin']]; $this->params['breadcrumbs'][] = $this->title; + +$this->params["navbar_menu_selected"] = "administracion"; + +if (ControlUsuarios::esAdmin()) { + AccionesLayoutWidget::agregarBoton( + \yii\bootstrap4\Html::a(" Nuevo usuario", ['create'], + ["class" => "dropdown-item"]) + ); +} ?> -
- = Html::a(Yii::t('user', 'Create {modelClass}', [ - 'modelClass' => 'User', - ]), ['create'], ['class' => 'btn btn-success']) ?> -
Para eliminar este usuario ingresá desde acá. Si creés que en un futuro puede volver a ser + necesario te sugerimos que lo desactives.
+ + = Alert::widget([ + "body" => " Esta acción no puede deshacerse", + "closeButton" => false, + "options" => ["class" => "alert-danger"] + ]) ?> + + = + Html::a("Eliminar usuario", ['delete', 'id' => $user->id], [ + 'class' => 'btn btn-danger btn-block shadow-sm d-sm-inline-block', + 'data' => [ + 'confirm' => Yii::t('app', 'Esta seguro que desea eliminar este usuario?'), + 'method' => 'post', + ], + ]) + ?> + +- = Html::a(Yii::t('user', 'Update'), ['update', 'id' => $user->id], ['class' => 'btn btn-primary']) ?> - = Html::a(Yii::t('user', 'Delete'), ['delete', 'id' => $user->id], [ - 'class' => 'btn btn-danger', - 'data' => [ - 'confirm' => Yii::t('user', 'Are you sure you want to delete this item?'), - 'method' => 'post', - ], - ]) ?> -
+if (ControlUsuarios::esAdmin()) { + AccionesLayoutWidget::agregarBoton( + \yii\bootstrap4\Html::a(" Editar usuario", ['update', "id" => $user->id], ["class" => "dropdown-item"]) + ); +} +?>