portal.mkgtu.ru/backend/controllers/OauthController.php

87 lines
2.0 KiB
PHP
Raw Normal View History

2024-03-28 09:51:45 +03:00
<?php
namespace backend\controllers;
use backend\models\OauthForm;
use backend\models\search\OauthSearch;
use filsh\yii2\oauth2server\models\OauthClients;
use Yii;
use yii\filters\VerbFilter;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
class OauthController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'delete' => ['post'],
],
],
];
}
public function actionIndex()
{
$searchModel = new OauthSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
public function actionCreate()
{
$model = new OauthClients();
$model->grant_types = "client_credentials authorization_code password implicit refresh_token";
if ($model->load(Yii::$app->request->post()) && $model->save(true)) {
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
public function actionUpdate($id)
{
$model = new OauthForm();
$model->setModel($this->findModel($id));
if ($model->load(Yii::$app->request->post()) && $model->save(false)) {
return $this->redirect(['index']);
}
return $this->render('update', [
'model' => $model
]);
}
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
protected function findModel($id)
{
if (($model = OauthClients::findOne(['client_id' => $id])) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}