Esempio n. 1
0
  @SuppressWarnings("unchecked")
  @RequestMapping(value = "/update", method = RequestMethod.GET)
  @ResponseBody
  public void updateUserInfo(User user, HttpServletRequest request, HttpServletResponse response) {

    ReflectUtil reflectUtil = new ReflectUtil();
    Map<String, Object> map = reflectUtil.getFieldAndValue(user);

    Map<String, Object> u = (Map<String, Object>) SessionUtil.getUser(request);

    user.setUsers_id((String) u.get("users_id"));

    // boolean f = userService.update(user,map);

    // 判断昵称是否合法
    if (this.isUserName(user.getUsername()) != true) {
      util.toJsonMsg(response, 1, "昵称错误,请重新填写!");
      return;
    }
    // 判断电话号码是否合法
    if (this.isPhone(user.getPhone()) != true) {
      util.toJsonMsg(response, 1, "电话号码不正确!");
      return;
    }
    // 判断qq号码是否合法
    if (this.isQq(user.getQq()) != true) {
      util.toJsonMsg(response, 1, "QQ号码不正确!");
      return;
    }
    // 判断邮箱是否合法
    if (this.isEmail(user.getEmail()) != true) {
      util.toJsonMsg(response, 1, "邮箱格式不正确!");
      return;
    }

    // 修改头像前,先删除旧头像
    String user_photo = user.getPhoto();
    if (user_photo != null) {
      String u_photo = (String) u.get("photo");
      if (u_photo != null && !u_photo.equals("")) {
        if (!u_photo.equals(FinalVariable.PHOTO_BOY) && !u_photo.equals(FinalVariable.PHOTO_GRIL))
          this.deletePhoto("/photo/" + u_photo);
      }
    }

    // 将用户数据插入到数据库中
    if (userService.update(user, map) == true) {
      util.toJsonMsg(response, 0, "修改成功!");

      u = userService.getUserById((String) u.get("users_id"));
      SessionUtil.setUser(request, u);
      return;
    } else {
      util.toJsonMsg(response, 2, "网络超时!");
      return;
    }
  }
Esempio n. 2
0
  @SuppressWarnings("unchecked")
  @RequestMapping(value = "/userInfo", method = RequestMethod.GET)
  @ResponseBody
  public String getUserInfo(User user, HttpServletRequest request, HttpServletResponse response) {

    String users_id = user.getUsers_id();
    Map<String, Object> u = new HashMap<String, Object>();
    if (users_id != null && !users_id.equals("")) {
      u = userService.getUserById(users_id);
    } else {
      u = (Map<String, Object>) SessionUtil.getUser(request);
    }

    return Object2JsonUtil.Object2Json(u);
  }