Merge branch '88-change-password' into 'dev'
Resolve "Смена пароля" Closes #88 See merge request romanov73/ng-tracker!96environments/staging/deployments/62
commit
3dbf635fb6
@ -0,0 +1,58 @@
|
||||
package ru.ulstu.user.controller;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
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.model.UserDto;
|
||||
import ru.ulstu.user.model.User;
|
||||
import ru.ulstu.user.model.UserListDto;
|
||||
import ru.ulstu.user.service.UserService;
|
||||
import ru.ulstu.user.service.UserSessionService;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "/users")
|
||||
public class UserMvcController extends OdinController<UserListDto, UserDto> {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(UserMvcController.class);
|
||||
|
||||
private final UserService userService;
|
||||
private final UserSessionService userSessionService;
|
||||
|
||||
public UserMvcController(UserService userService,
|
||||
UserSessionService userSessionService) {
|
||||
super(UserListDto.class, UserDto.class);
|
||||
this.userService = userService;
|
||||
this.userSessionService = userSessionService;
|
||||
}
|
||||
|
||||
@GetMapping("/profile")
|
||||
public void getUserProfile(ModelMap modelMap, HttpServletRequest request) {
|
||||
HttpSession session = request.getSession(false);
|
||||
final String sessionId = session.getAttribute(Constants.SESSION_ID_ATTR).toString();
|
||||
modelMap.addAttribute("userDto", new UserDto(userSessionService.getUserBySessionId(sessionId)));
|
||||
}
|
||||
|
||||
@PostMapping("/profile")
|
||||
public void updateUserProfile(ModelMap modelMap, HttpServletRequest request, UserDto userDto) {
|
||||
HttpSession session = request.getSession(false);
|
||||
final String sessionId = session.getAttribute(Constants.SESSION_ID_ATTR).toString();
|
||||
User user = userSessionService.getUserBySessionId(sessionId);
|
||||
modelMap.addAttribute("userDto", userService.updateUserInformation(user, userDto));
|
||||
}
|
||||
|
||||
@PostMapping("/invite")
|
||||
public String inviteUser(@RequestParam(value = "email") String email, ModelMap modelMap) {
|
||||
userService.inviteUser(email);
|
||||
return "redirect:/";
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package ru.ulstu.user.error;
|
||||
|
||||
public class UserPasswordsNotValidOrNotMatchException extends RuntimeException {
|
||||
public UserPasswordsNotValidOrNotMatchException() {
|
||||
public UserPasswordsNotValidOrNotMatchException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package ru.ulstu.user.error;
|
||||
|
||||
public class UserSendingMailException extends RuntimeException {
|
||||
public UserSendingMailException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<title>Password reset</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
Dear <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
|
||||
</p>
|
||||
<p>
|
||||
Your password has been changed.
|
||||
</p>
|
||||
<p>
|
||||
Regards,
|
||||
<br/>
|
||||
<em>Balance Team.</em>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<title>Account activation</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
Аккаунт в системе NG-Tracker был создан. <br />
|
||||
Данные для входа: <br />
|
||||
Логин - <span th:text="${email}"></span> <br />
|
||||
Пароль - <span th:text="${password}"></span>
|
||||
</p>
|
||||
<p>
|
||||
Regards,
|
||||
<br/>
|
||||
<em>Balance Team.</em>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,58 @@
|
||||
function changePassword() {
|
||||
oldPassword = document.getElementById("oldPassword").value
|
||||
password = document.getElementById("password").value
|
||||
confirmPassword = document.getElementById("confirmPassword").value
|
||||
|
||||
if ([oldPassword.length, password.length, confirmPassword.length].includes(0)) {
|
||||
showFeedbackMessage("Заполните все поля", MessageTypesEnum.WARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
if (password != confirmPassword) {
|
||||
showFeedbackMessage("Повторный пароль введен неверно", MessageTypesEnum.WARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url:"/api/1.0/users/changePassword",
|
||||
contentType: "application/json; charset=utf-8",
|
||||
data: JSON.stringify({
|
||||
"oldPassword": oldPassword,
|
||||
"password": password,
|
||||
"confirmPassword": confirmPassword,
|
||||
}),
|
||||
method: "POST",
|
||||
success: function() {
|
||||
document.getElementById("closeModalPassword").click();
|
||||
showFeedbackMessage("Пароль был обновлен", MessageTypesEnum.SUCCESS)
|
||||
|
||||
},
|
||||
error: function(errorData) {
|
||||
showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function inviteUser() {
|
||||
email = document.getElementById("email").value;
|
||||
re = /\S+@\S+\.\S+/;
|
||||
|
||||
|
||||
if (!re.test(email)) {
|
||||
showFeedbackMessage("Некорректный почтовый ящик", MessageTypesEnum.WARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url:"/api/1.0/users/invite?email=" + email,
|
||||
contentType: "application/json; charset=utf-8",
|
||||
method: "POST",
|
||||
success: function() {
|
||||
document.getElementById("closeModalInvite").click();
|
||||
showFeedbackMessage("Пользователь был успешно приглашен", MessageTypesEnum.SUCCESS)
|
||||
},
|
||||
error: function(errorData) {
|
||||
showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING)
|
||||
}
|
||||
})
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head th:fragment="headerfiles">
|
||||
<meta charset="UTF-8"/>
|
||||
<script type='text/javascript' src="js/users.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="changePasswordModal" class="modal fade text-center">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="label">Пригласить пользователя</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input class="form-control" id="oldPassword" type="password"
|
||||
placeholder="Старый пароль" required="required" name="oldPassword"/>
|
||||
<br/>
|
||||
<input class="form-control" id="password" type="password"
|
||||
placeholder="Новый пароль" required="required" name="password"/>
|
||||
<br/>
|
||||
<input class="form-control" id="confirmPassword" type="password"
|
||||
placeholder="Подтверждение нового пароля" required="required" name="confirmPassword"/>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button id="closeModalPassword" type="button" class="btn btn-secondary" data-dismiss="modal">Закрыть
|
||||
</button>
|
||||
<button type="button" onclick="changePassword()" class="btn btn-primary">Сохранить</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,32 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head th:fragment="headerfiles">
|
||||
<meta charset="UTF-8"/>
|
||||
</head>
|
||||
<body>
|
||||
<div id="inviteModal" class="modal fade text-center">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<form id="invite-form" method="post" action="/users/invite">
|
||||
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="label">Пригласить пользователя</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input class="form-control" id="email" type="text"
|
||||
placeholder="email" name="email"/>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Закрыть</button>
|
||||
<button type="submit" class="btn btn-primary">Пригласить</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,75 @@
|
||||
<!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" xmlns="http://www.w3.org/1999/html">
|
||||
<head>
|
||||
<link rel="stylesheet" href="../css/grant.css"/>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
||||
<div class="container" layout:fragment="content">
|
||||
<section id="ewrq">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-lg-12 text-center">
|
||||
<h2 class="section-heading text-uppercase">Личный кабинет</h2>
|
||||
</div>
|
||||
</div>
|
||||
<hr/>
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<form id="profile-form" method="post" th:action="@{'/users/profile'}"
|
||||
th:object="${userDto}">
|
||||
<input type="hidden" name="id" th:field="*{id}"/>
|
||||
<div class="form-group">
|
||||
<label for="firstName">Имя:</label>
|
||||
<input class="form-control" id="firstName" type="text"
|
||||
placeholder="Имя"
|
||||
th:field="*{firstName}"/>
|
||||
<p th:if="${#fields.hasErrors('firstName')}" th:errors="*{firstName}"
|
||||
class="alert alert-danger">Incorrect firstName</p>
|
||||
<p class="help-block text-danger"></p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="lastName">Фамилия:</label>
|
||||
<input class="form-control" id="lastName" type="text"
|
||||
placeholder="lastName"
|
||||
th:field="*{lastName}"/>
|
||||
<p th:if="${#fields.hasErrors('lastName')}" th:errors="*{lastName}"
|
||||
class="alert alert-danger">Incorrect lastName</p>
|
||||
<p class="help-block text-danger"></p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email">Email:</label>
|
||||
<input class="form-control" id="email" type="text"
|
||||
placeholder="Email"
|
||||
th:field="*{email}"/>
|
||||
<p th:if="${#fields.hasErrors('email')}" th:errors="*{email}"
|
||||
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"
|
||||
type="submit">
|
||||
Сохранить
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue