Profile.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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('email', 'nickname', 'password', 'avatar', 'old_recharge_password', 'recharge_password'))
  47. ));
  48. unset($v);
  49. $admin = Admin::get($this->auth->id);
  50. $params["salt"] = $admin['salt'];
  51. if (isset($params['old_recharge_password'])) {
  52. if (!Validate::is($params['old_recharge_password'], "/^[\S]{6,30}$/")) {
  53. $this->error(__("Please input correct password"));
  54. }
  55. $old_recharge_password = md5(md5($params['old_recharge_password']) . $params["salt"]);
  56. if ($old_recharge_password != $admin["recharge_password"])
  57. $this->error("充值旧密码错误! 无法修改");
  58. unset($params["old_recharge_password"]);
  59. }
  60. if (isset($params['password'])) {
  61. if (!Validate::is($params['password'], "/^[\S]{6,30}$/")) {
  62. $this->error(__("Please input correct password"));
  63. }
  64. $params['salt'] = Random::alnum();
  65. $params['password'] = md5(md5($params['password']) . $params['salt']);
  66. }
  67. if (isset($params['recharge_password'])) {
  68. if (!Validate::is($params['recharge_password'], "/^[\S]{6,30}$/")) {
  69. $this->error(__("Please input correct password"));
  70. }
  71. $params['recharge_password'] = md5(md5($params['recharge_password']) . $params['salt']);
  72. }
  73. if ($params) {
  74. $admin->save($params);
  75. //因为个人资料面板读取的Session显示,修改自己资料后同时更新Session
  76. Session::set("admin", $admin->toArray());
  77. $this->success();
  78. }
  79. $this->error();
  80. }
  81. return;
  82. }
  83. }