站点设置后端实现
*目前还有一个关闭注册功能还没完成
This commit is contained in:
parent
901e7ae77b
commit
a7dff15406
@ -11,7 +11,6 @@ use OTPHP\TOTP;
|
|||||||
use Throwable;
|
use Throwable;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\base\Exception;
|
use yii\base\Exception;
|
||||||
use yii\db\StaleObjectException;
|
|
||||||
use yii\filters\AccessControl;
|
use yii\filters\AccessControl;
|
||||||
use yii\filters\VerbFilter;
|
use yii\filters\VerbFilter;
|
||||||
use yii\web\Controller;
|
use yii\web\Controller;
|
||||||
@ -43,13 +42,13 @@ class AdminController extends Controller
|
|||||||
'class' => VerbFilter::class,
|
'class' => VerbFilter::class,
|
||||||
'actions' => [
|
'actions' => [
|
||||||
'index' => ['GET'],
|
'index' => ['GET'],
|
||||||
'system' => ['GET'],
|
'system' => ['GET','POST'],
|
||||||
'user' => ['GET'],
|
'user' => ['GET'],
|
||||||
'user-view' => ['GET', 'POST'],
|
'user-view' => ['GET', 'POST'],
|
||||||
'user-create' => ['GET', 'POST'],
|
'user-create' => ['GET', 'POST'],
|
||||||
'user-update' => ['GET', 'POST'],
|
'user-update' => ['GET', 'POST'],
|
||||||
'user-delete' => ['POST'],
|
'user-delete' => ['POST'],
|
||||||
'info' => ['GET','POST'],
|
'info' => ['GET', 'POST'],
|
||||||
'user-totpoff' => ['POST'],
|
'user-totpoff' => ['POST'],
|
||||||
'user-pwdreset' => ['POST'],
|
'user-pwdreset' => ['POST'],
|
||||||
],
|
],
|
||||||
@ -73,16 +72,26 @@ class AdminController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string|Response
|
||||||
* @throws HttpException
|
* @throws HttpException
|
||||||
*/
|
*/
|
||||||
public function actionSystem(): string
|
public function actionSystem(): Response|string
|
||||||
{
|
{
|
||||||
$siteConfig = new SiteConfig();
|
$siteConfig = new SiteConfig();
|
||||||
if(!$siteConfig->loadFromEnv()){
|
if (!$siteConfig->loadFromEnv()) {
|
||||||
throw new HttpException(500, 'Fatal error, Unable to load site configuration from .env file.');
|
throw new HttpException(500, 'Fatal error, Unable to load site configuration from .env file.');
|
||||||
}
|
}
|
||||||
return $this->render('system',[
|
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
|
'siteConfig' => $siteConfig
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -350,7 +359,7 @@ class AdminController extends Controller
|
|||||||
$totp_url = $totp->getProvisioningUri();
|
$totp_url = $totp->getProvisioningUri();
|
||||||
}
|
}
|
||||||
if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post())) {
|
if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post())) {
|
||||||
if ($model->save(true,['bio'])) {
|
if ($model->save(true, ['bio'])) {
|
||||||
Yii::$app->session->setFlash('success', '个人简介已更新');
|
Yii::$app->session->setFlash('success', '个人简介已更新');
|
||||||
return $this->render('info', [
|
return $this->render('info', [
|
||||||
'model' => $model,
|
'model' => $model,
|
||||||
|
Loading…
Reference in New Issue
Block a user