login.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace WY\app\controller;
  3. use WY\app\libs\Controller;
  4. if (!defined('WY_ROOT')) {
  5. exit;
  6. }
  7. class login extends Controller
  8. {
  9. function __construct()
  10. {
  11. parent::__construct();
  12. }
  13. public function index()
  14. {
  15. if ($url = $this->verifyUser->verify()) {
  16. $this->res->redirect($url);
  17. }
  18. $data = array('title' => '商户登录');
  19. $this->put('login.php', $data);
  20. }
  21. public function sigin()
  22. {
  23. $username = $this->req->post('username');
  24. $password = $this->req->post('password');
  25. $chkcode = $this->req->post('chkcode');
  26. $keepLogin = $this->req->post('kl');
  27. if ($username == '' || $password == '' || $chkcode == '') {
  28. $this->put('woodyapp.php', array('msg' => '选项填写不完整'));
  29. exit;
  30. }
  31. if (strtolower($chkcode) != $this->session->get('chkcode')) {
  32. $this->put('woodyapp.php', array('msg' => '验证码错误'));
  33. exit;
  34. }
  35. if (strpos($username, '@')) {
  36. $where = array('fields' => 'email=?', 'values' => array($username));
  37. if (!($userinfo = $this->model()->select('userid')->from('userinfo')->where($where)->fetchRow())) {
  38. $this->put('woodyapp.php', array('msg' => '邮箱账号未注册'));
  39. exit;
  40. }
  41. $user = $this->model()->select()->from('users')->where(array('fields' => 'id=?', 'values' => array($userinfo['userid'])))->fetchRow();
  42. if (!$user || $user['userpass'] != sha1($password)) {
  43. $this->put('woodyapp.php', array('msg' => '邮箱账号或密码错误'));
  44. exit;
  45. }
  46. } else {
  47. $where = array('fields' => 'username=? and userpass=?', 'values' => array($username, sha1($password)));
  48. if (!($user = $this->model()->select()->from('users')->where($where)->fetchRow())) {
  49. $this->put('woodyapp.php', array('msg' => '用户名或密码错误'));
  50. exit;
  51. }
  52. }
  53. if ($user['is_state'] == '2') {
  54. $this->put('woodyapp.php', array('msg' => '账号已被停用,请联系客服。'));
  55. exit;
  56. }
  57. if ($user['is_agent']) {
  58. $this->session->set('login_agentid', $user['id']);
  59. $this->session->set('login_agentname', $user['username']);
  60. } else {
  61. $this->session->set('login_userid', $user['id']);
  62. $this->session->set('login_username', $user['username']);
  63. }
  64. if ($keepLogin == 'yes') {
  65. $this->verifyUser->setck($user['id'], $username, $user['userpass']);
  66. }
  67. $ip = $this->req->server('REMOTE_ADDR');
  68. $logData = array('userid' => $user['id'], 'addtime' => time(), 'ip' => $ip ,'address' => $this->res->getIPLoc($ip));
  69. $this->model()->from('userlogs')->insertData($logData)->insert();
  70. $url = $user['is_agent'] ? '/agent' : '/member';
  71. $this->res->redirect($url);
  72. }
  73. public function logout()
  74. {
  75. $this->session->set('login_userid', '');
  76. $this->session->set('login_username', '');
  77. $this->session->set('login_agentid', '');
  78. $this->session->set('login_agentname', '');
  79. unset($_SESSION['login_userid']);
  80. unset($_SESSION['login_username']);
  81. unset($_SESSION['login_agentid']);
  82. unset($_SESSION['login_agentname']);
  83. $this->verifyUser->unsetck();
  84. $this->res->redirect('/login');
  85. }
  86. }
  87. ?>