|
|
@ -14,13 +14,16 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
|
import ru.ulstu.conference.service.ConferenceService;
|
|
|
|
import ru.ulstu.conference.service.ConferenceService;
|
|
|
|
import ru.ulstu.configuration.ApplicationProperties;
|
|
|
|
import ru.ulstu.configuration.ApplicationProperties;
|
|
|
|
import ru.ulstu.core.error.EntityIdIsNullException;
|
|
|
|
import ru.ulstu.core.error.EntityIdIsNullException;
|
|
|
|
import ru.ulstu.core.jpa.OffsetablePageRequest;
|
|
|
|
import ru.ulstu.core.jpa.OffsetablePageRequest;
|
|
|
|
import ru.ulstu.core.model.BaseEntity;
|
|
|
|
import ru.ulstu.core.model.BaseEntity;
|
|
|
|
import ru.ulstu.core.model.response.PageableItems;
|
|
|
|
import ru.ulstu.core.model.response.PageableItems;
|
|
|
|
|
|
|
|
import ru.ulstu.core.model.response.Response;
|
|
|
|
import ru.ulstu.user.error.UserActivationError;
|
|
|
|
import ru.ulstu.user.error.UserActivationError;
|
|
|
|
|
|
|
|
import ru.ulstu.user.error.UserBlockedException;
|
|
|
|
import ru.ulstu.user.error.UserEmailExistsException;
|
|
|
|
import ru.ulstu.user.error.UserEmailExistsException;
|
|
|
|
import ru.ulstu.user.error.UserIdExistsException;
|
|
|
|
import ru.ulstu.user.error.UserIdExistsException;
|
|
|
|
import ru.ulstu.user.error.UserIsUndeadException;
|
|
|
|
import ru.ulstu.user.error.UserIsUndeadException;
|
|
|
@ -252,7 +255,7 @@ public class UserService implements UserDetailsService {
|
|
|
|
mailService.sendChangePasswordMail(user);
|
|
|
|
mailService.sendChangePasswordMail(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean requestUserPasswordReset(String email) {
|
|
|
|
public boolean requestUserPasswordReset(String email) {
|
|
|
|
User user = userRepository.findOneByEmailIgnoreCase(email);
|
|
|
|
User user = userRepository.findOneByEmailIgnoreCase(email);
|
|
|
|
if (user == null) {
|
|
|
|
if (user == null) {
|
|
|
|
throw new UserNotFoundException(email);
|
|
|
|
throw new UserNotFoundException(email);
|
|
|
@ -313,6 +316,9 @@ public class UserService implements UserDetailsService {
|
|
|
|
if (!user.getActivated()) {
|
|
|
|
if (!user.getActivated()) {
|
|
|
|
throw new UserNotActivatedException();
|
|
|
|
throw new UserNotActivatedException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user.getBlocker() != null) {
|
|
|
|
|
|
|
|
throw new UserBlockedException(String.format("Вы заблокированы пользователем %s", user.getBlocker().getUserAbbreviate()));
|
|
|
|
|
|
|
|
}
|
|
|
|
return new org.springframework.security.core.userdetails.User(user.getLogin(),
|
|
|
|
return new org.springframework.security.core.userdetails.User(user.getLogin(),
|
|
|
|
user.getPassword(),
|
|
|
|
user.getPassword(),
|
|
|
|
Optional.ofNullable(user.getRoles()).orElse(Collections.emptySet()).stream()
|
|
|
|
Optional.ofNullable(user.getRoles()).orElse(Collections.emptySet()).stream()
|
|
|
@ -389,4 +395,10 @@ public class UserService implements UserDetailsService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ImmutableMap.of("users", usersInfoNow, "error", err);
|
|
|
|
return ImmutableMap.of("users", usersInfoNow, "error", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void blockUser(int userId) {
|
|
|
|
|
|
|
|
User userToBlock = findById(userId);
|
|
|
|
|
|
|
|
userToBlock.setBlocker(getCurrentUser());
|
|
|
|
|
|
|
|
userRepository.save(userToBlock);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|