Merge branch '87-inviting-user' into 88-change-password

merge-requests/96/head
Artem.Arefev 5 years ago
commit 4fc8bc3717

@ -3,14 +3,15 @@ package ru.ulstu.user.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import ru.ulstu.configuration.Constants;
import ru.ulstu.odin.controller.OdinController;
import ru.ulstu.user.error.UserSendingMailException;
import ru.ulstu.user.model.UserDto;
import ru.ulstu.user.model.User;
import ru.ulstu.user.model.UserListDto;
@ -23,20 +24,26 @@ import java.util.Map;
@Controller
@RequestMapping(value = "/users")
public class UserControllerV2 extends OdinController<UserListDto, UserDto> {
public class UserMvcController extends OdinController<UserListDto, UserDto> {
private final Logger log = LoggerFactory.getLogger(UserControllerV2.class);
private final Logger log = LoggerFactory.getLogger(UserMvcController.class);
private final UserService userService;
private final UserSessionService userSessionService;
public UserControllerV2(UserService userService,
UserSessionService userSessionService) {
public UserMvcController(UserService userService,
UserSessionService userSessionService) {
super(UserListDto.class, UserDto.class);
this.userService = userService;
this.userSessionService = userSessionService;
}
@ExceptionHandler(Exception.class)
public String errorHandler(Model model, Exception exception) {
model.addAttribute("error", exception.getMessage());
return "/error/error";
}
@GetMapping("/profile")
public void getUserProfile(ModelMap modelMap, HttpServletRequest request) {
HttpSession session = request.getSession(false);
@ -53,7 +60,7 @@ public class UserControllerV2 extends OdinController<UserListDto, UserDto> {
}
@PostMapping("/invite")
public String inviteUser(@RequestParam(value = "email") String email) throws UserSendingMailException {
public String inviteUser(@RequestParam(value = "email") String email, ModelMap modelMap) {
userService.inviteUser(email);
return "redirect:/";
}

@ -52,6 +52,8 @@ import java.util.stream.Collectors;
@Service
@Transactional
public class UserService implements UserDetailsService {
private static final String INVITE_USER_EXCEPTION = "Во время отправки приглашения произошла ошибка";
private final Logger log = LoggerFactory.getLogger(UserService.class);
private final UserRepository userRepository;
private final PasswordEncoder passwordEncoder;
@ -213,6 +215,7 @@ public class UserService implements UserDetailsService {
user.setFirstName(updateUser.getFirstName());
user.setLastName(updateUser.getLastName());
user.setEmail(updateUser.getEmail());
user.setLogin(updateUser.getLogin());
user = userRepository.save(user);
log.debug("Updated Information for User: {}", user.getLogin());
return userMapper.userEntityToUserDto(user);
@ -334,7 +337,7 @@ public class UserService implements UserDetailsService {
try {
mailService.sendInviteMail(variables, email);
} catch (MessagingException e) {
throw new UserSendingMailException(email);
throw new UserSendingMailException(INVITE_USER_EXCEPTION);
}
}
}

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<div class="container" layout:fragment="content">
<section id="services">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading text-uppercase"><span th:text="${error}"></span></h2>
<a href="/"><h3>Вернуться на главную</h3></a>
</div>
</div>
</div>
</section>
</div>
</body>
</html>

@ -49,6 +49,15 @@
class="alert alert-danger">Incorrect email</p>
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<label for="login">Логин:</label>
<input class="form-control" id="login" type="text"
placeholder="Login"
th:field="*{login}"/>
<p th:if="${#fields.hasErrors('login')}" th:errors="*{login}"
class="alert alert-danger">Incorrect email</p>
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<button id="sendMessageButton" name="save"
class="btn btn-success text-uppercase"

Loading…
Cancel
Save