AuthController.php 732 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace common\rest;
  3. use yii\filters\auth\HttpBearerAuth;
  4. use yii\filters\auth\QueryParamAuth;
  5. class AuthController extends JsonController {
  6. /**
  7. * @var \common\models\Usuario $usuario
  8. */
  9. public $usuario;
  10. public $permisos = [];
  11. public function behaviors() {
  12. $behavior = parent::behaviors();
  13. $behavior["authenticator"]["authMethods"] = [
  14. QueryParamAuth::className(),
  15. HttpBearerAuth::className()
  16. ];
  17. return $behavior;
  18. }
  19. public function beforeAction($action) {
  20. parent::beforeAction($action);
  21. $this->usuario = \Yii::$app->getUser()->getIdentity();
  22. if (!empty($this->permisos)) {
  23. $this->usuario->cargarPermisos($this->permisos);
  24. }
  25. return true;
  26. }
  27. }