@Secured({"ROLE_ADMIN", "ROLE_USER"}) @RequestMapping(value = "/api/profile/picture/update", method = RequestMethod.POST) public void updateProfilePicture(@RequestBody final Picture picture) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String email = authentication.getName(); pictureBean.create(picture); User user = userBean.findByEmail(email); user.setPicture(picture); userBean.update(user); }
@Secured({"ROLE_ADMIN", "ROLE_USER"}) @RequestMapping(value = "/api/profile", method = RequestMethod.GET, produces = "application/json") public User getProfile() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String email = authentication.getName(); User user = userBean.findByEmail(email); return user; }
/* * It works fine, you need just authorization from Gmail */ @RequestMapping(value = "/forgotpassword", method = RequestMethod.POST, produces = "text/plain") public ResponseEntity<String> forgotPassword(@RequestBody String email) { System.out.println("Email:" + email); User user = userBean.findByEmail(email); if (user != null) { // emailService.send(email, "*****@*****.**", "Property for Sales Password", // "Your password is :"+user.getPassword()); return new ResponseEntity("Password sent to email", HttpStatus.ACCEPTED); } else return new ResponseEntity("Email doesnt match to any existing user", HttpStatus.BAD_REQUEST); }
@RequestMapping(value = "/isconnected", method = RequestMethod.GET, produces = "application/json") public ResponseEntity<Role> isConnected() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String email = authentication.getName(); User user = userBean.findByEmail(email); Role role = new Role(); role.setName(authentication.getAuthorities().iterator().next().toString()); System.out.println("now is connected: " + user + " " + email + " " + role); if (user == null) return new ResponseEntity(role, HttpStatus.FORBIDDEN); return new ResponseEntity(role, HttpStatus.ACCEPTED); }
@RequestMapping(value = "/user/create", method = RequestMethod.POST) public void register(@RequestBody final User user) { Criteria criteria = new Criteria(); criteriaBean.create(criteria); BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); Role role = roleBean.findByName("ROLE_USER"); user.setPassword(passwordEncoder.encode(user.getPassword())); user.setRole(role); user.setCriteria(criteria); userBean.create(user); }
@Secured({"ROLE_ADMIN", "ROLE_USER"}) @RequestMapping(value = "/api/profile/update", method = RequestMethod.POST) public void update(@RequestBody final User user) { userBean.update(user); }