| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace app\admin\controller\general;
- use app\admin\model\Admin;
- use app\common\controller\Backend;
- use fast\Random;
- use think\Session;
- use think\Validate;
- /**
- * 个人配置
- *
- * @icon fa fa-user
- */
- class Profile extends Backend
- {
- protected $searchFields = 'id,title';
- /**
- * 查看
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- if ($this->request->isAjax()) {
- $this->model = model('AdminLog');
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $list = $this->model
- ->where($where)
- ->where('admin_id', $this->auth->id)
- ->order($sort, $order)
- ->paginate($limit);
- $result = array("total" => $list->total(), "rows" => $list->items());
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 更新个人信息
- */
- public function update()
- {
- if ($this->request->isPost()) {
- $this->token();
- $params = $this->request->post("row/a");
- $params = array_filter(array_intersect_key(
- $params,
- array_flip(array('email', 'nickname', 'password', 'avatar', 'old_recharge_password', 'recharge_password'))
- ));
- unset($v);
- $admin = Admin::get($this->auth->id);
- $params["salt"] = $admin['salt'];
- if (isset($params['old_recharge_password'])) {
- if (!Validate::is($params['old_recharge_password'], "/^[\S]{6,30}$/")) {
- $this->error(__("Please input correct password"));
- }
- $old_recharge_password = md5(md5($params['old_recharge_password']) . $params["salt"]);
- if ($old_recharge_password != $admin["recharge_password"])
- $this->error("充值旧密码错误! 无法修改");
- unset($params["old_recharge_password"]);
- }
- if (isset($params['password'])) {
- if (!Validate::is($params['password'], "/^[\S]{6,30}$/")) {
- $this->error(__("Please input correct password"));
- }
- $params['salt'] = Random::alnum();
- $params['password'] = md5(md5($params['password']) . $params['salt']);
- }
- if (isset($params['recharge_password'])) {
- if (!Validate::is($params['recharge_password'], "/^[\S]{6,30}$/")) {
- $this->error(__("Please input correct password"));
- }
- $params['recharge_password'] = md5(md5($params['recharge_password']) . $params['salt']);
- }
- if ($params) {
- $admin->save($params);
- //因为个人资料面板读取的Session显示,修改自己资料后同时更新Session
- Session::set("admin", $admin->toArray());
- $this->success();
- }
- $this->error();
- }
- return;
- }
- }
|