LoginController.class.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace Admin\Controller;
  3. class LoginController extends \Think\Controller
  4. {
  5. public function chexiao()
  6. {
  7. $trade = M()->query('select * from tw_trade where status=0 order by id desc ;');
  8. //$trade = M('Trade')->where(array('status' =>0))->select();
  9. //var_dump($trade);exit;
  10. $rs =array();
  11. foreach ($trade as $k => $v) {
  12. $rs[] = D('Trade')->chexiao($v['id']);
  13. }
  14. if (check_arr($rs)) {
  15. echo '撤销成功!';
  16. } else {
  17. echo '撤销失败!';
  18. }
  19. }
  20. public function index($username = NULL, $password = NULL, $verify = NULL, $urlkey = NULL)
  21. {
  22. if (IS_POST) {
  23. //echo $verify;die;
  24. //if (!check_verify(strtoupper($verify),'1')) {
  25. //$this->error('验证码输入错误!');
  26. //}
  27. $admin = M('Admin')->where(array('username' => $username))->find();
  28. if ($admin['password'] != md5($password)) {
  29. $this->error('用户名或密码错误!');
  30. } else {
  31. $uids = $admin['id'];
  32. $admin_auth = M('AuthGroupAccess')->where(array('uid' => $uids))->find();
  33. if(!$admin_auth){
  34. $this->error('用户暂未分组!');
  35. }
  36. $group_id = $admin_auth['group_id'];
  37. $admin_gid = M('AuthGroup')->where(array('id' => $group_id))->find();
  38. if(!$admin_gid){
  39. $this->error('用户所在分组不存在!');
  40. }
  41. M('Admin')->where(array('username' => $username))->save(array('last_login_time' => time(), 'last_login_ip' => get_client_ip()));
  42. session('admin_id', $admin['id']);
  43. S('5df4g5dsh8shnfsf', $admin['id']);
  44. session('admin_username', $admin['username']);
  45. session('admin_password', $admin['password']);
  46. $this->success('登陆成功!', U('Index/index'));
  47. }
  48. } else {
  49. defined('ADMIN_KEY') || define('ADMIN_KEY', '');
  50. if (ADMIN_KEY && ($urlkey != ADMIN_KEY)) {
  51. $this->redirect('Home/Index/index');
  52. }
  53. if (session('admin_id')) {
  54. $this->redirect('Admin/Index/index');
  55. }
  56. $this->display();
  57. }
  58. }
  59. public function loginout()
  60. {
  61. session(null);
  62. S('5df4g5dsh8shnfsf', null);
  63. $this->redirect('Login/index');
  64. }
  65. public function lockScreen()
  66. {
  67. if (!IS_POST) {
  68. $this->display();
  69. } else {
  70. $pass = trim(I('post.pass'));
  71. if ($pass) {
  72. session('LockScreen', $pass);
  73. session('LockScreenTime', 3);
  74. $this->success('锁屏成功,正在跳转中...');
  75. } else {
  76. $this->error('请输入一个锁屏密码');
  77. }
  78. }
  79. }
  80. public function unlock()
  81. {
  82. if (!session('admin_id')) {
  83. session(null);
  84. $this->error('登录已经失效,请重新登录...', '/Admin/login');
  85. }
  86. if (session('LockScreenTime') < 0) {
  87. session(null);
  88. $this->error('密码错误过多,请重新登录...', '/Admin/login');
  89. }
  90. $pass = trim(I('post.pass'));
  91. if ($pass == session('LockScreen')) {
  92. session('LockScreen', null);
  93. $this->success('解锁成功', '/Admin/index');
  94. }
  95. $admin = M('Admin')->where(array('id' => session('admin_id')))->find();
  96. if ($admin['password'] == md5($pass)) {
  97. session('LockScreen', null);
  98. $this->success('解锁成功', '/Admin/index');
  99. }
  100. session('LockScreenTime', session('LockScreenTime') - 1);
  101. $this->error('用户名或密码错误!');
  102. }
  103. public function queue()
  104. {
  105. $file_path = DATABASE_PATH . '/check_queue.json';
  106. $time = time();
  107. $timeArr = array();
  108. if (file_exists($file_path)) {
  109. $timeArr = file_get_contents($file_path);
  110. $timeArr = json_decode($timeArr, true);
  111. }
  112. array_unshift($timeArr, $time);
  113. $timeArr = array_slice($timeArr, 0, 3);
  114. if (file_put_contents($file_path, json_encode($timeArr))) {
  115. exit('exec ok[' . $time . ']' . "\n");
  116. } else {
  117. exit('exec fail[' . $time . ']' . "\n");
  118. }
  119. }
  120. }
  121. ?>