login.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace WY\app\controller\derpay;
  3. use WY\app\libs\Controller;
  4. if (!defined('WY_ROOT')) {
  5. exit;
  6. }
  7. class login extends CheckAdmin
  8. {
  9. public function index()
  10. {
  11. $data = array('title' => '管理登录');
  12. $this->put('login.php', $data);
  13. }
  14. public function sigin()
  15. {
  16. $username = $this->req->post('username');
  17. $password = $this->req->post('password');
  18. $chkcode = $this->req->post('chkcode');
  19. if ($username == '' || $password == '' || $chkcode == '') {
  20. echo json_encode(array('status' => 1, 'msg' => '选项填写不完整'));
  21. exit;
  22. }
  23. if (!$this->session->get('chkcode') || $this->session->get('chkcode') != strtolower($chkcode)) {
  24. echo json_encode(array('status' => 1, 'msg' => '验证码填写错误'));
  25. exit;
  26. }
  27. if ($user = $this->model()->select()->from('admin')->where(array('fields' => 'adminname=?', 'values' => array($username)))->fetchRow()) {
  28. $ip = $this->req->server('REMOTE_ADDR');
  29. if ($user['is_limit_ip'] && strpos($user['limit_ip'], $ip) === false) {
  30. echo json_encode(array('status' => 1, 'msg' => '登录IP无效'));
  31. exit;
  32. }
  33. if ($user['adminpass'] == sha1($password)) {
  34. $this->session->set('login_adminname', $username);
  35. $data = array('adminid' => $user['id'], 'addtime' => time(), 'ip' => $ip);
  36. $this->model()->from('adminlogs')->insertData($data)->insert();
  37. echo json_encode(array('status' => 1, 'msg' => "欢迎管理员:[$username]\n您已经登录成功系统!", 'url' => $this->dir));
  38. exit;
  39. }
  40. }
  41. echo json_encode(array('status' => 1, 'msg' => '账号或密码不正确'));
  42. exit;
  43. }
  44. public function logout()
  45. {
  46. if ($this->req->session('login_adminname')) {
  47. $_SESSION['login_adminname'] = '';
  48. unset($_SESSION['login_adminname']);
  49. }
  50. $this->res->redirect($this->dir);
  51. }
  52. }