@RequestMapping( value = "/edit", method = RequestMethod.POST, produces = "application/json", consumes = "application/json") @ResponseBody public Map update(@RequestBody Map request, HttpSession session) throws TapWisdomException { Map response = new HashMap(); TwUser twUser = getTwUser(session); User user = new User(); user.setId(twUser.getId()); if (request.containsKey("user")) { String userJson = (String) request.get("user"); user = Utils.getObjectFromString(userJson, User.class); user.setId(twUser.getId()); Boolean update = userService.updateUser(user); user = userService.getUser(user.getId()); UserView userView = CommonUtils.filterSensitiveData(user); session.setAttribute("user", twUser); response.put("success", update); response.put("user", userView); return getResponse(update ? 0 : 1, response); } else { throw new TapWisdomException(1, "user field is mandatory"); } }
@RequestMapping( value = "/login", method = RequestMethod.POST, produces = "application/json", consumes = "application/json") @ResponseBody public Map login(@RequestBody Map request, HttpSession session) throws TapWisdomException { if (isUserLoggedIn(session)) { throw new TapWisdomException(1, "Invalid access to API, user already logged in"); } else { if (request.containsKey(Constants.SOURCE)) { String source = (String) request.get(Constants.SOURCE); UserSource userSource = Enum.valueOf(UserSource.class, source); User user = new User(); user.setSource(userSource); user.setStatus(UserStatus.active); if (userSource == UserSource.facebook) { String fbProfileJson = (String) request.get("facebookProfile"); FacebookProfile facebookProfile = Utils.getObjectFromString(fbProfileJson, FacebookProfile.class); user.setFacebookProfile(facebookProfile); } else if (userSource == UserSource.google) { String gProfileJson = (String) request.get("googleProfile"); GoogleProfile googleProfile = Utils.getObjectFromString(gProfileJson, GoogleProfile.class); user.setGoogleProfile(googleProfile); } else if (userSource == UserSource.linkedIn) { String lProfileJson = (String) request.get("linkedInProfile"); LiProfile linkedInProfile = Utils.getObjectFromString(lProfileJson, LiProfile.class); user.setLinkedInProfile(linkedInProfile); } else { throw new TapWisdomException(1, "Invalid user source passed"); } user = userService.createUser(user); UserView userView = CommonUtils.filterSensitiveData(user); // store minimal info in session session.setAttribute("user", CommonUtils.getTwUser(userView)); Map map = new HashMap(); map.put("user", userView); return getResponse(0, map); } else { throw new TapWisdomException(1, "No source passed"); } } }