82 lines
2.2 KiB
PHP
82 lines
2.2 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | YwxApp [ WE CAN DO IT JUST THINK ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Author: ywxapp<admin@ywxapp.cn>
|
|
// +----------------------------------------------------------------------
|
|
declare (strict_types = 1);
|
|
|
|
namespace app\member\controller;
|
|
|
|
use think\facade\Event;
|
|
use ywxapp\controller\MemberBase;
|
|
use ywxapp\model\MemberUser as UserModel;
|
|
use app\member\validate\Settings as SettingsValidate;
|
|
|
|
/**
|
|
* 账户设置
|
|
* 解决此前「设置」菜单为死链的问题(member 应用原无 Settings 控制器)。
|
|
* 页面展示账户基础信息,并支持更新昵称 / 邮箱,更新时触发 UserSettingUpdate 事件。
|
|
*/
|
|
class Settings extends MemberBase
|
|
{
|
|
/**
|
|
* 需登录
|
|
* @var array
|
|
*/
|
|
protected $noNeedLogin = [];
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $noNeedVerify = ['*'];
|
|
|
|
|
|
protected function initialize()
|
|
{}
|
|
|
|
/**
|
|
* 设置页
|
|
*/
|
|
public function index()
|
|
{
|
|
$user = $this->user();
|
|
$this->view->assign('info', $user);
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
/**
|
|
* 保存设置
|
|
*/
|
|
public function save()
|
|
{
|
|
if (!($this->request->isAjax() && $this->request->isPost())) {
|
|
$this->result->error('访问错误');
|
|
}
|
|
$user = $this->user();
|
|
$data = $this->request->param();
|
|
$validate = new SettingsValidate();
|
|
if (! $validate->check($data)) {
|
|
$this->result->error($validate->getError());
|
|
}
|
|
$update = [];
|
|
|
|
if (isset($data['nickname']) && $data['nickname'] !== '') {
|
|
$update['nickname'] = $data['nickname'];
|
|
}
|
|
if (isset($data['email']) && $data['email'] !== '') {
|
|
$update['email'] = $data['email'];
|
|
}
|
|
|
|
if (!empty($update)) {
|
|
$user->save($update);
|
|
// 插件事件触发点:账户设置更新
|
|
Event::trigger('UserSettingUpdate', ['member' => $user, 'data' => $update]);
|
|
}
|
|
|
|
$this->result->success();
|
|
}
|
|
}
|