Compare commits

...

7 Commits
dev ... gl_88

Author SHA1 Message Date
arefiev1997
48d7131593 gl_88 inviting user 2019-05-13 03:16:37 +04:00
arefiev1997
9abcf7792e Merge branch 'lk' into gl_88 2019-05-12 23:07:59 +04:00
arefiev1997
9c53257729 fixed lk page 2019-05-12 22:26:50 +04:00
arefiev1997
ed8855272f lk base 2019-05-11 22:06:31 +04:00
arefiev1997
09aa0bd4d6 Merge remote-tracking branch 'origin/move-to-jdk11' into lk 2019-05-06 00:38:58 +04:00
Anton Romanov
13131186bf Merge branch 'dev' into 'master'
Dev

See merge request romanov73/ng-tracker!27
2019-03-04 10:04:02 +00:00
Anton Romanov
f7bbf4d746 Merge branch 'dev' into 'master'
Dev to master

See merge request romanov73/ng-tracker!25
2019-01-16 21:04:20 +00:00
12 changed files with 256 additions and 40 deletions

View File

@ -125,6 +125,7 @@ dependencies {
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.6.0'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.6.0'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test'
testCompile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.3.1'

View File

@ -3,15 +3,9 @@ package ru.ulstu.user.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import ru.ulstu.configuration.Constants;
import ru.ulstu.core.model.response.PageableItems;
import ru.ulstu.core.model.response.Response;
@ -19,15 +13,12 @@ import ru.ulstu.odin.controller.OdinController;
import ru.ulstu.odin.model.OdinMetadata;
import ru.ulstu.odin.model.OdinVoid;
import ru.ulstu.odin.service.OdinService;
import ru.ulstu.user.model.UserDto;
import ru.ulstu.user.model.UserListDto;
import ru.ulstu.user.model.UserResetPasswordDto;
import ru.ulstu.user.model.UserRoleConstants;
import ru.ulstu.user.model.UserRoleDto;
import ru.ulstu.user.model.UserSessionListDto;
import ru.ulstu.user.model.*;
import ru.ulstu.user.service.UserService;
import ru.ulstu.user.service.UserSessionService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import static ru.ulstu.user.controller.UserController.URL;
@ -142,8 +133,8 @@ public class UserController extends OdinController<UserListDto, UserDto> {
}
// TODO: add page for user edit (user-profile)
@PostMapping("/change-information")
public Response<UserDto> changeInformation(@Valid @RequestBody UserDto userDto) {
@PostMapping(value = "/change-information", params = "save")
public Response<UserDto> changeInformation(@Valid UserDto userDto) {
log.debug("REST: UserController.changeInformation( {} )", userDto.getLogin());
return new Response<>(userService.updateUserInformation(userDto));
}
@ -167,4 +158,10 @@ public class UserController extends OdinController<UserListDto, UserDto> {
log.debug("REST: UserController.requestPasswordReset( {} )", key);
return new Response<>(userService.completeUserPasswordReset(key, userResetPasswordDto));
}
@PostMapping("invite")
public Response<Boolean> inviteUser(@RequestParam("email") String email) {
log.debug("REST: UserController.inviteUser( {} )", email);
return new Response<>(userService.inviteUser(email));
}
}

View File

@ -0,0 +1,35 @@
package ru.ulstu.user.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import ru.ulstu.configuration.Constants;
import ru.ulstu.user.model.User;
import ru.ulstu.user.model.UserDto;
import ru.ulstu.user.service.UserSessionService;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
@Controller
@RequestMapping(value = "/profile")
@ApiIgnore
public class UserProfileController {
private final UserSessionService userSessionService;
public UserProfileController(UserSessionService userSessionService)
{
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();
UserDto userDto = userSessionService.getUserBySessionId(sessionId);
modelMap.addAttribute("userDto", userDto);
}
}

View File

@ -85,4 +85,9 @@ public class MailService {
public void sendPasswordResetMail(User user) {
sendEmailFromTemplate(user, "passwordResetEmail", Constants.MAIL_RESET);
}
@Async
public void sendInviteEmail(User user, Map<String, Object> variables) {
sendEmailFromTemplate(variables, user, "inviteUser", Constants.MAIL_ACTIVATE);
}
}

View File

@ -1,5 +1,6 @@
package ru.ulstu.user.service;
import com.google.common.collect.ImmutableMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
@ -37,13 +38,7 @@ import ru.ulstu.user.repository.UserRepository;
import ru.ulstu.user.repository.UserRoleRepository;
import ru.ulstu.user.util.UserUtils;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
@Service
@ -329,4 +324,23 @@ public class UserService implements UserDetailsService {
public List<User> filterByAgeAndDegree(boolean hasDegree, boolean hasAge) {
return userRepository.filterByAgeAndDegree(hasDegree, hasAge);
}
public boolean inviteUser(String email) {
if (userRepository.findOneByEmailIgnoreCase(email) != null) {
throw new UserEmailExistsException(email);
}
String password = UserUtils.generatePassword(6);
User user = new User();
user.setLogin(email);
user.setPassword(passwordEncoder.encode(password));
user.setActivated(true);
user.setFirstName("USER");
user.setLastName("USER");
user.setEmail(email);
userRepository.save(user);
Map<String, Object> variables = ImmutableMap.of("password", password);
mailService.sendInviteEmail(user, variables );
return true;
}
}

View File

@ -10,10 +10,13 @@ import ru.ulstu.core.jpa.OffsetablePageRequest;
import ru.ulstu.core.model.response.PageableItems;
import ru.ulstu.user.error.UserNotFoundException;
import ru.ulstu.user.model.User;
import ru.ulstu.user.model.UserDto;
import ru.ulstu.user.model.UserSession;
import ru.ulstu.user.model.UserSessionListDto;
import ru.ulstu.user.repository.UserSessionRepository;
import javax.mail.Session;
import static ru.ulstu.core.util.StreamApiUtils.convert;
@Service
@ -22,10 +25,12 @@ public class UserSessionService {
private final Logger log = LoggerFactory.getLogger(UserSessionService.class);
private final UserSessionRepository userSessionRepository;
private final UserService userService;
private final UserMapper userMapper;
public UserSessionService(UserSessionRepository userSessionRepository, UserService userService) {
public UserSessionService(UserSessionRepository userSessionRepository, UserService userService, UserMapper userMapper) {
this.userSessionRepository = userSessionRepository;
this.userService = userService;
this.userMapper = userMapper;
}
@Transactional(readOnly = true)
@ -54,4 +59,9 @@ public class UserSessionService {
userSessionRepository.save(userSession);
log.debug("User session {} closed", sessionId);
}
public UserDto getUserBySessionId(String sessionId) {
User user = userSessionRepository.findOneBySessionId(sessionId).getUser();
return new UserDto(user);
}
}

View File

@ -6,6 +6,14 @@ import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import java.security.SecureRandom;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class UserUtils {
private static final int DEF_COUNT = 20;
@ -17,6 +25,10 @@ public class UserUtils {
return RandomStringUtils.randomNumeric(DEF_COUNT);
}
public static String generatePassword(int length) {
return RandomStringUtils.randomAscii(length);
}
public static String getCurrentUserLogin(SecurityContext securityContext) {
if (securityContext == null) {
return null;

View File

@ -33,6 +33,6 @@ spring.liquibase.enabled=true
# Application Settings
ng-tracker.base-url=http://127.0.0.1:8080
ng-tracker.undead-user-login=admin
ng-tracker.dev-mode=true
ng-tracker.dev-mode=false
ng-tracker.use-https=false
ng-tracker.check-run=false

View File

@ -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>
Your account has been created, please click on the URL below to activate it:
</p>
<p>
Your login details are: <span th:text="${user.email + ' ' + password}"></span>>
</p>
<p>
Regards,
<br/>
<em>Balance Team.</em>
</p>
</body>
</html>

View File

@ -55,18 +55,46 @@
<a class="nav-link js-scroll-trigger" target="_blank" href="http://is.ulstu.ru">Сайт кафедры</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" target="_blank" th:href="@{'http://timetable.athene.tech?filter='+${currentUser}}">Расписание</a>
<a class="nav-link js-scroll-trigger" target="_blank"
th:href="@{'http://timetable.athene.tech?filter='+${currentUser}}">Расписание</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" target="_blank" href="https://kias.rfbr.ru/">КИАС РФФИ</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="/logout">Выход</a>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Профиль
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="/profile/profile">Личный кабинет</a>
<a class="dropdown-item" href="/logout">Выход</a>
<a class="dropdown-item" data-toggle="modal" href="invite.html" data-target="#exampleModal">Пригласить</a>
</div>
</li>
</ul>
</div>
</div>
</nav>
<div id="exampleModal" class="modal fade text-center">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Пригласить пользователя</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form id="invite-form" method="post" action="/api/1.0/users/invite">
<input class="form-control" id="email" type="text"
placeholder="email" name="email"/>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</form>
</div>
</div>
</div>
<div class="container-fluid">
<div class="container">
<ul id="messages" class="feedback-panel">
@ -100,33 +128,40 @@
<th:block layout:fragment="scripts">
</th:block>
<!-- Yandex.Metrika counter -->
<script type="text/javascript" >
<script type="text/javascript">
(function (d, w, c) {
(w[c] = w[c] || []).push(function() {
(w[c] = w[c] || []).push(function () {
try {
w.yaCounter49387279 = new Ya.Metrika2({
id:49387279,
clickmap:true,
trackLinks:true,
accurateTrackBounce:true,
webvisor:true
id: 49387279,
clickmap: true,
trackLinks: true,
accurateTrackBounce: true,
webvisor: true
});
} catch(e) { }
} catch (e) {
}
});
var n = d.getElementsByTagName("script")[0],
s = d.createElement("script"),
f = function () { n.parentNode.insertBefore(s, n); };
f = function () {
n.parentNode.insertBefore(s, n);
};
s.type = "text/javascript";
s.async = true;
s.src = "https://mc.yandex.ru/metrika/tag.js";
if (w.opera == "[object Opera]") {
d.addEventListener("DOMContentLoaded", f, false);
} else { f(); }
} else {
f();
}
})(document, window, "yandex_metrika_callbacks2");
</script>
<noscript><div><img src="https://mc.yandex.ru/watch/49387279" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
<noscript>
<div><img src="https://mc.yandex.ru/watch/49387279" style="position:absolute; left:-9999px;" alt=""/></div>
</noscript>
<!-- /Yandex.Metrika counter -->
</body>
</html>

View File

@ -0,0 +1,15 @@
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Пригласить пользователя</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form id="invite-form" method="post" action="@{/api/1.0/users/invite}">
<div class="modal-body">
<input class="form-control" id="email" type="text" placeholder="Email"/>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>

View File

@ -0,0 +1,71 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
<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="@{'/api/1.0/users/change-information'}"
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">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 login</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>