Java tutorial
/* * Project: greenline-pecker-home * * File Created at 2012-3-26 * * Copyright 2012 Greenline.com Corporation Limited. * All rights reserved. * * This software is the confidential and proprietary information of * Greenline Company. ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Greenline.com. */ package com.greenline.guahao.web.module.home.controllers.my.profile; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.greenline.common.util.DESUtil; import com.greenline.common.util.RegexUtil; import com.greenline.guahao.biz.enums.LoginIdTypeEnum; import com.greenline.guahao.biz.enums.VCodeCachePrefixEnum; import com.greenline.guahao.biz.enums.VerifyTypeEnum; import com.greenline.guahao.biz.manager.cache.CommonCacheManager; import com.greenline.guahao.biz.manager.cache.valid.CodeCacheManager; import com.greenline.guahao.biz.manager.hrs.ExpertManager; import com.greenline.guahao.biz.manager.user.UserManager; import com.greenline.guahao.biz.manager.user.UserVerifyManager; import com.greenline.guahao.biz.manager.user.dataobject.UserDO; import com.greenline.guahao.biz.manager.user.result.CheckResult; import com.greenline.guahao.biz.manager.user.result.UserResult; import com.greenline.guahao.biz.util.BizCommonUtils; import com.greenline.guahao.biz.util.DateUtils; import com.greenline.guahao.web.module.common.annotation.MethodRemark; import com.greenline.guahao.web.module.common.constants.EncodeKeyConstants; import com.greenline.guahao.web.module.common.constants.UserProfileConstants; import com.greenline.guahao.web.module.common.cookie.CookieUser; import com.greenline.guahao.web.module.common.cookie.UserCookieUtil; import com.greenline.guahao.web.module.common.json.OperationJsonObject; import com.greenline.guahao.web.module.common.utils.UserUtil; import com.greenline.guahao.web.module.home.controllers.user.UserLoginPO; import com.greenline.guahao.web.module.home.validator.user.ModifyPwValidator; import com.greenline.guahao.web.module.home.vo.user.ModifyPasswordVO; /** * @Type ProfileInfoController * @Desc ?? * @author jianyun.zheng * @date 2012-3-26 * @Version V1.0 */ @Controller @RequestMapping("/my") public class ProfileController { private final static Log logger = LogFactory.getLog(ProfileController.class); @Resource private UserManager userManager; @Resource private HttpServletRequest request; @Resource private CodeCacheManager codeCacheManager; @Resource private UserVerifyManager userVerifyManager; @Resource private ProfileProcess profileProcess; @Resource private ExpertManager expertManager; @Resource private CommonCacheManager commonCacheManager; private final static String FORWARD_MODPSW_SUCCESS = "forward:tomod"; private final static String MY_PROFILE = "my/profile/profile"; private final static String VIEW_MODIPWD = "my/password/modifypassword"; private final static String BIND_USER = "my/profile/bind_user"; private final static String VIEW_BIND_SUCC = "/bind_email_succ"; private final static String VIEW_BIND_FAIL = "/bind_email_fail"; private final static String SEND_EMAIL_SUCC = "my/profile/send_email_succ"; private final static String MY_ERROR = "/notfound"; /** * ?? */ private final static int MODIFY_PSWD_ERROR_NUM_TOP_LIMIT = 6; // ?? /** * ??24? 24 * 60 * 60 * 1000 = 86400000(??) */ private final static int MODIFY_PSWD_ERROR_NUM_TIMEOUT = 24 * 60 * 60 * 1000; /** * ?? */ private final static String MODIFY_PSWD_ERROR_NUM_CACHE_KEY_PRE = "error_num_of_modify_login_password:"; /** * ??-??;???? * * @param model * @return String */ @MethodRemark(value = "remark=?,method=GET") @RequestMapping(value = "/index", method = RequestMethod.GET) public String index(ModelMap model) { boolean isLogin = false; Long cuserId = UserCookieUtil.getUserId(request); UserDO user = null; if (cuserId != null) { user = userManager.findUserByUserId(cuserId); if (null != user && user.getStatus() != null && user.getStatus().intValue() == 1) { isLogin = true; } } if (isLogin) { // ??-??;???? boolean flag = UserUtil.isUserProfileImperfection(user); if (flag) { // ?? return "redirect:/my/profile/0"; } else { return "redirect:/my/orderlist"; } } else { UserLoginPO vo = new UserLoginPO(); model.put("hideFlag", true); model.put("user", vo); return "user/login"; } } /** * ? * * @param model * @param userId * @param type 0?123 * @return String * @throws CommonException */ @MethodRemark(value = "remark=?,userId=id,type=0?123") @RequestMapping(value = "/profile/{type}") public String getProfileInfo(ModelMap model, @PathVariable String type) { // ?cookieuserId Long cuserId = UserCookieUtil.getUserId(request); // ? if (null == cuserId) { return MY_ERROR; } UserDO userDO = userManager.findUserByUserId(cuserId); if (null == userDO) { return MY_ERROR; } // ??alipay_2088702696307613html5??? if (userDO.getReg_type() == 3 && userDO.getLoginId().startsWith("alipay_") && userDO.getLoginId().substring(7, userDO.getLoginId().length()).length() == 16) { model.put("html5alipay", true); } // ?? if (UserUtil.isUserProfileImperfection(userDO)) { model.put("updateProfile", true); } if (StringUtils.isNotBlank(userDO.getCertNo()) && "15".equals(String.valueOf(userDO.getCertNo().length()))) { model.put("firstGenerationCert", true); } if ("4".equals(type)) { CheckResult cr = userManager.checkKeywordLimit(Long.valueOf(cuserId), "userName"); if (!cr.isModify()) { model.put("isModified", true); } } if ("5".equals(type)) { CheckResult cr = userManager.checkKeywordLimit(Long.valueOf(cuserId), "mobile"); if (!cr.isModify()) { model.put("isModified", true); } } if ("6".equals(type)) { CheckResult cr = userManager.checkKeywordLimit(Long.valueOf(cuserId), "email"); if (!cr.isModify()) { model.put("isModified", true); } } // id userDO.setEncodeUserId( DESUtil.DESEncode(userDO.getUserId().toString(), EncodeKeyConstants.USER_ENCODE_KEY)); model.put("userInfo", userDO); model.put("mobile", LoginIdTypeEnum.MOBILE.getValue()); model.put("email", LoginIdTypeEnum.EMAIL.getValue()); model.put("type", type); model.put("gmtCreated", DateUtils.getYmdhmssDateString(userDO.getGmtCreated())); return MY_PROFILE; } /** * ?? * * @param userDO * @param code * @param result * @return OperationJsonObject */ @MethodRemark(value = "remark=??,method=ajax,code=??") @RequestMapping(value = "/updateprofile", method = RequestMethod.POST) public @ResponseBody OperationJsonObject doProfileUpdate(@ModelAttribute("userInfo") UserDO userInfo, @RequestParam(value = "code", required = true) String code, BindingResult result) { OperationJsonObject json = new OperationJsonObject(); String msg = StringUtils.EMPTY; try { if (!this.isUserIdValid(userInfo)) { // id? json.setHasError(true); json.setMessage("??"); return json; } Long cuserId = UserCookieUtil.getUserId(request); if (!userInfo.getUserId().equals(cuserId)) { json.setHasError(true); json.setMessage(UserProfileConstants.ERR_MSG_LOGIN_USER_ID_ERROR); return json; } if (!BizCommonUtils.isAllChinese(userInfo.getUserName())) { json.setHasError(true); json.setMessage("??"); return json; } UserDO userDO = userManager.findUserByUserId(cuserId); // msg = profileProcess.validate(userInfo, result, json); if (!json.getHasError()) { // ?,??? UserDO user = new UserDO(); user.setUserId(cuserId); user.setCertNo(userInfo.getCertNo()); user.setUserName(userInfo.getUserName()); user.setAddress(userInfo.getAddress()); // ?? user.setPatient_med_type("1"); user.setPatient_med_no(userInfo.getPatient_med_no()); // ????1?? user.setCertType("1"); if (userDO.getReg_type() == 1) { user.setEmail(userInfo.getEmail()); user.setReg_type(1); msg = profileProcess.updateUser(user, json); } else { if (codeCacheManager.verifyMobileCode(VerifyTypeEnum.UPDATE_PROFILE, userInfo.getMobile(), code)) { if (userDO.getReg_type() == 2) { user.setMobile(userInfo.getMobile()); user.setBindMobile(1); user.setReg_type(2); } else { user.setMobile(userInfo.getMobile()); user.setBindMobile(1); user.setEmail(userInfo.getEmail()); user.setReg_type(userDO.getReg_type()); if (userDO.getReg_type() == 4) { user.setNickName(userDO.getNickName()); } } msg = profileProcess.updateUser(user, json); codeCacheManager.delCode(VerifyTypeEnum.UPDATE_PROFILE, VCodeCachePrefixEnum.CODE_PRE.getValue() + userInfo.getMobile()); } else { json.setHasError(Boolean.TRUE); msg = UserProfileConstants.ERR_MSG_MOBILE_CODE; } } } } catch (Exception e) { logger.error(e); json.setHasError(Boolean.TRUE); msg = UserProfileConstants.ERR_MSG_SYSTEM_ERROR; } // ? json.setMessage(msg); return json; } /** * ?id? * * @param userInfo * @return true?false? */ private boolean isUserIdValid(UserDO userInfo) { // ??id String decodeUserId = DESUtil.DESDecode(userInfo.getEncodeUserId(), EncodeKeyConstants.USER_ENCODE_KEY); if (!StringUtils.isNumeric(decodeUserId)) { // id? return false; } userInfo.setUserId(Long.parseLong(decodeUserId)); return true; } /** * * * @param userDO * @param mobile * @param code * @return String */ @MethodRemark(value = "remark=,mobile=?,code=??") @RequestMapping(value = "/bindmobile", method = RequestMethod.POST) public String doBindMobile(ModelMap model, @ModelAttribute("userInfo") UserDO userDO, @RequestParam(value = "mobile", required = true) String mobile, @RequestParam(value = "code", required = true) String code) { if (!this.isUserIdValid(userDO)) { // id? model.put("errorMessage", UserProfileConstants.ERR_MSG_LOGIN_USER_ID_ERROR); return MY_PROFILE; } Long cuserId = UserCookieUtil.getUserId(request); if (!userDO.getUserId().equals(cuserId)) { model.put("errorMessage", UserProfileConstants.ERR_MSG_LOGIN_USER_ID_ERROR); return MY_PROFILE; } UserDO userinfo = userManager.findUserByUserId(cuserId); if (null == userinfo) { return MY_ERROR; } // ? if (!RegexUtil.isMobile(StringUtils.trim(mobile))) { profileProcess.setBindModel(userinfo, model); model.put("type", 1); return MY_PROFILE; } UserResult urr = userManager.valiMobileNo(cuserId, mobile, userinfo.getReg_type()); if (urr != null && urr.getUserDO() != null) { // ?? UserDO userdo = urr.getUserDO(); model.put("errorMessage", UserProfileConstants.ERR_MSG_MOBILE_NO_HAS_BEEN_USED_BY_OTHER_PREFIX + profileProcess.loginIdHiden(userdo.getLoginId(), userdo.getReg_type()) + UserProfileConstants.ERR_MSG_MOBILE_NO_HAS_BEEN_USED_BY_OTHER_POSTFIX); profileProcess.setBindModel(userinfo, model); model.put("type", 1); return MY_PROFILE; } UserDO userCheck = userManager.findUserByUserId(cuserId); if (null == userCheck) { return MY_ERROR; } if (!UserUtil.isBindMobile(userCheck)) { profileProcess.setBindModel(userCheck, model); return MY_PROFILE; } if (codeCacheManager.verifyMobileCode(VerifyTypeEnum.UPDATE_PROFILE, mobile, code)) { UserDO user = new UserDO(); user.setUserId(cuserId); user.setMobile(mobile); user.setBindMobile(1); UserResult r = userManager.bindUserMobile(user); codeCacheManager.delCode(VerifyTypeEnum.UPDATE_PROFILE, VCodeCachePrefixEnum.CODE_PRE.getValue() + mobile); if (r.isSystemError()) { profileProcess.setBindModel(userinfo, model); model.put("type", 1); model.put("code", code); return MY_PROFILE; } else { model.put("successMessage", UserProfileConstants.MSG_UPDATE_PROFILE_SUCCESS); UserDO users = userManager.findUserByUserId(cuserId); if (null == users) { return MY_ERROR; } profileProcess.setBindModel(users, model); return MY_PROFILE; } } else { profileProcess.setBindModel(userinfo, model); model.put("type", 1); model.put("code", code); model.put("errorMessage", UserProfileConstants.ERR_MSG_MOBILE_CODE); return MY_PROFILE; } } /** * * * @param userDO * @return String */ @MethodRemark(value = "remark=") @RequestMapping(value = "/writeNickName", method = RequestMethod.POST) public String writeNickName(ModelMap model, @ModelAttribute("userInfo") UserDO userDO) { if (!this.isUserIdValid(userDO)) { // id? return MY_ERROR; } CookieUser cuser = UserCookieUtil.getUserCookie(request); if (cuser == null || cuser.getUserId() == null) { return MY_ERROR; } UserDO userCheck = userManager.findUserByUserId(cuser.getUserId()); if (null == userCheck) { return MY_ERROR; } if (!userDO.getUserId().equals(cuser.getUserId())) { model.put("errorMessage", UserProfileConstants.ERR_MSG_LOGIN_USER_ID_ERROR); userCheck.setEncodeUserId( DESUtil.DESEncode(userCheck.getUserId().toString(), EncodeKeyConstants.USER_ENCODE_KEY)); model.put("userInfo", userCheck); model.put("gmtCreated", DateUtils.getYmdhmssDateString(userCheck.getGmtCreated())); return MY_PROFILE; } // ?? if (StringUtils.isNotBlank(userCheck.getNickName())) { model.put("errorMessage", UserProfileConstants.ERR_MSG_USER_ISSET_NICKNAME); userCheck.setEncodeUserId( DESUtil.DESEncode(userCheck.getUserId().toString(), EncodeKeyConstants.USER_ENCODE_KEY)); model.put("userInfo", userCheck); model.put("gmtCreated", DateUtils.getYmdhmssDateString(userCheck.getGmtCreated())); return MY_PROFILE; } UserDO user = new UserDO(); user.setUserId(userDO.getUserId()); // if (userManager.isExistNickName(userDO.getNickName())) { model.put("errorMessage", UserProfileConstants.ERR_MSG_NICKNAME_ERROR); profileProcess.setNickModel(userCheck, model, userDO.getNickName()); return MY_PROFILE; } user.setNickName(userDO.getNickName()); // UserResult r = userManager.writeNickName(user); if (r.isSystemError()) { model.put("errorMessage", r.getResponseDesc()); profileProcess.setNickModel(userCheck, model, userDO.getNickName()); return MY_PROFILE; } // cookie? cuser.setNickName(userDO.getNickName()); UserCookieUtil.write(request, cuser); userCheck.setNickName(userDO.getNickName()); userCheck.setEncodeUserId( DESUtil.DESEncode(userCheck.getUserId().toString(), EncodeKeyConstants.USER_ENCODE_KEY)); model.put("userInfo", userCheck); model.put("gmtCreated", DateUtils.getYmdhmssDateString(userCheck.getGmtCreated())); model.put("mobile", LoginIdTypeEnum.MOBILE.getValue()); model.put("email", LoginIdTypeEnum.EMAIL.getValue()); return MY_PROFILE; } /** * ?? * * @param userDO * @return String */ @MethodRemark(value = "remark=??") @RequestMapping(value = "/modifyUserName", method = RequestMethod.POST) public String modifyUserName(ModelMap model, @ModelAttribute("userInfo") UserDO userDO) { if (!this.isUserIdValid(userDO)) { // id? return MY_ERROR; } Long cuserId = UserCookieUtil.getUserId(request); UserDO userCheck = userManager.findUserByUserId(cuserId); if (null == userCheck) { return MY_ERROR; } if (!userDO.getUserId().equals(cuserId)) { model.put("errorMessage", UserProfileConstants.ERR_MSG_LOGIN_USER_ID_ERROR); userCheck.setEncodeUserId( DESUtil.DESEncode(userCheck.getUserId().toString(), EncodeKeyConstants.USER_ENCODE_KEY)); model.put("userInfo", userCheck); model.put("gmtCreated", DateUtils.getYmdhmssDateString(userCheck.getGmtCreated())); return MY_PROFILE; } if (!BizCommonUtils.isAllChinese(userDO.getUserName())) { model.put("errorMessage", "??"); userCheck.setEncodeUserId( DESUtil.DESEncode(userCheck.getUserId().toString(), EncodeKeyConstants.USER_ENCODE_KEY)); model.put("userInfo", userCheck); model.put("gmtCreated", DateUtils.getYmdhmssDateString(userCheck.getGmtCreated())); return MY_PROFILE; } UserDO user = new UserDO(); user.setUserId(userDO.getUserId()); user.setUserName(userDO.getUserName()); // ?? UserResult r = userManager.modifyUserName(user); if (r.isSystemError()) { model.put("errorMessage", r.getResponseDesc()); userCheck.setEncodeUserId( DESUtil.DESEncode(userCheck.getUserId().toString(), EncodeKeyConstants.USER_ENCODE_KEY)); model.put("userInfo", userCheck); model.put("gmtCreated", DateUtils.getYmdhmssDateString(userCheck.getGmtCreated())); model.put("isUpdateUser", false); model.put("mobile", LoginIdTypeEnum.MOBILE.getValue()); model.put("email", LoginIdTypeEnum.EMAIL.getValue()); return MY_PROFILE; } // ?cookie CookieUser cuser = UserCookieUtil.getUserCookie(request); cuser.setUserName(userDO.getUserName()); UserCookieUtil.write(request, cuser, Integer.parseInt(StringUtils.isBlank(cuser.getExpiry()) ? "-1" : cuser.getExpiry())); UserDO afterSetInfo = userManager.findUserByUserId(userDO.getUserId()); if (null == afterSetInfo) { return MY_ERROR; } afterSetInfo.setEncodeUserId( DESUtil.DESEncode(afterSetInfo.getUserId().toString(), EncodeKeyConstants.USER_ENCODE_KEY)); model.put("userInfo", afterSetInfo); model.put("gmtCreated", DateUtils.getYmdhmssDateString(afterSetInfo.getGmtCreated())); model.put("mobile", LoginIdTypeEnum.MOBILE.getValue()); model.put("email", LoginIdTypeEnum.EMAIL.getValue()); return MY_PROFILE; } /** * * * @param userDO * @return String */ @MethodRemark(value = "remark=") @RequestMapping(value = "/modifyUserMobile", method = RequestMethod.POST) public String modifyUserMobile(ModelMap model, @ModelAttribute("userInfo") UserDO userDO, @RequestParam(value = "code", required = true) String code) { if (!this.isUserIdValid(userDO)) { // id? return MY_ERROR; } Long cuserId = UserCookieUtil.getUserId(request); UserDO userCheck = userManager.findUserByUserId(cuserId); if (null == userCheck) { return MY_ERROR; } if (!userDO.getUserId().equals(cuserId)) { model.put("errorMessage", UserProfileConstants.ERR_MSG_LOGIN_USER_ID_ERROR); userCheck.setEncodeUserId( DESUtil.DESEncode(userCheck.getUserId().toString(), EncodeKeyConstants.USER_ENCODE_KEY)); model.put("userInfo", userCheck); model.put("gmtCreated", DateUtils.getYmdhmssDateString(userCheck.getGmtCreated())); return MY_PROFILE; } if (codeCacheManager.verifyMobileCode(VerifyTypeEnum.UPDATE_PROFILE, userDO.getNewMobile(), code)) { UserResult urr = userManager.valiMobileNo(cuserId, userDO.getNewMobile(), userCheck.getReg_type()); if (urr != null && urr.getUserDO() != null) { // ?? UserDO userdo = urr.getUserDO(); model.put("errorMessage", UserProfileConstants.ERR_MSG_MOBILE_NO_HAS_BEEN_USED_BY_OTHER_PREFIX + profileProcess.loginIdHiden(userdo.getLoginId(), userdo.getReg_type()) + UserProfileConstants.ERR_MSG_MOBILE_NO_HAS_BEEN_USED_BY_OTHER_POSTFIX); userCheck .setEncodeUserId(DESUtil.DESEncode(cuserId.toString(), EncodeKeyConstants.USER_ENCODE_KEY)); model.put("userInfo", userCheck); model.put("gmtCreated", DateUtils.getYmdhmssDateString(userCheck.getGmtCreated())); return MY_PROFILE; } UserDO user = new UserDO(); user.setUserId(userDO.getUserId()); user.setMobile(userDO.getNewMobile()); user.setReg_type(userDO.getReg_type()); if (userDO.getReg_type() == 1) { user.setLoginId(userDO.getNewMobile()); } // UserResult r = userManager.modifyUserMobile(user); if (r.isSystemError()) { model.put("errorMessage", r.getResponseDesc()); profileProcess.setBindModel(userCheck, model); return MY_PROFILE; } // ?cookie CookieUser cuser = UserCookieUtil.getUserCookie(request); if (userDO.getReg_type() == 1) { cuser.setLoginId(userDO.getNewMobile()); } UserCookieUtil.write(request, cuser, Integer.parseInt(StringUtils.isBlank(cuser.getExpiry()) ? "-1" : cuser.getExpiry())); UserDO afterSetInfo = userManager.findUserByUserId(userDO.getUserId()); if (null == afterSetInfo) { return MY_ERROR; } afterSetInfo.setEncodeUserId( DESUtil.DESEncode(afterSetInfo.getUserId().toString(), EncodeKeyConstants.USER_ENCODE_KEY)); model.put("userInfo", afterSetInfo); model.put("gmtCreated", DateUtils.getYmdhmssDateString(afterSetInfo.getGmtCreated())); model.put("mobile", LoginIdTypeEnum.MOBILE.getValue()); model.put("email", LoginIdTypeEnum.EMAIL.getValue()); } else { userCheck.setEncodeUserId(DESUtil.DESEncode(cuserId.toString(), EncodeKeyConstants.USER_ENCODE_KEY)); model.put("errorMessage", UserProfileConstants.ERR_MSG_MOBILE_CODE); model.put("userInfo", userCheck); model.put("newMobile", userDO.getNewMobile()); model.put("gmtCreated", DateUtils.getYmdhmssDateString(userCheck.getGmtCreated())); model.put("type", 5); model.put("code", code); model.put("isUpdateUser", false); return MY_PROFILE; } return MY_PROFILE; } /** * ?? * * @param model * @param email * @return String */ @MethodRemark(value = "remark=??,method=POST") @RequestMapping(value = "/sendbindemail", method = RequestMethod.POST) public String sendBindEmail(ModelMap model, @ModelAttribute("userInfo") UserDO userDO, BindingResult result) { if (!this.isUserIdValid(userDO)) { // id? model.put("errorMessage", UserProfileConstants.ERR_MSG_LOGIN_USER_ID_ERROR); return MY_PROFILE; } Long cuserId = UserCookieUtil.getUserId(request); if (!userDO.getUserId().equals(cuserId)) { model.put("errorMessage", UserProfileConstants.ERR_MSG_LOGIN_USER_ID_ERROR); return MY_PROFILE; } UserDO userinfo = userManager.findUserByUserId(cuserId); if (null == userinfo) { return MY_ERROR; } // if (!RegexUtil.isEmail(userDO.getEmail())) { userinfo.setEncodeUserId( DESUtil.DESEncode(userinfo.getUserId().toString(), EncodeKeyConstants.USER_ENCODE_KEY)); model.put("userInfo", userinfo); model.put("type", 2); model.put("mobile", LoginIdTypeEnum.MOBILE.getValue()); model.put("email", LoginIdTypeEnum.EMAIL.getValue()); model.put("gmtCreated", DateUtils.getYmdhmssDateString(userinfo.getGmtCreated())); model.put("isUpdateUser", false); model.put("errorMessage", UserProfileConstants.ERR_MSG_EMAIL_FORMAT_ERROR); return MY_PROFILE; } else { userVerifyManager.sendEmailVerifyCode(userDO.getUserId(), userDO.getUserName(), userDO.getEmail(), VerifyTypeEnum.BIND_EMAIL); model.put("email", userDO.getEmail()); return SEND_EMAIL_SUCC; } } /** * ?? * * @param model * @param email * @return String */ @MethodRemark(value = "remark=??,method=POST") @RequestMapping(value = "/modifyEmail", method = RequestMethod.POST) public String modifyEmail(ModelMap model, @ModelAttribute("userInfo") UserDO userDO, BindingResult result) { if (!this.isUserIdValid(userDO)) { // id? return MY_ERROR; } Long cuserId = UserCookieUtil.getUserId(request); if (!userDO.getUserId().equals(cuserId)) { model.put("errorMessage", UserProfileConstants.ERR_MSG_LOGIN_USER_ID_ERROR); return MY_PROFILE; } UserDO userinfo = userManager.findUserByUserId(cuserId); if (null == userinfo) { return MY_ERROR; } // if (!RegexUtil.isEmail(userDO.getEmail())) { userinfo.setEncodeUserId( DESUtil.DESEncode(userinfo.getUserId().toString(), EncodeKeyConstants.USER_ENCODE_KEY)); model.put("userInfo", userinfo); model.put("type", 6); model.put("mobile", LoginIdTypeEnum.MOBILE.getValue()); model.put("email", LoginIdTypeEnum.EMAIL.getValue()); model.put("newEmail", userDO.getEmail()); model.put("gmtCreated", DateUtils.getYmdhmssDateString(userinfo.getGmtCreated())); model.put("isUpdateUser", false); model.put("errorMessage", UserProfileConstants.ERR_MSG_EMAIL_FORMAT_ERROR); return MY_PROFILE; } else { CheckResult check = userManager.isExistLoginId(userDO.getEmail()); if (check.isExist()) { userinfo.setEncodeUserId( DESUtil.DESEncode(userinfo.getUserId().toString(), EncodeKeyConstants.USER_ENCODE_KEY)); model.put("userInfo", userinfo); model.put("type", 6); model.put("mobile", LoginIdTypeEnum.MOBILE.getValue()); model.put("email", LoginIdTypeEnum.EMAIL.getValue()); model.put("newEmail", userDO.getEmail()); model.put("gmtCreated", DateUtils.getYmdhmssDateString(userinfo.getGmtCreated())); model.put("isUpdateUser", false); model.put("errorMessage", UserProfileConstants.ERR_MSG_EMAIL_MODIFIED_ERROR); return MY_PROFILE; } userVerifyManager.sendEmailVerifyCode(userDO.getUserId(), userDO.getUserName(), userDO.getEmail(), VerifyTypeEnum.UPDATE_EMAIL); model.put("email", userDO.getEmail()); return SEND_EMAIL_SUCC; } } /** * * * @param model * @param userId * @param code * @param email * @return String */ @MethodRemark(value = "remark=,method=GET,userId=id,code=??,email=?") @RequestMapping(value = "/binding/{userId}/{code}/{email:.*}", method = RequestMethod.GET) public String mailUserBind(ModelMap model, @PathVariable("userId") String userId, @PathVariable String code, @PathVariable("email") String email) { // id String decodeUserId = DESUtil.DESDecode(userId, EncodeKeyConstants.ENCODE_KEY_USER_VERIFY); if (!StringUtils.isNumeric(decodeUserId)) { return MY_ERROR; } UserDO userCheck = userManager.findUserByUserId(Long.valueOf(decodeUserId)); if (null == userCheck) { return MY_ERROR; } Boolean result = userVerifyManager.verifyEmailCode(userId, email, code, VerifyTypeEnum.BIND_EMAIL); if (result) { if (LoginIdTypeEnum.EMAIL.getValue().equals(userCheck.getReg_type())) { UserDO userDo = new UserDO(); userDo.setUserId(Long.valueOf(decodeUserId)); userDo.setLoginId(email); userDo.setReg_type(userCheck.getReg_type()); userDo.setCertNo(userCheck.getCertNo()); UserResult userRes = userManager.updateUserInfo(userDo); if (userRes.isSystemError()) { logger.error(userRes.getResponseDesc()); return VIEW_BIND_FAIL; } } if (userManager.bindUserEmail(Long.parseLong(decodeUserId), email) > 0) { // ? return VIEW_BIND_SUCC; } } else { model.put("linkError", true); return VIEW_BIND_FAIL; } return VIEW_BIND_FAIL; } /** * ? * * @param model * @return String */ @MethodRemark(value = "remark=?") @RequestMapping(value = "/tomod") public String toModPswpage(ModelMap model) { CookieUser user = UserCookieUtil.getUserCookie(request); model.put("user", user); return VIEW_MODIPWD; } /** * html5??? * * @param model * @return String */ @MethodRemark(value = "remark=?") @RequestMapping(value = "/toBindUser") public String toBindUser(ModelMap model) { CookieUser user = UserCookieUtil.getUserCookie(request); model.put("user", user); return BIND_USER; } /** * ???; ?24?624?? * * @return */ private boolean modifyLoginPswdErrorNumReachTopLimit() { boolean reach = false; String key = MODIFY_PSWD_ERROR_NUM_CACHE_KEY_PRE + UserCookieUtil.getUserId(request); String num = commonCacheManager.getString(key); // ? if (null != num && NumberUtils.isDigits(num)) { int n = Integer.valueOf(num).intValue(); if (n >= MODIFY_PSWD_ERROR_NUM_TOP_LIMIT) { reach = true; // ??? } } return reach; } /** * ?? */ private void addModifyLoginPswdErrorNum() { String key = MODIFY_PSWD_ERROR_NUM_CACHE_KEY_PRE + UserCookieUtil.getUserId(request); String num = commonCacheManager.getString(key); // ? int n = 1; if (null != num && NumberUtils.isDigits(num)) { n = Integer.valueOf(num).intValue(); if (n < MODIFY_PSWD_ERROR_NUM_TOP_LIMIT) {// ?? commonCacheManager.increment(key); } } else { commonCacheManager.setString(key, "" + n, MODIFY_PSWD_ERROR_NUM_TIMEOUT); } } /** * ?? */ private void clearModifyLoginPswdErrorNum() { String key = MODIFY_PSWD_ERROR_NUM_CACHE_KEY_PRE + UserCookieUtil.getUserId(request); commonCacheManager.delete(key); } /** * ??? * * @param model * @param modifypwd * @param result * @return String */ @MethodRemark(value = "remark=???,method=POST") @RequestMapping(value = "/modifyPassword", method = RequestMethod.POST) public String modifyPassword(ModelMap model, @ModelAttribute("modifypwd") ModifyPasswordVO modifypwd, BindingResult result) { if (StringUtils.isBlank(modifypwd.getLoginId())) { // ModifyPwValidator pwdvalid = new ModifyPwValidator(); pwdvalid.validate(modifypwd, result); if (result.hasErrors()) { return null; } if (modifyLoginPswdErrorNumReachTopLimit()) { model.put("errorMessage", "????"); logger.warn(String.format( "??%s%s???%s", UserCookieUtil.getUserId(request), MODIFY_PSWD_ERROR_NUM_TIMEOUT, MODIFY_PSWD_ERROR_NUM_TOP_LIMIT)); } else { // ? String resultMsg = userManager.modifyPassword(UserCookieUtil.getLoginId(request), modifypwd.getOldPassword(), modifypwd.getNewPassword()); if (StringUtils.isNotBlank(resultMsg)) { addModifyLoginPswdErrorNum(); // model.put("errorMessage", resultMsg); } else { clearModifyLoginPswdErrorNum(); // model.put("successMessage", UserProfileConstants.MSG_PASSWORD_UPDATE_SUCCESS); } } return FORWARD_MODPSW_SUCCESS; } else { CookieUser user = UserCookieUtil.getUserCookie(request); // ??? boolean flag = Boolean.TRUE; if (flag && StringUtils.isBlank(modifypwd.getNewPassword())) { model.put("errorMessage", "??"); flag = Boolean.FALSE; } if (flag && StringUtils.isBlank(modifypwd.getReNewPassword())) { model.put("errorMessage", "??"); flag = Boolean.FALSE; } if (flag && !modifypwd.getReNewPassword().equals(modifypwd.getNewPassword())) { model.put("errorMessage", "??"); flag = Boolean.FALSE; } if (StringUtils.isNotBlank(modifypwd.getLoginId())) { boolean isExistDoctorLogin = expertManager.isExistDoctorLogin(modifypwd.getLoginId()); if (flag && isExistDoctorLogin) { model.put("errorMessage", "??"); flag = Boolean.FALSE; } } else { model.put("errorMessage", "???"); flag = Boolean.FALSE; } if (!flag) { model.put("modifypwd", modifypwd); model.put("user", user); return BIND_USER; } UserDO userDO = new UserDO(); userDO.setUserId(user.getUserId()); userDO.setLoginId(modifypwd.getLoginId()); UserResult r = userManager.updateUser(userDO); if (r.isSystemError()) { model.put("errorMessage", r.getResponseDesc()); model.put("modifypwd", modifypwd); model.put("user", user); return BIND_USER; } else { boolean isSucess = userManager.resetPassword(modifypwd.getLoginId(), modifypwd.getNewPassword()); if (isSucess) { // ?cookie CookieUser cuser = UserCookieUtil.getUserCookie(request); cuser.setLoginId(modifypwd.getLoginId()); UserCookieUtil.write(request, cuser); return FORWARD_MODPSW_SUCCESS; } else { model.put("errorMessage", r.getResponseDesc()); model.put("modifypwd", modifypwd); model.put("user", user); return BIND_USER; } } } } /** * ?? * * @param email * @return OperationJsonObject */ @MethodRemark(value = "remark=??,method=ajax") @RequestMapping(value = "/sendemail", method = RequestMethod.GET) public @ResponseBody OperationJsonObject doSendEmail(@ModelAttribute("email") String email) { OperationJsonObject json = new OperationJsonObject(); Long userid = UserCookieUtil.getUserId(request); // user??? if (userManager.reSendCheck(userid, email)) { json.setHasError(false); json.setMessage(UserProfileConstants.MSG_USER_ENABLED_EMAIL_SEND_SUCCESS); } else { json.setHasError(true); json.setMessage(UserProfileConstants.ERR_MSG_USER_ENABLED_RESEND_EMAIL_FAILED); } return json; } @RequestMapping(value = "/info/perfection") public @ResponseBody OperationJsonObject isUserProfileImperfection() { OperationJsonObject json = new OperationJsonObject(); Long cuserId = UserCookieUtil.getUserId(request); UserDO userDO = userManager.findUserByUserId(cuserId); // ??true boolean result = UserUtil.isUserProfileImperfection(userDO); if (result) { json.setCode("1"); } else { json.setCode("0"); } return json; } @RequestMapping(value = "/modify/addrOrMedNo") public @ResponseBody OperationJsonObject updateUserAddrOrPatientMedNo(HttpServletRequest request) { OperationJsonObject json = new OperationJsonObject(); String encodeUserId = request.getParameter("encodeUserId"); if (StringUtils.isBlank(encodeUserId)) { json.setHasError(true); json.setMessage("?,?!"); return json; } // ??id String decodeUserId = DESUtil.DESDecode(encodeUserId, EncodeKeyConstants.USER_ENCODE_KEY); if (!StringUtils.isNumeric(decodeUserId)) { // id? json.setHasError(true); json.setMessage("?,?!"); return json; } Long userId = Long.parseLong(decodeUserId); UserDO userDo = userManager.findUserByUserId(userId); if (null == userDo) { json.setHasError(true); json.setMessage("?,?!"); return json; } String addr = request.getParameter("address"); String medNo = request.getParameter("patientMedNo"); if (StringUtils.isNotBlank(addr)) { userDo.setAddress(addr); } if (StringUtils.isNotBlank(medNo)) { userDo.setPatient_med_type("1"); userDo.setPatient_med_no(medNo); } // ? UserResult r = userManager.updateMedNoOrAddrByUserId(userDo); if (r.isSystemError()) { json.setHasError(Boolean.TRUE); json.setMessage(r.getResponseDesc()); } return json; } /** * ?? * * @param userDO * @param code * @param result * @return OperationJsonObject */ @MethodRemark(value = "remark=??,method=ajax,code=??") @RequestMapping(value = "/fristCertToTwo", method = RequestMethod.POST) public @ResponseBody OperationJsonObject fristCertUpdateTwo(HttpServletRequest request) { OperationJsonObject json = new OperationJsonObject(); Long userid = UserCookieUtil.getUserId(request); if (!StringUtils.isNumeric(userid.toString())) { // id? json.setHasError(true); json.setMessage("?,?!"); return json; } UserDO userDO = userManager.findUserByUserId(userid); if (null == userDO) { json.setHasError(true); json.setMessage("?,?!"); return json; } String certno = request.getParameter("certno"); if (StringUtils.isNotBlank(userDO.getCertNo()) && !("15".equals(String.valueOf(userDO.getCertNo().length())))) { json.setHasError(true); json.setMessage("?18??!"); return json; } if (!RegexUtil.isIdCard(StringUtils.trim(certno))) { // ??? json.setHasError(Boolean.TRUE); json.setMessage(UserProfileConstants.ERR_MSG_CERT_NO_ERROR); json.setData(certno); return json; } else { UserResult ur = userManager.valiCertNo(userDO.getUserId(), userDO.getCertNo(), userDO.getReg_type()); if (ur != null && ur.getUserDO() != null) { // ?? UserDO userdo = ur.getUserDO(); json.setHasError(Boolean.TRUE); json.setMessage(UserProfileConstants.ERR_MSG_CERT_NO_HAS_BEEN_USED_BY_OTHER_PREFIX + profileProcess.loginIdHiden(userdo.getLoginId(), userdo.getReg_type()) + UserProfileConstants.ERR_MSG_CERT_NO_HAS_BEEN_USED_BY_OTHER_POSTFIX); json.setData(certno); return json; } // ?,??? UserDO user = new UserDO(); user.setUserId(userid); user.setCertNo(certno); user.setCertType("1"); // ? UserResult r = userManager.modifyUserCertNO(user); if (r.isSystemError()) { json.setHasError(Boolean.TRUE); json.setMessage(r.getResponseDesc()); return json; } // ? json.setMessage("?"); return json; } } }