model.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. class ssoModel extends model
  3. {
  4. /**
  5. * Check Key.
  6. *
  7. * @access public
  8. * @return bool
  9. */
  10. public function checkKey()
  11. {
  12. if(!isset($this->config->sso->turnon) or !$this->config->sso->turnon) return false;
  13. if(empty($this->config->sso->key)) return false;
  14. return $this->get->hash == $this->config->sso->key;
  15. }
  16. /**
  17. * Get bind user.
  18. *
  19. * @param string $account
  20. * @access public
  21. * @return object|false
  22. */
  23. public function getBindUser($account)
  24. {
  25. return $this->dao->select('*')->from(TABLE_USER)->where('ranzhi')->eq($account)->andWhere('deleted')->eq('0')->fetch();
  26. }
  27. /**
  28. * Get bind users with ranzhi.
  29. *
  30. * @access public
  31. * @return array
  32. */
  33. public function getBindUsers()
  34. {
  35. return $this->dao->select('account,ranzhi')->from(TABLE_USER)->where('ranzhi')->ne('')->andWhere('deleted')->eq('0')->fetchPairs('ranzhi', 'account');
  36. }
  37. /**
  38. * Bind user.
  39. *
  40. * @access public
  41. * @return object|false
  42. */
  43. public function bind()
  44. {
  45. $data = fixer::input('post')->get();
  46. if($data->bindType == 'bind') return $this->ssoTao->bindZTUser($data);
  47. if($data->bindType == 'add') return $this->ssoTao->addZTUser($data);
  48. }
  49. /**
  50. * Create a user from ranzhi.
  51. *
  52. * @param object $data
  53. * @access public
  54. * @return array
  55. */
  56. public function createUser($data)
  57. {
  58. $user = $this->dao->select('*')->from(TABLE_USER)->where('account')->eq($data->account)->fetch();
  59. if($user) return array('status' => 'fail', 'data' => $this->lang->sso->bindHasAccount);
  60. $this->dao->insert(TABLE_USER)->data($data)->autoCheck()->exec();
  61. if(dao::isError()) return array('status' => 'fail', 'data' => dao::getError());
  62. return array('status' => 'success', 'id' => $this->dao->lastInsertId());
  63. }
  64. }