Profile.php 2.6 KB

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