コード例 #1
0
 @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);
 }
コード例 #2
0
 @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;
 }
コード例 #3
0
 /*
  * 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);
 }
コード例 #4
0
 @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);
 }
コード例 #5
0
 @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);
 }
コード例 #6
0
 @Secured({"ROLE_ADMIN", "ROLE_USER"})
 @RequestMapping(value = "/api/profile/update", method = RequestMethod.POST)
 public void update(@RequestBody final User user) {
   userBean.update(user);
 }