Profile.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace app\admin\controller\general;
  3. use app\admin\model\Admin;
  4. use app\common\controller\Backend;
  5. use fast\Random;
  6. use think\Session;
  7. use think\Validate;
  8. /**
  9. * 个人配置
  10. *
  11. * @icon fa fa-user
  12. */
  13. class Profile extends Backend
  14. {
  15. protected $searchFields = 'id,title';
  16. /**
  17. * 查看
  18. */
  19. public function index()
  20. {
  21. //设置过滤方法
  22. $this->request->filter(['strip_tags', 'trim']);
  23. if ($this->request->isAjax()) {
  24. $this->model = model('AdminLog');
  25. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  26. $list = $this->model
  27. ->where($where)
  28. ->where('admin_id', $this->auth->id)
  29. ->order($sort, $order)
  30. ->paginate($limit);
  31. $result = array("total" => $list->total(), "rows" => $list->items());
  32. return json($result);
  33. }
  34. return $this->view->fetch();
  35. }
  36. /**
  37. * 更新个人信息
  38. */
  39. public function update()
  40. {
  41. if ($this->request->isPost()) {
  42. $this->token();
  43. $params = $this->request->post("row/a");
  44. $params = array_filter(array_intersect_key(
  45. $params,
  46. array_flip(array('nickname', 'password', 'avatar'))
  47. ));
  48. unset($v);
  49. if (isset($params['password'])) {
  50. if (!Validate::is($params['password'], "/^[\S]{6,30}$/")) {
  51. $this->error(__("Please input correct password"));
  52. }
  53. $params['salt'] = Random::alnum();
  54. $params['password'] = md5(md5($params['password']) . $params['salt']);
  55. }
  56. if ($params) {
  57. $admin = Admin::get($this->auth->id);
  58. $admin->save($params);
  59. //因为个人资料面板读取的Session显示,修改自己资料后同时更新Session
  60. Session::set("admin", $admin->toArray());
  61. Session::set("admin.safecode", $this->auth->getEncryptSafecode($admin));
  62. $this->success();
  63. }
  64. $this->error();
  65. }
  66. return;
  67. }
  68. }