Merge branch '87-inviting-user' into 88-change-password
This commit is contained in:
commit
4fc8bc3717
@ -3,14 +3,15 @@ package ru.ulstu.user.controller;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.ui.ModelMap;
|
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.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import ru.ulstu.configuration.Constants;
|
import ru.ulstu.configuration.Constants;
|
||||||
import ru.ulstu.odin.controller.OdinController;
|
import ru.ulstu.odin.controller.OdinController;
|
||||||
import ru.ulstu.user.error.UserSendingMailException;
|
|
||||||
import ru.ulstu.user.model.UserDto;
|
import ru.ulstu.user.model.UserDto;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.model.UserListDto;
|
import ru.ulstu.user.model.UserListDto;
|
||||||
@ -23,20 +24,26 @@ import java.util.Map;
|
|||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping(value = "/users")
|
@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 UserService userService;
|
||||||
private final UserSessionService userSessionService;
|
private final UserSessionService userSessionService;
|
||||||
|
|
||||||
public UserControllerV2(UserService userService,
|
public UserMvcController(UserService userService,
|
||||||
UserSessionService userSessionService) {
|
UserSessionService userSessionService) {
|
||||||
super(UserListDto.class, UserDto.class);
|
super(UserListDto.class, UserDto.class);
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.userSessionService = userSessionService;
|
this.userSessionService = userSessionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(Exception.class)
|
||||||
|
public String errorHandler(Model model, Exception exception) {
|
||||||
|
model.addAttribute("error", exception.getMessage());
|
||||||
|
return "/error/error";
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/profile")
|
@GetMapping("/profile")
|
||||||
public void getUserProfile(ModelMap modelMap, HttpServletRequest request) {
|
public void getUserProfile(ModelMap modelMap, HttpServletRequest request) {
|
||||||
HttpSession session = request.getSession(false);
|
HttpSession session = request.getSession(false);
|
||||||
@ -53,7 +60,7 @@ public class UserControllerV2 extends OdinController<UserListDto, UserDto> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/invite")
|
@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);
|
userService.inviteUser(email);
|
||||||
return "redirect:/";
|
return "redirect:/";
|
||||||
}
|
}
|
@ -52,6 +52,8 @@ import java.util.stream.Collectors;
|
|||||||
@Service
|
@Service
|
||||||
@Transactional
|
@Transactional
|
||||||
public class UserService implements UserDetailsService {
|
public class UserService implements UserDetailsService {
|
||||||
|
private static final String INVITE_USER_EXCEPTION = "Во время отправки приглашения произошла ошибка";
|
||||||
|
|
||||||
private final Logger log = LoggerFactory.getLogger(UserService.class);
|
private final Logger log = LoggerFactory.getLogger(UserService.class);
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
private final PasswordEncoder passwordEncoder;
|
private final PasswordEncoder passwordEncoder;
|
||||||
@ -213,6 +215,7 @@ public class UserService implements UserDetailsService {
|
|||||||
user.setFirstName(updateUser.getFirstName());
|
user.setFirstName(updateUser.getFirstName());
|
||||||
user.setLastName(updateUser.getLastName());
|
user.setLastName(updateUser.getLastName());
|
||||||
user.setEmail(updateUser.getEmail());
|
user.setEmail(updateUser.getEmail());
|
||||||
|
user.setLogin(updateUser.getLogin());
|
||||||
user = userRepository.save(user);
|
user = userRepository.save(user);
|
||||||
log.debug("Updated Information for User: {}", user.getLogin());
|
log.debug("Updated Information for User: {}", user.getLogin());
|
||||||
return userMapper.userEntityToUserDto(user);
|
return userMapper.userEntityToUserDto(user);
|
||||||
@ -334,7 +337,7 @@ public class UserService implements UserDetailsService {
|
|||||||
try {
|
try {
|
||||||
mailService.sendInviteMail(variables, email);
|
mailService.sendInviteMail(variables, email);
|
||||||
} catch (MessagingException e) {
|
} catch (MessagingException e) {
|
||||||
throw new UserSendingMailException(email);
|
throw new UserSendingMailException(INVITE_USER_EXCEPTION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
21
src/main/resources/templates/error/error.html
Normal file
21
src/main/resources/templates/error/error.html
Normal 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>
|
@ -49,6 +49,15 @@
|
|||||||
class="alert alert-danger">Incorrect email</p>
|
class="alert alert-danger">Incorrect email</p>
|
||||||
<p class="help-block text-danger"></p>
|
<p class="help-block text-danger"></p>
|
||||||
</div>
|
</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">
|
<div class="form-group">
|
||||||
<button id="sendMessageButton" name="save"
|
<button id="sendMessageButton" name="save"
|
||||||
class="btn btn-success text-uppercase"
|
class="btn btn-success text-uppercase"
|
||||||
|
Loading…
Reference in New Issue
Block a user