ServiceController.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. Doo::loadModelAt('auser', 'admin');
  3. Doo::loadModelAt('ausers', 'admin');
  4. Doo::loadModel('users');
  5. Doo::loadClass('profile');
  6. Doo::loadClass('PasswordHash');
  7. Doo::loadClass('mailer');
  8. Doo::loadClass('nusoap');
  9. /*
  10. * To change this license header, choose License Headers in Project Properties.
  11. * To change this template file, choose Tools | Templates
  12. * and open the template in the editor.
  13. */
  14. // 列表停用 编辑 重置密码
  15. // 管理员权限管理
  16. // 管理员修改密码
  17. class ServiceController extends DooController
  18. {
  19. private $data, $users, $user, $profile, $ph, $userz, $mailer;
  20. public function __construct()
  21. {
  22. $this->users = new AUsers();
  23. $this->user = new AUser();
  24. $this->userz = new Users();
  25. $this->profile = new Profile();
  26. $this->mailer = new Mailer();
  27. $this->ph = new PasswordHash(8, FALSE);
  28. $this->data['rootUrl'] = Doo::conf()->APP_URL;
  29. }
  30. public function ZGServer()
  31. {
  32. ini_set("soap.wsdl_cache_enabled", "0");
  33. $server = new SoapServer(Doo::conf()->APP_URL . 'service/getwsdl?wsdl', array('soap_version' => SOAP_1_2));
  34. $server->setClass('ServiceController');
  35. $server->addFunction('addUser');
  36. $server->addFunction(SOAP_FUNCTIONS_ALL);
  37. $server->handle();
  38. }
  39. public function getWSDL()
  40. {
  41. ini_set("soap.wsdl_cache_enabled", "0");
  42. $soap = new soap_server;
  43. $soap->configureWSDL('UserService', 'urn:UserService', Doo::conf()->APP_URL . 'service/user');
  44. $soap->soap_defencoding = 'UTF-8';
  45. $soap->register(
  46. 'addUser',
  47. array('username' => 'xsd:string', 'realname' => 'xsd:string'),
  48. array('retval' => 'xsd:boolean'),
  49. 'urn:UserService',
  50. 'urn:UserService#addUser'
  51. );
  52. // $soap->register(
  53. // 'updateUser',
  54. // array('username' => 'xsd:string')
  55. // );
  56. // $soap->service(file_get_contents("php://input"));
  57. $soap->service(isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '');
  58. }
  59. function addUser($username, $realname)
  60. {
  61. if (isset($username) && isset($realname)) {
  62. $uid = $this->users->createUser($username, $username);
  63. if ($uid) {
  64. $this->profile->ZGinsertProfile($uid, urldecode($realname));
  65. return true;
  66. } else {
  67. return false;
  68. }
  69. } else {
  70. return false;
  71. }
  72. }
  73. public function randomPassword()
  74. {
  75. $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
  76. $pass = array(); //remember to declare $pass as an array
  77. $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
  78. for ($i = 0; $i < 8; $i++) {
  79. $n = rand(0, $alphaLength);
  80. $pass[] = $alphabet[$n];
  81. }
  82. return implode($pass); //turn the array into a string
  83. }
  84. }