Beispiel #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;
 }
Beispiel #2
0
 @RequestMapping("basicInfo")
 public ModelAndView basicInfo(HttpSession session) {
   ModelAndView mv = new ModelAndView("profile/basicInfo");
   UserSession userSession = (UserSession) session.getAttribute("userSession");
   ThirdPartyAccount qq =
       tpaService.findByUidAndType(
           userSession.getUser().getUid(), ThirdPartyAccount.ACCOUNT_TYPE_QQ);
   ThirdPartyAccount weibo =
       tpaService.findByUidAndType(
           userSession.getUser().getUid(), ThirdPartyAccount.ACCOUNT_TYPE_XINLANG);
   mv.addObject("qq", qq == null ? "" : qq.getHeadIconBig());
   mv.addObject("weibo", weibo == null ? "" : weibo.getHeadIconBig());
   return mv;
 }
Beispiel #3
0
 @RequestMapping("/thirdParty")
 public ModelAndView thirdParty(HttpSession session) {
   UserSession userSession = (UserSession) session.getAttribute("userSession");
   ModelAndView mv = new ModelAndView("profile/thirdParty");
   ThirdPartyAccount qq =
       tpaService.findByUidAndType(
           userSession.getUser().getUid(), ThirdPartyAccount.ACCOUNT_TYPE_QQ);
   mv.addObject("qq", qq);
   ThirdPartyAccount weibo =
       tpaService.findByUidAndType(
           userSession.getUser().getUid(), ThirdPartyAccount.ACCOUNT_TYPE_XINLANG);
   mv.addObject("weibo", weibo);
   return mv;
 }
Beispiel #4
0
 @RequestMapping("/sendEmail")
 @ResponseBody
 public Object sendEmial(String email, HttpSession session) {
   Map<String, Object> map = new HashMap<String, Object>();
   try {
     UserSession userSession = (UserSession) session.getAttribute("userSession");
     sendEmail(email, userSession.getUser());
     map.put("success", true);
   } catch (Exception e) {
     LOG.error("邮件发送失败", e);
     map.put("success", false);
     map.put("message", "未知错误");
   }
   return map;
 }
Beispiel #5
0
  @RequestMapping("/cropImg")
  @ResponseBody
  public Object cropImg(
      HttpServletRequest request,
      String imgUrl,
      double imgInitW,
      double imgInitH,
      double imgW,
      double imgH,
      double imgY1,
      double imgX1,
      double cropH,
      double cropW) {
    Map<String, Object> map = new HashMap<String, Object>();
    ServletContext context = request.getServletContext();
    try {
      String fileName = imgUrl.substring(imgUrl.lastIndexOf("/") + 1);
      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 oraginal = new File(filePath);
      File tmp = new File(filePath + "tmp");
      File file = new File(filePath.replace(".", "1."));
      ImageUtils.resize(oraginal, tmp, (int) imgW, (int) imgH, 1.0f);
      ImageUtils.cut(tmp, file, (int) imgX1, (int) imgY1, (int) cropW, (int) cropH);
      oraginal.delete();
      tmp.delete();
      HttpSession session = request.getSession(false);
      UserSession userSession = (UserSession) session.getAttribute("userSession");
      Param ossBucket = paramService.findByKey(Constants.OSS_BUCKET);
      String key = "user" + userSession.getUser().getUid() + ".png";
      ossService.headIconUpload(ossBucket.getTextValue(), file, "user/headIcon/", key);
      String url = imgUrl.replace(".", "1.");

      map.put("status", "success");
      map.put("url", url);
    } catch (Exception e) {
      map.put("status", "error");
      map.put("message", "文件切割异常");
      LOG.error("文件切割异常:", e);
    }
    return map;
  }
Beispiel #6
0
 @RequestMapping(value = "/unbindWeibo", method = RequestMethod.POST)
 @ResponseBody
 public Object unbindWeibo(HttpSession session) {
   Map<String, Object> map = new HashMap<String, Object>();
   try {
     UserSession userSession = (UserSession) session.getAttribute("userSession");
     ThirdPartyAccount tpa =
         tpaService.findByUidAndType(
             userSession.getUser().getUid(), ThirdPartyAccount.ACCOUNT_TYPE_XINLANG);
     tpa.setUser(null);
     tpaService.update(tpa);
     map.put("success", true);
   } catch (Exception e) {
     LOG.error("解绑新浪失败", e);
     map.put("success", false);
     map.put("message", "未知错误");
   }
   return map;
 }
Beispiel #7
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;
 }
Beispiel #8
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;
 }
