AdminController.php 7.5 KB

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