@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 = {"/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/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 = "/dashboard/upload", method = RequestMethod.POST) public @ResponseBody LinkedList<FileMeta> upload( HttpServletRequest request, HttpServletResponse response) throws FileUploadException, Exception { String dirPath = null; Long fileSizeAllowed = null; try { dirPath = Utils.loadProperties().getProperty("user.file.storing.dir"); fileSizeAllowed = Long.parseLong(Utils.loadProperties().getProperty("user.file.storing.upload.size.bytes")); } catch (Exception e) { e.printStackTrace(); logger.error(Utils.getStackTrace(e.fillInStackTrace())); FileMeta meta = new FileMeta(); meta.setFileName(""); meta.setFileType( "We applogies for inconvenience, " + "there is some error at the server-side. Please try again after some time. "); LinkedList<FileMeta> files = new LinkedList<FileMeta>(); files.add(meta); return files; } logger.info("Processing uploaded file"); String fileUploadRequestType = null; if (request instanceof MultipartHttpServletRequest) { fileUploadRequestType = FileUploadProcessorDelegator.TYPE_MULTIPART_HTTP_SERVLET_REQUEST; } else { fileUploadRequestType = FileUploadProcessorDelegator.TYPE_HTTP_SERVLET_REQUEST; } FileUploadProcessorDelegator delegator = new FileUploadProcessorDelegator(fileUploadRequestType); return delegator.processUploadedFile(request, fileSizeAllowed, dirPath, userService); }