Commit 00b37ce1 authored by Matija Obreza's avatar Matija Obreza

Fixed bug in updating user's email address

parent 93290f7e
......@@ -255,14 +255,19 @@ public class UserServiceImpl implements UserService {
@PreAuthorize("hasRole('ADMINISTRATOR') || principal.user.id == #userId")
@Transactional(readOnly = false, rollbackFor = NotUniqueUserException.class)
public User updateData(long userId, String name, String email) throws UserException {
final User user = userPersistence.findOne(userId);
if (user == null) {
throw new UserException("No user with id=" + userId);
}
if (!emailValidator.isValid(email)) {
throw new UserException();
LOG.warn("Invalid email provided: " + email);
throw new UserException("Invalid email provided: " + email);
}
if (userPersistence.findByEmail(email) != null) {
if (! StringUtils.equals(email, user.getEmail()) && userPersistence.findByEmail(email) != null) {
throw new NotUniqueUserException(new Throwable(), email);
}
final User user = userPersistence.findOne(userId);
user.setName(name);
user.setEmail(email);
userPersistence.save(user);
......@@ -449,7 +454,7 @@ public class UserServiceImpl implements UserService {
final Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (principal instanceof AuthUserDetails) {
if (! ((AuthUserDetails) principal).getUser().getId().equals(user.getId())) {
if (!((AuthUserDetails) principal).getUser().getId().equals(user.getId())) {
LOG.warn("Not adding role, user != principal");
return;
}
......
......@@ -16,12 +16,15 @@
package org.genesys2.server.servlet.controller.rest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.genesys2.server.exception.NotUniqueUserException;
import org.genesys2.server.exception.UserException;
import org.genesys2.server.model.impl.User;
import org.genesys2.server.service.EMailVerificationService;
import org.genesys2.server.service.OAuth2ClientDetailsService;
import org.genesys2.server.service.TeamService;
import org.genesys2.server.service.UserService;
import org.genesys2.server.servlet.controller.rest.model.UserChangedDataJson;
......@@ -34,11 +37,12 @@ import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller("restUsersController")
......@@ -52,9 +56,6 @@ public class UsersController extends RestController {
@Autowired
protected UserService userService;
@Autowired
private OAuth2ClientDetailsService clientDetailsService;
@Autowired
private EMailVerificationService emailVerificationService;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment