@RequestMapping( value = "/dashboard/updateuser", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody String updateUserProfile( @RequestBody String contactObjectJSON, ModelMap model, HttpServletRequest request) { logger.info("Updating User Profile for JSON" + contactObjectJSON); if (filter.isUserSessionExpired(request, encoder)) { return "You session has expired. Please login again to proceed!!"; } Contact contact = null; try { contact = Utils.getContactObjectFromJSON(contactObjectJSON); logger.info("Updating User Profile for username = "******"Error in updating user details in database."; } model.addAttribute("command", contact); return "true"; }
@RequestMapping( value = "/dashboard/updatepassword", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public boolean updatePassword(@RequestBody String passwordsJSON) { logger.info("Updating User Passwords for JSON" + passwordsJSON); try { String passwords[] = Utils.getPasswordsFromJSON(passwordsJSON); logger.info("Passwords received : " + Arrays.toString(passwords)); // check if user is login Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth instanceof UsernamePasswordAuthenticationToken) { UserDetails userDetail = (UserDetails) auth.getPrincipal(); logger.debug("Processing for user's details: " + userDetail); String username = userDetail.getUsername(); logger.info("Username taken from SecurityContext " + username); User user = userService.getUserByUsername(username); // mdPassEncoder.isPasswordValid(user.getPassword(), passwords[0], user.getSalt())){ // BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); // mdPassEncoder.encodePassword(passwords[1], salt)); if (user != null) { if (user.getPassword() != null && encoder.matches(passwords[0], user.getPassword())) { // String salt = String.valueOf(Utils.getSalt()); // user.setSalt(salt); user.setPassword(encoder.encode(passwords[1])); userService.create(user); } else { return false; } } } } catch (Exception e) { logger.error(Utils.getStackTrace(e.fillInStackTrace())); return false; } return true; }
@RequestMapping( value = {"/welcome"}, method = RequestMethod.GET) public ModelAndView defaultPage(Locale locale, HttpServletRequest request) { logger.info("Welcome to welcome Page. The client locale is {}.", locale); Contact contact = new Contact(); // check if user is login Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth instanceof UsernamePasswordAuthenticationToken) { UserDetails userDetail = (UserDetails) auth.getPrincipal(); String username = userDetail.getUsername(); logger.info("username taken from SecurityContext " + username); User user = userService.getUserByUsername(username); if (user != null) { Utils.populateContact(user, contact); } logger.info("Contact object populated with username " + contact.getUsername()); } ModelAndView mav = new ModelAndView("userMain"); mav.addObject("countriesMap", Utils.getCountriesMap()); mav.addObject("command", contact); mav.addObject( DashboardSessionManagmentFilter.SESSION_AUTHENTICATION_PARAM_NAME, filter.generateSecurityToken(request, encoder)); return mav; }
@RequestMapping( value = {"/dashboard/getFilesLog"}, method = RequestMethod.GET) public ModelAndView getUploadedFilesLog(Locale locale) { logger.info("Welcome to files log Page. The client locale is {}.", locale); ModelAndView mav = new ModelAndView(); // check if user is login Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth instanceof UsernamePasswordAuthenticationToken) { UserDetails userDetail = (UserDetails) auth.getPrincipal(); String username = userDetail.getUsername(); logger.info("Username taken for checking user is verified " + username); User user = userService.getUserByUsername(username); if (user != null) { mav.addObject("filesSet", user.getFiles()); } } mav.setViewName("filesLog"); return mav; }