Esempio n. 1
0
 @RequestMapping("/updateBasicInfo")
 @ResponseBody
 public Object updateBasicInfo(User u, int headIcon, HttpSession session) {
   Map<String, Object> map = new HashMap<String, Object>();
   UserSession userSession = (UserSession) session.getAttribute("userSession");
   User user = userSession.getUser();
   try {
     user.setAddress(u.getAddress());
     user.setHeadIconUsed(headIcon);
     if (headIcon != 0) {
       ThirdPartyAccount tpa = tpaService.findByUidAndType(user.getUid(), headIcon);
       if (tpa != null) {
         user.setHeadIconBig(tpa.getHeadIconBig());
       } else {
         user.setHeadIconBig(null);
       }
     } else {
       user.setHeadIconBig(user.getHeadIconLocal());
     }
     user.setBirthday(u.getBirthday());
     user.setQq(u.getQq());
     user.setSex(u.getSex());
     userService.update(user);
     map.put("success", true);
     map.put("message", "保存成功");
   } catch (Exception e) {
     LOG.error("更新个人信息失败,用户ID:" + user.getUid(), e);
     map.put("success", false);
     map.put("message", "未知错误");
   }
   return map;
 }
Esempio n. 2
0
 @RequestMapping("/updateHeadIcon")
 @ResponseBody
 public Object updateHeadIcon(String url, HttpServletRequest request) {
   Map<String, Object> map = new HashMap<String, Object>();
   try {
     UserSession userSession = (UserSession) request.getSession(false).getAttribute("userSession");
     User user = userSession.getUser();
     String fileName = url.substring(url.lastIndexOf("/") + 1);
     ServletContext context = request.getServletContext();
     String relpath =
         context.getRealPath("/").substring(0, context.getRealPath("/").indexOf(File.separator))
             + File.separator;
     String uppath = "download" + File.separator + "headIcon" + File.separator + fileName;
     String filePath = relpath + uppath;
     File file = new File(filePath);
     Param ossBucket = paramService.findByKey(Constants.OSS_BUCKET);
     Param ossEndpoint = paramService.findByKey(Constants.OSS_ENDPOINT);
     Param ossUrl = paramService.findByKey(Constants.OSS_URL);
     String key = "user" + userSession.getUser().getUid() + ".png";
     ossService.headIconUpload(ossBucket.getTextValue(), file, "user/headIcon/", key);
     String newUrl =
         "http://"
             + (ossUrl == null || ossUrl.getTextValue() == null || "".equals(ossUrl)
                 ? ossBucket.getTextValue() + "." + ossEndpoint.getTextValue()
                 : ossUrl.getTextValue())
             + "/user/headIcon/"
             + key;
     user.setHeadIconLocal(newUrl);
     if (user.getHeadIconUsed() == User.HEADICON_LOCAL) {
       user.setHeadIconBig(newUrl);
       user.setHeadIconMid(newUrl);
       user.setHeadIconSmall(newUrl);
     }
     file.delete();
     userService.update(user);
     map.put("success", true);
   } catch (Exception e) {
     LOG.error("更新头像失败", e);
     map.put("success", false);
     map.put("message", "未知错误");
   }
   return map;
 }
Esempio n. 3
0
 @RequestMapping("/updateMobile")
 @ResponseBody
 public Object updateMobile(String mobile, String code, HttpSession session) {
   Map<String, Object> map = new HashMap<String, Object>();
   try {
     String m = (String) session.getAttribute("mobile");
     if (!m.equals(mobile)) {
       map.put("success", false);
       map.put("message", "验证失败,手机号不一致");
       return map;
     }
     UserSession userSession = (UserSession) session.getAttribute("userSession");
     User user = userSession.getUser();
     String smsCode = (String) session.getAttribute("smsCode");
     String guid = (String) session.getAttribute("security");
     SecurityVerification securityVerification = securityVerificationService.find(guid);
     Date now = new Date();
     long time = now.getTime() - securityVerification.getVerificationTime().getTime();
     if (time > securityVerification.getTimeout() * 60 * 1000) {
       map.put("message", "验证码超时,请重新验证");
       map.put("success", true);
     } else if (code.trim().equals(smsCode)) {
       user.setMobile(mobile);
       user.setMobileStatus(true);
       userService.update(user);
       securityVerificationService.delete(securityVerification);
       map.put("message", "验证成功");
       map.put("success", true);
     }
     map.put("success", true);
   } catch (Exception e) {
     LOG.error("手机验证失败", e);
     map.put("success", false);
     map.put("message", "未知错误");
   }
   return map;
 }