tokens.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * The tokens entry point of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
  6. * @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Chunsheng Wang <chunsheng@cnezsoft.com>
  8. * @package entries
  9. * @version 1
  10. * @link https://www.zentao.net
  11. */
  12. class tokensEntry extends baseEntry
  13. {
  14. /**
  15. * POST method.
  16. *
  17. * @access public
  18. * @return string
  19. */
  20. public function post()
  21. {
  22. $account = $this->request('account');
  23. $password = $this->request('password', '');
  24. $authKey = $this->request('authKey', '');
  25. $addAction = $this->request('addAction', false);
  26. $this->loadModel('user');
  27. if($password)
  28. {
  29. if($this->user->checkLocked($account)) return $this->sendError(400, sprintf($this->lang->user->loginLocked, $this->config->user->lockMinutes));
  30. $user = $this->user->identify($account, $password);
  31. }
  32. else
  33. {
  34. $user = $this->loadModel('im')->userIdentifyWithToken($account, $authKey);
  35. if(is_object($user))
  36. {
  37. $user->admin = strpos($this->app->company->admins, ",{$user->account},") !== false;
  38. }
  39. else
  40. {
  41. $user = null;
  42. }
  43. }
  44. if($user)
  45. {
  46. $this->user->login($user, $addAction);
  47. return $this->send(201, array('token' => session_id()));
  48. }
  49. $fails = $this->user->failPlus($account);
  50. $remainTimes = $this->config->user->failTimes - $fails;
  51. if($remainTimes <= 0)
  52. {
  53. return $this->sendError(400, sprintf($this->lang->user->loginLocked, $this->config->user->lockMinutes));
  54. }
  55. if($remainTimes <= 3)
  56. {
  57. return $this->sendError(400, sprintf($this->lang->user->lockWarning, $remainTimes));
  58. }
  59. return $this->sendError(400, $this->lang->user->loginFailed);
  60. }
  61. }