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

This commit is contained in:
Artem.Arefev 2019-05-17 02:01:56 +04:00
commit 4fc8bc3717
4 changed files with 47 additions and 7 deletions

View File

@ -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:/";
}

View File

@ -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);
}
}
}

View File

@ -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>

View File

@ -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"