IndexController.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-present http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: Powerless < wzxaini9@gmail.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\user\controller;
  12. use app\user\model\UserModel;
  13. use cmf\controller\HomeBaseController;
  14. class IndexController extends HomeBaseController
  15. {
  16. /**
  17. * 前台用户首页(公开)
  18. */
  19. public function index()
  20. {
  21. $id = $this->request->param("id", 0, "intval");
  22. $userModel = new UserModel();
  23. $user = $userModel->where('id', $id)->find();
  24. if (empty($user)) {
  25. $this->error("查无此人!");
  26. }
  27. $this->assign($user->toArray());
  28. $this->assign('user',$user);
  29. return $this->fetch(":index");
  30. }
  31. /**
  32. * 前台ajax 判断用户登录状态接口
  33. */
  34. function isLogin()
  35. {
  36. if (cmf_is_user_login()) {
  37. $this->success("用户已登录",null,['user'=>cmf_get_current_user()]);
  38. } else {
  39. $this->error("此用户未登录!");
  40. }
  41. }
  42. /**
  43. * 退出登录
  44. */
  45. public function logout()
  46. {
  47. session("user", null);//只有前台用户退出
  48. return redirect($this->request->root() . "/");
  49. }
  50. }