站点设置后端实现
*目前还有一个关闭注册功能还没完成
This commit is contained in:
parent
901e7ae77b
commit
a7dff15406
@ -11,7 +11,6 @@ use OTPHP\TOTP;
|
||||
use Throwable;
|
||||
use Yii;
|
||||
use yii\base\Exception;
|
||||
use yii\db\StaleObjectException;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\web\Controller;
|
||||
@ -43,7 +42,7 @@ class AdminController extends Controller
|
||||
'class' => VerbFilter::class,
|
||||
'actions' => [
|
||||
'index' => ['GET'],
|
||||
'system' => ['GET'],
|
||||
'system' => ['GET','POST'],
|
||||
'user' => ['GET'],
|
||||
'user-view' => ['GET', 'POST'],
|
||||
'user-create' => ['GET', 'POST'],
|
||||
@ -73,15 +72,25 @@ class AdminController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @return string|Response
|
||||
* @throws HttpException
|
||||
*/
|
||||
public function actionSystem(): string
|
||||
public function actionSystem(): Response|string
|
||||
{
|
||||
$siteConfig = new SiteConfig();
|
||||
if (!$siteConfig->loadFromEnv()) {
|
||||
throw new HttpException(500, 'Fatal error, Unable to load site configuration from .env file.');
|
||||
}
|
||||
if (Yii::$app->request->isPost) {
|
||||
if ($siteConfig->load(Yii::$app->request->post()) && $siteConfig->validate()) {
|
||||
if ($siteConfig->saveToEnv()) {
|
||||
Yii::$app->session->setFlash('success', '保存成功');
|
||||
return $this->redirect(['system']);
|
||||
} else {
|
||||
Yii::$app->session->setFlash('error', '保存失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->render('system', [
|
||||
'siteConfig' => $siteConfig
|
||||
]);
|
||||
|
Loading…
Reference in New Issue
Block a user