AdminController.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. session_start(); // starts new or resumes existing session
  3. Doo::loadModelAt('auser', 'admin');
  4. Doo::loadModelAt('ausers', 'admin');
  5. Doo::loadModel('users');
  6. Doo::loadClass('profile');
  7. Doo::loadClass('PasswordHash');
  8. Doo::loadClass('mailer');
  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 AdminController extends DooController
  18. {
  19. private $data, $users, $user, $profile, $ph, $userz, $mailer;
  20. public function beforeRun($resource, $action)
  21. {
  22. if (!isset($_SESSION['auid'])) {
  23. return Doo::conf()->APP_URL . 'manage';
  24. }
  25. }
  26. public function __construct()
  27. {
  28. $this->users = new AUsers();
  29. $this->user = new AUser();
  30. $this->userz = new Users();
  31. $this->profile = new Profile();
  32. $this->mailer = new Mailer();
  33. $this->ph = new PasswordHash(8, FALSE);
  34. $this->data['rootUrl'] = Doo::conf()->APP_URL;
  35. }
  36. function addUser()
  37. {
  38. $params = NULL;
  39. if (isset($_POST['email'])) {
  40. if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
  41. $postArray = $_POST;
  42. $passwdStr = $this->randomPassword();
  43. $postArray['userid'] = $this->users->createUser($_POST['email'], $passwdStr);
  44. if (isset($postArray['userid'])) {
  45. $this->profile->insertProfile($postArray);
  46. $this->mailer->setEmails($_POST['email']);
  47. $this->mailer->seteTitle('新账号开通');
  48. $this->mailer->setClientName($postArray['realname']);
  49. $signupConfigStr = '<p>开通了计量支付云版的帐号:</p><p>登录帐号(邮箱):<b><a href="mailto:' . $_POST['email'] . '" target="_blank">' . $_POST['email'] . '</a></b></p><p>登录密码:<b>' . $passwdStr . '</b></p><p>请及时登录并修改您的个人信息及密码。</p>';
  50. $this->mailer->setContent($signupConfigStr);
  51. $this->mailer->send_mail();
  52. return Doo::conf()->APP_URL . 'manage/user/list';
  53. } else {
  54. return Doo::conf()->APP_URL . 'manage/user/add';
  55. }
  56. } else {
  57. return Doo::conf()->APP_URL . 'manage/user/add';
  58. }
  59. }
  60. $this->render('admin-addUser', $this->data, TRUE);
  61. }
  62. public function randomPassword()
  63. {
  64. $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
  65. $pass = array(); //remember to declare $pass as an array
  66. $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
  67. for ($i = 0; $i < 8; $i++) {
  68. $n = rand(0, $alphaLength);
  69. $pass[] = $alphabet[$n];
  70. }
  71. return implode($pass); //turn the array into a string
  72. }
  73. function editUser()
  74. {
  75. $this->data['users'] = $this->users->getOne(array('where' => 'uid = ?', 'param' => array($this->params['uid']), 'asArray' => TRUE));
  76. $this->data['profile'] = $this->profile->getProWithUid($this->params['uid']);
  77. if (isset($_POST['email']) && ($_POST['email'] != $this->data['users']['uemail']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
  78. if (!$this->userz->getOne(array('where' => 'uemail = ?', 'param' => array($_POST['email']), 'asArray' => TRUE))) {
  79. $this->userz->uemail = $_POST['email'];
  80. $this->userz->update(array('where' => 'uid = ?', 'param' => array($this->params['uid'])));
  81. }
  82. }
  83. if (isset($_POST['company']) && isset($_POST['jobs']) && isset($_POST['name']) && isset($_POST['phone'])) {
  84. $this->profile->upProfile($this->params['uid'], $_POST);
  85. return Doo::conf()->APP_URL . 'manage/user/list';
  86. }
  87. $this->render('admin-editUser', $this->data, TRUE);
  88. }
  89. function option()
  90. {
  91. $this->data['auser'] = $this->user->getOne(array('where' => 'auid = ?', 'param' => array($_SESSION['auid']), 'asArray' => TRUE));
  92. if (isset($_POST['oldpasswd']) && isset($_POST['newpasswd']) && isset($_POST['renewpasswd']) && ($_POST['newpasswd'] == $_POST['renewpasswd']) && $this->ph->CheckPassword($_POST['oldpasswd'], $this->data['auser']['aupass'])) {
  93. $this->user->upPasswWd($_SESSION['auid'], $this->ph->HashPassword($_POST['newpasswd']));
  94. return Doo::conf()->APP_URL . 'manage/user/list';
  95. }
  96. $this->render('admin-option', $this->data, TRUE);
  97. }
  98. function userSwitch()
  99. {
  100. $userzArray = $this->userz->getOne(array('where' => 'uid = ?', 'param' => array($this->params['uid']), 'asArray' => TRUE));
  101. if (isset($userzArray['uid']) && $userzArray['isstop']) {
  102. $this->userz->isstop = 0;
  103. } else {
  104. $this->userz->isstop = 1;
  105. }
  106. $this->userz->update(array('where' => 'uid = ?', 'param' => array($this->params['uid'])));
  107. return Doo::conf()->APP_URL . 'manage/user/list';
  108. }
  109. function userRepasswd()
  110. {
  111. $userzArray = $this->userz->getOne(array('where' => 'uid = ?', 'param' => array($this->params['uid']), 'asArray' => TRUE));
  112. if (isset($userzArray['uemail'])) {
  113. $passwdStr = $this->randomPassword();
  114. $this->userz->upass = $this->ph->HashPassword($passwdStr);
  115. if ($this->userz->update(array('where' => 'uid=?', 'param' => array($this->params['uid'])))) {
  116. $proArray = $this->profile->getProWithUid($this->params['uid']);
  117. $this->mailer->setEmails($userzArray['uemail']);
  118. $this->mailer->seteTitle('密码重置');
  119. $this->mailer->setClientName($proArray['name']);
  120. $signupConfigStr = '<p>重置了计量支付云版的帐号密码:</p><p>登录帐号(邮箱):<b><a href="mailto:' . $userzArray['uemail'] . '" target="_blank">' . $userzArray['uemail'] . '</a></b></p><p>登录密码:<b>' . $passwdStr . '</b></p><p>请及时登录并修改您的新密码。</p>';
  121. $this->mailer->setContent($signupConfigStr);
  122. $this->mailer->send_mail();
  123. echo $userzArray['uemail'];
  124. }
  125. }
  126. }
  127. function userList()
  128. {
  129. if (isset($_SESSION['passwd'])) {
  130. echo '添加用户的密码是:' . $_SESSION['passwd'];
  131. }
  132. $this->data['userlist'] = $this->users->getRowAll();
  133. foreach ($this->data['userlist'] as $key => $value) {
  134. $proArray = $this->profile->getProWithUid($value['uid']);
  135. if (isset($proArray)) {
  136. $this->data['userlist'][$key]['name'] = $proArray['name'];
  137. $this->data['userlist'][$key]['company'] = $proArray['company'];
  138. $this->data['userlist'][$key]['jobs'] = $proArray['jobs'];
  139. $this->data['userlist'][$key]['phone'] = $proArray['phone'];
  140. $this->data['userlist'][$key]['mobile'] = $proArray['mobile'];
  141. $this->data['userlist'][$key]['isstop'] = $value['isstop'];
  142. }
  143. unset($proArray);
  144. $this->data['userlist'][$key]['email'] = $value['uemail'];
  145. }
  146. $this->data['menu'] = 2;
  147. $this->render('admin-userlist', $this->data, TRUE);
  148. }
  149. }