Beispiel #9
0
  @RequestMapping("/bindWeibo")
  public void weiboLogin(HttpServletRequest request, HttpServletResponse response, String code) {
    try {
      ThirdPartyAccess xinlang = thirdPartyAccessService.findByType(ThirdPartyAccess.TYPE_XINLANG);
      GlobalSetting globalSetting = (GlobalSetting) request.getSession().getAttribute("setting");
      weibo4j.Oauth oauth = new weibo4j.Oauth();
      weibo4j.http.AccessToken accessTokenObj =
          oauth.getAccessTokenByCode(
              code,
              xinlang.getAccessKey(),
              xinlang.getAccessSecret(),
              "http://" + globalSetting.getAppUrl() + "/profile/bindWeibo");
      String accessToken = null, uid = null, tokenExpireIn = null;
      if ("".equals(accessTokenObj.getAccessToken())) {
        // 我们的网站被CSRF攻击了或者用户取消了授权
        // 做一些数据统计工作
        LOG.info("没有获取到响应参数");
      } else {
        accessToken = accessTokenObj.getAccessToken();
        tokenExpireIn = accessTokenObj.getExpireIn();

        request.getSession().setAttribute("token_expirein", String.valueOf(tokenExpireIn));

        // 利用获取到的accessToken 去获取当前用的uid -------- start
        Account am = new Account(accessToken);
        JSONObject uidObj = am.getUid();
        uid = uidObj.getString("uid");
        request.getSession().setAttribute("openId", uid);
        request.getSession().setAttribute("loginType", UserSession.TYPE_XINLANG);
        // 利用获取到的accessToken 去获取当前用户的openid --------- end
        // 为空代表首次登录,此处获取的信息尚未完全
        ThirdPartyAccount tpa = tpaService.findByOpenId(uid);
        if (tpa == null) {
          // 获取新浪微博用户的信息
          Users um = new Users(accessToken);
          weibo4j.model.User wUser = um.showUserById(uid);
          tpa = new ThirdPartyAccount();
          tpa.setOpenId(uid);
          tpa.setAccountType(UserSession.TYPE_XINLANG);
          tpa.setAccessToken(accessToken);

          tpa.setHeadIconHD(wUser.getAvatarHD());
          tpa.setHeadIconBig(wUser.getAvatarLarge());
          tpa.setHeadIconMid(wUser.getProfileImageUrl());
          tpa.setHeadIconSmall(wUser.getProfileImageUrl());
          tpa = tpaService.update(tpa);
        }
        UserSession userSession =
            (UserSession) request.getSession(false).getAttribute("userSession");
        tpa.setUser(userSession.getUser());
        tpaService.update(tpa);
        response.sendRedirect("thirdParty");
      }
    } catch (IOException e) {
      LOG.error("重定向回本站失败", e);
    } catch (WeiboException e) {
      LOG.error("连接到新浪失败", e);
    } catch (JSONException e) {
      LOG.error("JSON解析错误", e);
    }
  }
Beispiel #10
0
  @RequestMapping("/bindQQ")
  public void bindQQ(HttpServletRequest request, HttpServletResponse response) {
    try {
      ThirdPartyAccess qq = thirdPartyAccessService.findByType(ThirdPartyAccess.TYPE_QQ);
      GlobalSetting globalSetting = (GlobalSetting) request.getSession().getAttribute("setting");
      AccessToken accessTokenObj =
          (new Oauth())
              .getAccessTokenByRequest(
                  request,
                  qq.getAccessKey(),
                  qq.getAccessSecret(),
                  "http://" + globalSetting.getAppUrl() + "/op/login/QQLogin");
      String accessToken = null, openID = null;
      long tokenExpireIn = 0L;
      if ("".equals(accessTokenObj.getAccessToken())) {
        // 我们的网站被CSRF攻击了或者用户取消了授权
        // 做一些数据统计工作
        LOG.info("没有获取到响应参数");
      } else {
        accessToken = accessTokenObj.getAccessToken();
        tokenExpireIn = accessTokenObj.getExpireIn();

        request.getSession().setAttribute("token_expirein", String.valueOf(tokenExpireIn));

        // 利用获取到的accessToken 去获取当前用的openid -------- start
        OpenID openIDObj = new OpenID(accessToken);
        openID = openIDObj.getUserOpenID();

        request.getSession().setAttribute("openId", openID);
        request.getSession().setAttribute("loginType", UserSession.TYPE_QQ);
        // 利用获取到的accessToken 去获取当前用户的openid --------- end
        // 为空代表首次登录,此处获取的信息尚未完全
        ThirdPartyAccount tpa = tpaService.findByOpenId(openID);
        if (tpa == null) {
          // 获取用户QQ空间的信息
          UserInfo qzoneUserInfo = new UserInfo(accessToken, openID);
          UserInfoBean userInfoBean = qzoneUserInfo.getUserInfo(qq.getAccessKey());
          if (userInfoBean != null) {
            tpa = new ThirdPartyAccount();
            tpa.setOpenId(openID);
            tpa.setAccountType(UserSession.TYPE_QQ);
            tpa.setAccessToken(accessToken);
            tpa.setHeadIconBig(userInfoBean.getAvatar().getAvatarURL100());
            tpa.setHeadIconMid(userInfoBean.getAvatar().getAvatarURL50());
            tpa.setHeadIconSmall(userInfoBean.getAvatar().getAvatarURL30());
            tpa = tpaService.update(tpa);
          }
        }

        UserSession userSession =
            (UserSession) request.getSession(false).getAttribute("userSession");
        tpa.setUser(userSession.getUser());
        tpaService.update(tpa);

        //				fate.qq4j.weibo.UserInfo weiboUserInfo = new fate.qq4j.weibo.UserInfo(
        //						accessToken, openID);
        //				com.qq.connect.javabeans.weibo.UserInfoBean weiboUserInfoBean = weiboUserInfo
        //						.getUserInfo(qq.getAccessKey());
        response.sendRedirect("thirdParty");
      }
    } catch (QQConnectException e) {
      LOG.error("连接到QQ失败", e);
    } catch (IOException e) {
      LOG.error("重定向会本站失败", e);
    }
  }