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

/src/com/jeecms/cms/action/member/MemberAct.java

https://gitlab.com/MetadataDev/mcms
Java | 258 lines | 167 code | 15 blank | 76 comment | 24 complexity | 22642a7bb8cf72c333759abab168d1d4 MD5 | raw file
  1. package com.jeecms.cms.action.member;
  2. import static com.jeecms.cms.Constants.TPLDIR_MEMBER;
  3. import java.io.IOException;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import org.slf4j.Logger;
  7. import org.slf4j.LoggerFactory;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Controller;
  10. import org.springframework.ui.ModelMap;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.RequestMethod;
  13. import com.jeecms.common.web.ResponseUtils;
  14. import com.jeecms.core.entity.CmsSite;
  15. import com.jeecms.core.entity.CmsUser;
  16. import com.jeecms.core.entity.CmsUserExt;
  17. import com.jeecms.core.entity.MemberConfig;
  18. import com.jeecms.core.manager.CmsUserExtMng;
  19. import com.jeecms.core.manager.CmsUserMng;
  20. import com.jeecms.core.web.WebErrors;
  21. import com.jeecms.core.web.util.CmsUtils;
  22. import com.jeecms.core.web.util.FrontUtils;
  23. /**
  24. * 会员中心Action
  25. */
  26. @Controller
  27. public class MemberAct {
  28. private static final Logger log = LoggerFactory.getLogger(MemberAct.class);
  29. public static final String MEMBER_CENTER = "tpl.memberCenter";
  30. public static final String MEMBER_PROFILE = "tpl.memberProfile";
  31. public static final String MEMBER_PORTRAIT = "tpl.memberPortrait";
  32. public static final String MEMBER_PASSWORD = "tpl.memberPassword";
  33. /**
  34. * 会员中心页
  35. *
  36. * 如果没有登录则跳转到登陆页
  37. *
  38. * @param request
  39. * @param response
  40. * @param model
  41. * @return
  42. */
  43. @RequestMapping(value = "/member/index.jspx", method = RequestMethod.GET)
  44. public String index(HttpServletRequest request,
  45. HttpServletResponse response, ModelMap model) {
  46. CmsSite site = CmsUtils.getSite(request);
  47. CmsUser user = CmsUtils.getUser(request);
  48. FrontUtils.frontData(request, model, site);
  49. MemberConfig mcfg = site.getConfig().getMemberConfig();
  50. // 没有开启会员功能
  51. if (!mcfg.isMemberOn()) {
  52. return FrontUtils.showMessage(request, model, "member.memberClose");
  53. }
  54. if (user == null) {
  55. return FrontUtils.showLogin(request, model, site);
  56. }
  57. return FrontUtils.getTplPath(request, site.getSolutionPath(),
  58. TPLDIR_MEMBER, MEMBER_CENTER);
  59. }
  60. /**
  61. * 个人资料输入页
  62. *
  63. * @param request
  64. * @param response
  65. * @param model
  66. * @return
  67. */
  68. @RequestMapping(value = "/member/profile.jspx", method = RequestMethod.GET)
  69. public String profileInput(HttpServletRequest request,
  70. HttpServletResponse response, ModelMap model) {
  71. CmsSite site = CmsUtils.getSite(request);
  72. CmsUser user = CmsUtils.getUser(request);
  73. FrontUtils.frontData(request, model, site);
  74. MemberConfig mcfg = site.getConfig().getMemberConfig();
  75. // 没有开启会员功能
  76. if (!mcfg.isMemberOn()) {
  77. return FrontUtils.showMessage(request, model, "member.memberClose");
  78. }
  79. if (user == null) {
  80. return FrontUtils.showLogin(request, model, site);
  81. }
  82. return FrontUtils.getTplPath(request, site.getSolutionPath(),
  83. TPLDIR_MEMBER, MEMBER_PROFILE);
  84. }
  85. /**
  86. * 更换头像
  87. * @param request
  88. * @param response
  89. * @param model
  90. * @return
  91. */
  92. @RequestMapping(value = "/member/portrait.jspx", method = RequestMethod.GET)
  93. public String portrait(HttpServletRequest request,
  94. HttpServletResponse response, ModelMap model) {
  95. CmsSite site = CmsUtils.getSite(request);
  96. CmsUser user = CmsUtils.getUser(request);
  97. FrontUtils.frontData(request, model, site);
  98. MemberConfig mcfg = site.getConfig().getMemberConfig();
  99. // 没有开启会员功能
  100. if (!mcfg.isMemberOn()) {
  101. return FrontUtils.showMessage(request, model, "member.memberClose");
  102. }
  103. if (user == null) {
  104. return FrontUtils.showLogin(request, model, site);
  105. }
  106. return FrontUtils.getTplPath(request, site.getSolutionPath(),
  107. TPLDIR_MEMBER, MEMBER_PORTRAIT);
  108. }
  109. /**
  110. * 个人资料提交页
  111. *
  112. * @param request
  113. * @param response
  114. * @param model
  115. * @return
  116. * @throws IOException
  117. */
  118. @RequestMapping(value = "/member/profile.jspx", method = RequestMethod.POST)
  119. public String profileSubmit(CmsUserExt ext, String nextUrl,
  120. HttpServletRequest request, HttpServletResponse response,
  121. ModelMap model) throws IOException {
  122. CmsSite site = CmsUtils.getSite(request);
  123. CmsUser user = CmsUtils.getUser(request);
  124. FrontUtils.frontData(request, model, site);
  125. MemberConfig mcfg = site.getConfig().getMemberConfig();
  126. // 没有开启会员功能
  127. if (!mcfg.isMemberOn()) {
  128. return FrontUtils.showMessage(request, model, "member.memberClose");
  129. }
  130. if (user == null) {
  131. return FrontUtils.showLogin(request, model, site);
  132. }
  133. ext.setId(user.getId());
  134. cmsUserExtMng.update(ext, user);
  135. log.info("update CmsUserExt success. id={}", user.getId());
  136. return FrontUtils.showSuccess(request, model, nextUrl);
  137. }
  138. /**
  139. * 密码修改输入页
  140. *
  141. * @param request
  142. * @param response
  143. * @param model
  144. * @return
  145. */
  146. @RequestMapping(value = "/member/pwd.jspx", method = RequestMethod.GET)
  147. public String passwordInput(HttpServletRequest request,
  148. HttpServletResponse response, ModelMap model) {
  149. CmsSite site = CmsUtils.getSite(request);
  150. CmsUser user = CmsUtils.getUser(request);
  151. FrontUtils.frontData(request, model, site);
  152. MemberConfig mcfg = site.getConfig().getMemberConfig();
  153. // 没有开启会员功能
  154. if (!mcfg.isMemberOn()) {
  155. return FrontUtils.showMessage(request, model, "member.memberClose");
  156. }
  157. if (user == null) {
  158. return FrontUtils.showLogin(request, model, site);
  159. }
  160. return FrontUtils.getTplPath(request, site.getSolutionPath(),
  161. TPLDIR_MEMBER, MEMBER_PASSWORD);
  162. }
  163. /**
  164. * 密码修改提交页
  165. *
  166. * @param origPwd
  167. * 原始密码
  168. * @param newPwd
  169. * 新密码
  170. * @param email
  171. * 邮箱
  172. * @param nextUrl
  173. * 下一个页面地址
  174. * @param request
  175. * @param response
  176. * @param model
  177. * @return
  178. * @throws IOException
  179. */
  180. @RequestMapping(value = "/member/pwd.jspx", method = RequestMethod.POST)
  181. public String passwordSubmit(String origPwd, String newPwd, String email,
  182. String nextUrl, HttpServletRequest request,
  183. HttpServletResponse response, ModelMap model) throws IOException {
  184. CmsSite site = CmsUtils.getSite(request);
  185. CmsUser user = CmsUtils.getUser(request);
  186. FrontUtils.frontData(request, model, site);
  187. MemberConfig mcfg = site.getConfig().getMemberConfig();
  188. // 没有开启会员功能
  189. if (!mcfg.isMemberOn()) {
  190. return FrontUtils.showMessage(request, model, "member.memberClose");
  191. }
  192. if (user == null) {
  193. return FrontUtils.showLogin(request, model, site);
  194. }
  195. WebErrors errors = validatePasswordSubmit(user.getId(), origPwd,
  196. newPwd, email, request);
  197. if(user.getId()==2){
  198. errors.addErrorString("您不能修改密码!");
  199. }
  200. if (errors.hasErrors()) {
  201. return FrontUtils.showError(request, response, model, errors);
  202. }
  203. cmsUserMng.updatePwdEmail(user.getId(), newPwd, email);
  204. return FrontUtils.showSuccess(request, model, nextUrl);
  205. }
  206. /**
  207. * 验证密码是否正确
  208. *
  209. * @param origPwd
  210. * 原密码
  211. * @param request
  212. * @param response
  213. */
  214. @RequestMapping("/member/checkPwd.jspx")
  215. public void checkPwd(String origPwd, HttpServletRequest request,
  216. HttpServletResponse response) {
  217. CmsUser user = CmsUtils.getUser(request);
  218. boolean pass = cmsUserMng.isPasswordValid(user.getId(), origPwd);
  219. ResponseUtils.renderJson(response, pass ? "true" : "false");
  220. }
  221. private WebErrors validatePasswordSubmit(Integer id, String origPwd,
  222. String newPwd, String email, HttpServletRequest request) {
  223. WebErrors errors = WebErrors.create(request);
  224. if (errors.ifBlank(origPwd, "origPwd", 100)) {
  225. return errors;
  226. }
  227. if (errors.ifMaxLength(newPwd, "newPwd", 100)) {
  228. return errors;
  229. }
  230. if (errors.ifNotEmail(email, "email", 100)) {
  231. return errors;
  232. }
  233. if (!cmsUserMng.isPasswordValid(id, origPwd)) {
  234. errors.addErrorCode("member.origPwdInvalid");
  235. return errors;
  236. }
  237. return errors;
  238. }
  239. @Autowired
  240. private CmsUserMng cmsUserMng;
  241. @Autowired
  242. private CmsUserExtMng cmsUserExtMng;
  243. }