PublicController.class.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * 小梦科技资源nanodreamtech.com
  4. *
  5. * ==========================================================================
  6. * @link https://www.nanodreamtech.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license https://www.nanodreamtech.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Admin\Controller;
  15. class PublicController extends \Think\Controller {
  16. public function login($username = null, $password = null, $verify = null){
  17. $config = S('DB_CONFIG_DATA');
  18. if(!$config){
  19. $config = api('Config/lists');
  20. S('DB_CONFIG_DATA',$config);
  21. }
  22. C($config); //添加配置
  23. if(IS_POST){
  24. if(empty($username)){
  25. $this->error('用户名不能为空!');
  26. }elseif(empty($password)){
  27. $this->error('密码不能为空!');
  28. }
  29. $user=M('Admin')->getByAUname($username);
  30. //用户存在且可用
  31. if($user&&$user['a_status']==1){
  32. //验证密码
  33. if(think_ucenter_encrypt($password,C('PWD_KEY'))==$user['a_passwd']){
  34. $auth = array(
  35. 'uid' => $user['a_id'],
  36. 'username' => $user['a_uname'],
  37. 'is_super' => $user['a_is_super'],
  38. 'role_id' => $user['a_role_id'],
  39. 'last_login_time' => $user['a_last_login_time'],
  40. );
  41. session('user_auth', $auth);
  42. session('user_auth_sign', data_auth_sign($auth));
  43. $_SESSION[C('ADMIN_AUTH_KEY')] = false;
  44. if (C('USER_AUTH_ON')) {
  45. $_SESSION[C('USER_AUTH_KEY')] = $user['a_id'];
  46. if ($user['a_is_super']) {
  47. // 超级管理员无需认证
  48. $_SESSION[C('ADMIN_AUTH_KEY')] = true;
  49. }
  50. // 缓存访问权限
  51. \Org\Util\Rbac::saveAccessList();
  52. }
  53. $data = array();
  54. $data['a_id'] = $user['a_id'];
  55. $data['a_last_login_time'] = time();
  56. $data['a_login_count'] = array('exp','a_login_count+1');
  57. $data['a_last_login_ip'] = get_client_ip();
  58. M('Admin')->save($data);
  59. sellerLog('登录后台管理系统',1);
  60. storage_user_action($user['a_id'],$user['a_uname'],C('BACKEND_USER'),'登录了后台系统');
  61. $this->success('登录成功!', U('Index/index'));
  62. }else{
  63. $this->error('密码错误!');
  64. }
  65. }else{
  66. $this->error('用户不存在或被禁用!');
  67. }
  68. } else {
  69. $this->admin_xxximage = C('admin_xxximage');
  70. $this->admin_backimage = C('admin_backimage');
  71. $this->display();
  72. }
  73. }
  74. public function logout(){
  75. sellerLog('退出了后台管理系统',0);
  76. if (C('USER_AUTH_ON')) {
  77. unset($_SESSION[C('USER_AUTH_KEY')]);
  78. unset($_SESSION[C('ADMIN_AUTH_KEY')]);
  79. }
  80. session('[destroy]');
  81. $this->redirect('login');
  82. }
  83. public function verify(){
  84. $verify = new \Think\Verify();
  85. $verify->entry(1);
  86. }
  87. public function clear(){
  88. clear_cache();
  89. $this->success('缓存清理完毕');
  90. }
  91. }