Profile.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. /**
  16. * 查看
  17. */
  18. public function index()
  19. {
  20. //设置过滤方法
  21. $this->request->filter(['strip_tags']);
  22. if ($this->request->isAjax()) {
  23. $model = model('AdminLog');
  24. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  25. $login_url = '/admin/index/login';
  26. $total = $model
  27. ->where($where)
  28. ->where('admin_id', $this->auth->id)
  29. ->where('url',$login_url)
  30. ->order($sort, $order)
  31. ->count();
  32. $list = $model
  33. ->where($where)
  34. ->where('admin_id', $this->auth->id)
  35. ->where('url',$login_url)
  36. ->order($sort, $order)
  37. ->limit($offset, $limit)
  38. ->select();
  39. $result = array("total" => $total, "rows" => $list);
  40. return json($result);
  41. }
  42. return $this->view->fetch();
  43. }
  44. /**
  45. * 更新个人信息
  46. */
  47. public function update()
  48. {
  49. if ($this->request->isPost()) {
  50. $this->token();
  51. $params = $this->request->post("row/a");
  52. $params = array_filter(array_intersect_key(
  53. $params,
  54. array_flip(array('email', 'nickname', 'password', 'avatar'))
  55. ));
  56. unset($v);
  57. if (!Validate::is($params['email'], "email")) {
  58. $this->error(__("Please input correct email"));
  59. }
  60. if (isset($params['password'])) {
  61. if(!preg_match("/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[\s\S]{8,16}$/",$params['password']))
  62. {
  63. $this->error("至少8-16个字符,至少1个大写字母,1个小写字母和1个数字,其他可以是任意字符");
  64. }
  65. $params['salt'] = Random::alnum();
  66. $params['password'] = md5(md5($params['password']) . $params['salt']);
  67. }
  68. $exist = Admin::where('email', $params['email'])->where('id', '<>', $this->auth->id)->find();
  69. if ($exist) {
  70. $this->error(__("Email already exists"));
  71. }
  72. if ($params) {
  73. $admin = Admin::get($this->auth->id);
  74. Admin::where('id',$this->auth->id)->update($params);
  75. //因为个人资料面板读取的Session显示,修改自己资料后同时更新Session
  76. Session::set("admin", $admin);
  77. $this->success();
  78. }
  79. $this->error();
  80. }
  81. return;
  82. }
  83. }