PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/upload/src/applications/profile/controller/IndexController.php

https://gitlab.com/wuhang2003/phpwind
PHP | 251 lines | 180 code | 22 blank | 49 comment | 32 complexity | 81753f7d6d02a7679146e7dbb8661283 MD5 | raw file
  1. <?php
  2. Wind::import('APPS:.profile.controller.BaseProfileController');
  3. Wind::import('SRV:user.srv.PwUserProfileService');
  4. Wind::import('SRV:user.validator.PwUserValidator');
  5. Wind::import('SRV:user.PwUserBan');
  6. Wind::import('APPS:profile.service.PwUserProfileExtends');
  7. /**
  8. * 用户资料页面
  9. *
  10. * @author xiaoxia.xu <xiaoxia.xuxx@aliyun-inc.com>
  11. * @copyright ©2003-2103 phpwind.com
  12. * @license http://www.phpwind.com
  13. * @version $Id: IndexController.php 28946 2013-05-31 04:59:50Z jieyin $
  14. * @package src.products.u.controller.profile
  15. */
  16. class IndexController extends BaseProfileController {
  17. /* (non-PHPdoc)
  18. * @see BaseProfileController::beforeAction()
  19. */
  20. public function beforeAction($handlerAdapter) {
  21. parent::beforeAction($handlerAdapter);
  22. $this->setCurrentLeft('profile');
  23. }
  24. /* (non-PHPdoc)
  25. * @see WindController::run()
  26. */
  27. public function run() {
  28. $userInfo = Wekit::load('user.PwUser')->getUserByUid($this->loginUser->uid, PwUser::FETCH_INFO);
  29. $userInfo = array_merge($this->loginUser->info, $userInfo);
  30. list($year, $month, $day) = PwUserHelper::getBirthDay();
  31. $this->setOutput($this->_buildArea($userInfo['location']), 'location');
  32. $this->setOutput($this->_buildArea($userInfo['hometown']), 'hometown');
  33. $isAllowSign = false;
  34. if ($this->loginUser->getPermission('allow_sign')) {
  35. $isAllowSign = true;
  36. $isSignBan = false;
  37. if (Pw::getstatus($this->loginUser->info['status'], PwUser::STATUS_BAN_SIGN)) {
  38. Wind::import('SRV:user.srv.PwBanBp');
  39. $banBp = new PwBanBp($this->loginUser->uid);
  40. if (false === $banBp->checkIfBanSign()) {
  41. $banBp->recoveryBanSignError();
  42. } elseif ($banBp->endDateTimeBanSign()) {
  43. $s = 1 << (PwUser::STATUS_BAN_SIGN - 1);
  44. $this->loginUser->info['status'] = $this->loginUser->info['status'] - $s;
  45. } else {
  46. $isSignBan = true;
  47. }
  48. }
  49. }
  50. $extendsSrv = new PwUserProfileExtends($this->loginUser);
  51. list($_left, $_tab) = $this->getMenuService()->getCurrentTab($this->getInput('_left'), $this->getInput('_tab'));
  52. $extendsSrv->setCurrent($_left, $_tab);
  53. $this->runHook('c_profile_foot_run', $extendsSrv);
  54. $this->setOutput($extendsSrv, 'hookSrc');
  55. $this->setOutput($isAllowSign, 'isAllowSign');
  56. $this->setOutput($isSignBan, 'isSignBan');
  57. $this->setOutput($this->loginUser->getPermission('sign_max_length'), 'signMaxLength');
  58. $this->setOutput($year, 'years');
  59. $this->setOutput($month, 'months');
  60. $this->setOutput($day, 'days');
  61. $this->setOutput($userInfo, 'userinfo');
  62. // seo设置
  63. Wind::import('SRV:seo.bo.PwSeoBo');
  64. $seoBo = PwSeoBo::getInstance();
  65. $lang = Wind::getComponent('i18n');
  66. $seoBo->setCustomSeo($lang->getMessage('SEO:profile.index.run.title'), '', '');
  67. Wekit::setV('seo', $seoBo);
  68. }
  69. /**
  70. * 编辑用户信息
  71. */
  72. public function dorunAction() {
  73. $this->getRequest()->isPost() || $this->showError('operate.fail');
  74. $userDm = new PwUserInfoDm($this->loginUser->uid);
  75. $userDm->setRealname($this->getInput('realname', 'post'));
  76. $userDm->setByear($this->getInput('byear', 'post'));
  77. $userDm->setBmonth($this->getInput('bmonth', 'post'));
  78. $userDm->setBday($this->getInput('bday', 'post'));
  79. $userDm->setGender($this->getInput('gender', 'post'));
  80. $userDm->setHomepage($this->getInput('homepage', 'post'));
  81. $userDm->setProfile($this->getInput('profile', 'post'));
  82. list($hometown, $location) = $this->getInput(array('hometown', 'location'), 'post');
  83. $srv = WindidApi::api('area');
  84. $areas = $srv->fetchAreaInfo(array($hometown, $location));
  85. $userDm->setHometown($hometown, isset($areas[$hometown]) ? $areas[$hometown] : '');
  86. $userDm->setLocation($location, isset($areas[$location]) ? $areas[$location] : '');
  87. //没有禁止签名的时候方可编辑签名
  88. if ($this->loginUser->getPermission('allow_sign')) {
  89. $bbsSign = $this->getInput('bbs_sign', 'post');
  90. if (($len = $this->loginUser->getPermission('sign_max_length')) && Pw::strlen($bbsSign) > $len) { //仅在此限制签名字数
  91. $this->showError(array('USER:user.edit.sign.length.over', array('{max}' => $len)));
  92. }
  93. Wind::import('LIB:ubb.PwUbbCode');
  94. Wind::import('LIB:ubb.config.PwUbbCodeConvertConfig');
  95. $ubb = new PwUbbCodeConvertConfig();
  96. $ubb->isConverImg = $this->loginUser->getPermission('sign_ubb_img') ? true : false;
  97. $userDm->setBbsSign($bbsSign)
  98. ->setSignUseubb($bbsSign != PwUbbCode::convert($bbsSign, $ubb) ? 1 : 0);
  99. }
  100. $result = $this->_editUser($userDm, PwUser::FETCH_MAIN + PwUser::FETCH_INFO);
  101. if ($result instanceof PwError) {
  102. $this->showError($result->getError());
  103. } else {
  104. $this->loginUser->info = array_merge($this->loginUser->info, $userDm->getData());
  105. $this->showMessage('USER:user.edit.profile.success');
  106. }
  107. }
  108. /**
  109. * 联系方式
  110. */
  111. public function contactAction() {
  112. $userInfo = Wekit::load('user.PwUser')->getUserByUid($this->loginUser->uid, PwUser::FETCH_INFO);
  113. $extendsSrv = new PwUserProfileExtends($this->loginUser);
  114. list($_left, $_tab) = $this->getMenuService()->getCurrentTab($this->getInput('_left'), $this->getInput('_tab'));
  115. $extendsSrv->setCurrent($_left, $_tab);
  116. $this->runHook('c_profile_foot_run', $extendsSrv);
  117. $this->setOutput($extendsSrv, 'hookSrc');
  118. $this->setOutput($userInfo, 'userinfo');
  119. }
  120. /**
  121. * 编辑联系方式
  122. */
  123. public function docontactAction() {
  124. $this->getRequest()->isPost() || $this->showError('operate.fail');
  125. $userDm = new PwUserInfoDm($this->loginUser->uid);
  126. $userDm->setTelphone($this->getInput('telphone', 'post'));
  127. $userDm->setAddress($this->getInput('address', 'post'));
  128. $userDm->setZipcode($this->getInput('zipcode', 'post'));
  129. $userDm->setAliww($this->getInput('aliww', 'post'));
  130. $userDm->setQq($this->getInput('qq', 'post'));
  131. $userDm->setMsn($this->getInput('msn', 'post'));
  132. list($alipay, $mobile) = $this->getInput(array('alipay', 'mobile'), 'post');
  133. if ($alipay) {
  134. $r = PwUserValidator::isAlipayValid($alipay, $this->loginUser->username);
  135. if ($r instanceof PwError) $this->showError($r->getError());
  136. }
  137. if ($mobile) {
  138. $r = PwUserValidator::isMobileValid($mobile);
  139. if ($r instanceof PwError) $this->showError($r->getError());
  140. }
  141. if ($email) {
  142. $r = PwUserValidator::isEmailValid($email, $this->loginUser->username);
  143. if ($r instanceof PwError) $this->showError($r->getError());
  144. }
  145. $userDm->setMobile($mobile);
  146. $userDm->setAlipay($alipay);
  147. $result = $this->_editUser($userDm, PwUser::FETCH_MAIN + PwUser::FETCH_INFO);
  148. if ($result instanceof PwError) {
  149. $this->showError($result->getError());
  150. } else {
  151. $this->loginUser->info = array_merge($this->loginUser->info, $userDm->getData());
  152. $this->showMessage('USER:user.edit.contact.success');
  153. }
  154. }
  155. /**
  156. * 密码验证
  157. */
  158. public function editemailAction() {
  159. $userInfo = Wekit::load('user.PwUser')->getUserByUid($this->loginUser->uid, PwUser::FETCH_MAIN);
  160. $this->setOutput($userInfo, 'userinfo');
  161. }
  162. /**
  163. * 密码验证
  164. */
  165. public function doeditemailAction() {
  166. $this->getRequest()->isPost() || $this->showError('operate.fail');
  167. list($passwd, $email) = $this->getInput(array('passwd', 'email'), 'post');
  168. if (!$passwd || !$email) $this->showError('USER:empty.error');
  169. Wind::import('SRV:user.srv.PwTryPwdBp');
  170. $tryPwdBp = new PwTryPwdBp();
  171. if (($result = $tryPwdBp->checkPassword($this->loginUser->uid, $passwd, $this->getRequest()->getClientIp())) instanceof PwError) {
  172. list($error,) = $result->getError();
  173. if ($error == 'USER:login.error.pwd') {
  174. $this->showError($result->getError());
  175. } else {
  176. Wind::import('SRC:service.user.srv.PwUserService');
  177. $srv = new PwUserService();
  178. $srv->logout();
  179. $this->forwardAction('u/login/run', array('backurl' => WindUrlHelper::createUrl('profile/index/run')));
  180. }
  181. }
  182. $userDm = new PwUserInfoDm($this->loginUser->uid);
  183. $r = PwUserValidator::isEmailValid($email, $this->loginUser->username);
  184. if ($r instanceof PwError) $this->showError($r->getError());
  185. $userDm->setEmail($email);
  186. $result = $this->_editUser($userDm, PwUser::FETCH_MAIN);
  187. if ($result instanceof PwError) {
  188. $this->showError($result->getError());
  189. } else {
  190. $this->loginUser->info = array_merge($this->loginUser->info, $userDm->getData());
  191. $this->showMessage('USER:user.edit.contact.success', 'profile/index/contact?_tab=contact');
  192. }
  193. }
  194. /* (non-PHPdoc)
  195. * @see PwBaseController::setDefaultTemplateName()
  196. */
  197. protected function setDefaultTemplateName($handlerAdapter) {
  198. $this->setTemplate('profile_' . $handlerAdapter->getAction());
  199. }
  200. /**
  201. * 编辑用户
  202. *
  203. * @param PwUserInfoDm $dm
  204. * @param int $type
  205. * @return boolean|PwError
  206. */
  207. private function _editUser($dm, $type = PwUser::FETCH_MAIN) {
  208. /* @var $userDs PwUser */
  209. $userDs = Wekit::load('user.PwUser');
  210. $result = $userDs->editUser($dm, $type);
  211. if ($result instanceof PwError) return $result;
  212. /*用户资料设置完成-基本资料-service钩子点:s_PwUserService_editUser*/
  213. PwSimpleHook::getInstance('profile_editUser')->runDo($dm);
  214. return true;
  215. }
  216. /**
  217. * 设置地区显示
  218. *
  219. * @return array
  220. */
  221. private function _buildArea($areaid) {
  222. $default = array(array('areaid' => '', 'name' => ''), array('areaid' => '', 'name' => ''), array('areaid' => '', 'name' => ''));
  223. if (!$areaid) {
  224. return $default;
  225. }
  226. $rout = WindidApi::api('area')->getAreaRout($areaid);
  227. return WindUtility::mergeArray($default, $rout);
  228. }
  229. }