esoe
2 weeks ago
23 changed files with 465 additions and 80 deletions
@ -0,0 +1,25 @@
@@ -0,0 +1,25 @@
|
||||
package gsp.technologies.main.access.login; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
|
||||
/** |
||||
* DTO для обмена данными с сервисом авторизации |
||||
* хранит: |
||||
* - номер сессии пользователя |
||||
* - номер запрошенного аккаунта |
||||
*/ |
||||
|
||||
@AllArgsConstructor |
||||
@NoArgsConstructor |
||||
@Data |
||||
public class AuthDTO implements Serializable { |
||||
|
||||
private String sessionId; |
||||
private String accountId; |
||||
private String code35; |
||||
|
||||
} |
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
package gsp.technologies.main.access.logout; |
||||
|
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.context.request.RequestContextHolder; |
||||
import org.springframework.web.context.request.ServletRequestAttributes; |
||||
|
||||
/** |
||||
* Контроллер для выхода из системы |
||||
*/ |
||||
@Controller |
||||
@RequestMapping(path = "/logout") |
||||
public class LogoutController { |
||||
private static final Logger log = LoggerFactory.getLogger(LogoutController.class); |
||||
|
||||
@GetMapping("") |
||||
public String mainframe() { |
||||
log.info("GET /logout"); |
||||
log.info("текущая сессия: {}", RequestContextHolder.currentRequestAttributes().getSessionId()); |
||||
|
||||
//logout
|
||||
ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes(); |
||||
attr.getRequest().getSession().invalidate(); |
||||
log.info("новая сессия: {}", RequestContextHolder.currentRequestAttributes().getSessionId()); |
||||
|
||||
//возвращаем пользователя на исходную страницу, с новой сссией
|
||||
String referer = attr.getRequest().getHeader("Referer"); |
||||
return "redirect:"+ referer; |
||||
} |
||||
} |
@ -0,0 +1,73 @@
@@ -0,0 +1,73 @@
|
||||
package gsp.technologies.main.account; |
||||
|
||||
import java.util.List; |
||||
|
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.ui.Model; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.context.request.RequestContextHolder; |
||||
|
||||
import gsp.technologies.main.code.Code; |
||||
|
||||
/** |
||||
* Контроллер формы аккаунта |
||||
* возвращает thymeleaf шаблон |
||||
*/ |
||||
@Controller |
||||
@RequestMapping(path = "/account") |
||||
public class AccountController { |
||||
private static final Logger log = LoggerFactory.getLogger(AccountController.class); |
||||
|
||||
@GetMapping("") |
||||
public String account(Model model) { |
||||
log.info("GET /account"); |
||||
//данные аккаунта (id, organization, position)
|
||||
Long id = 1L; |
||||
String code = Code.encode(id); |
||||
OrganizationDTO organization = OrganizationDTO.builder() |
||||
.id(1L) |
||||
.name("ГСП-Т") |
||||
.build(); |
||||
PositionDTO position = PositionDTO.builder() |
||||
.id(1L) |
||||
.name("Сварщик") |
||||
.organization(organization) |
||||
.build(); |
||||
String sessionid = RequestContextHolder.currentRequestAttributes().getSessionId(); |
||||
List<CourseDTO> courses = List.of( |
||||
CourseDTO.builder() |
||||
.id(1L) |
||||
.name("Охрана труда") |
||||
.passed(true) |
||||
.build(), |
||||
CourseDTO.builder() |
||||
.id(2L) |
||||
.name("Работы на высоте") |
||||
.passed(false) |
||||
.build(), |
||||
CourseDTO.builder() |
||||
.id(3L) |
||||
.name("Первая помощь") |
||||
.passed(true) |
||||
.build() |
||||
); |
||||
AccountDTO account = AccountDTO.builder() |
||||
.id(id) |
||||
.code(code) |
||||
.position(position) |
||||
.sessionid(sessionid) |
||||
.courses(courses) |
||||
.build(); |
||||
|
||||
model.addAttribute("account", account); |
||||
log.info("account: " + account); |
||||
|
||||
//перечень назначенных курсов
|
||||
// ...
|
||||
|
||||
return "account"; |
||||
} |
||||
} |
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
package gsp.technologies.main.account; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.List; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Builder; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
|
||||
@Builder |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
@Data |
||||
public class AccountDTO implements Serializable { |
||||
private Long id; |
||||
private String code; |
||||
private PositionDTO position; |
||||
private String sessionid; |
||||
private List<CourseDTO> courses; |
||||
} |
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
package gsp.technologies.main.account; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Builder; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
|
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
@Builder |
||||
@Data |
||||
public class CourseDTO implements Serializable { |
||||
|
||||
private Long id; |
||||
private String name; |
||||
private Boolean passed; |
||||
} |
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
package gsp.technologies.main.account; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Builder; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
|
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
@Builder |
||||
@Data |
||||
public class OrganizationDTO { |
||||
private Long id; |
||||
private String name; //наименование организации
|
||||
} |
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
package gsp.technologies.main.account; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Builder; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
|
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
@Builder |
||||
@Data |
||||
public class PositionDTO implements Serializable { |
||||
private Long id; |
||||
private String name; |
||||
private OrganizationDTO organization; |
||||
} |
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
package gsp.technologies.main.code; |
||||
|
||||
/** |
||||
* Класс, содержащий методы преобразования id в 35-ричное представление |
||||
*/ |
||||
public abstract class Code { |
||||
public static String encode(Long value) { |
||||
String code = value.toString(); |
||||
return code; |
||||
} |
||||
|
||||
public static Long decode(String code) { |
||||
Long value = Long.valueOf(code); |
||||
return value; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
package gsp.technologies.main.course; |
||||
|
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.PathVariable; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
||||
@Controller |
||||
@RequestMapping(path = "/courses") |
||||
public class CourseController { |
||||
private static final Logger log = LoggerFactory.getLogger(CourseController.class); |
||||
|
||||
@GetMapping("/view/{id}") |
||||
public String course(@PathVariable Long id) { |
||||
log.info("GET /courses"); |
||||
|
||||
return "course"; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,2 @@
@@ -0,0 +1,2 @@
|
||||
# Первая помощь |
||||
![pic](/content/courses/1/pictures/states.png) |
After Width: | Height: | Size: 164 KiB |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html> |
||||
<html xmlns="http://www.w3.org/1999/xhtml" |
||||
xmlns:th="http://www.thymeleaf.org"> |
||||
<head> |
||||
<meta charset="UTF-8"> |
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||
<title>exam-account</title> |
||||
<script src="https://cdn.jsdelivr.net/npm/@webcomponents/webcomponentsjs@2/webcomponents-loader.min.js"></script> |
||||
<script type="module" src="https://cdn.jsdelivr.net/gh/zerodevx/zero-md@1/src/zero-md.min.js"></script> |
||||
<style> |
||||
.code { |
||||
color: red; |
||||
font-weight: bold; |
||||
font-size: 300%; |
||||
} |
||||
</style> |
||||
</head> |
||||
<header> |
||||
<!-- Информация об аккаунте: id, organization, position --> |
||||
<div th:insert="~{fragments/account :: info(account=${account})}"></div> |
||||
</header> |
||||
<body> |
||||
<!-- Перечень доступных курсов --> |
||||
<div th:insert="~{fragments/account :: courses(account=${account})}"></div> |
||||
</body> |
||||
<footer> |
||||
<!-- Выход из аккаунта, обновление сессии --> |
||||
<div th:insert="~{fragments/controls :: logout}"></div> |
||||
<div th:insert="~{fragments/common/footer :: copy}"></div> |
||||
</footer> |
||||
</html> |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html> |
||||
<html xmlns="http://www.w3.org/1999/xhtml" |
||||
xmlns:th="http://www.thymeleaf.org"> |
||||
<head> |
||||
<meta charset="UTF-8"> |
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||
<title>exam-account</title> |
||||
<script src="https://cdn.jsdelivr.net/npm/@webcomponents/webcomponentsjs@2/webcomponents-loader.min.js"></script> |
||||
<script type="module" src="https://cdn.jsdelivr.net/gh/zerodevx/zero-md@1/src/zero-md.min.js"></script> |
||||
<style> |
||||
.code { |
||||
color: red; |
||||
font-weight: bold; |
||||
font-size: 300%; |
||||
} |
||||
</style> |
||||
</head> |
||||
<header> |
||||
<!-- Информация об аккаунте: id, organization, position --> |
||||
<!-- <div th:insert="~{fragments/account :: info(account=${account})}"></div> --> |
||||
</header> |
||||
<body> |
||||
<!-- первый курс --> |
||||
<div th:insert="~{fragments/course :: main}"></div> |
||||
</body> |
||||
<footer> |
||||
<!-- Выход из аккаунта, обновление сессии --> |
||||
<!-- <div th:insert="~{fragments/controls :: logout}"></div> |
||||
<div th:insert="~{fragments/common/footer :: copy}"></div> --> |
||||
</footer> |
||||
</html> |
@ -0,0 +1,10 @@
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html> |
||||
<html xmlns:th="http://www.thymeleaf.org"> |
||||
|
||||
<body> |
||||
<div th:fragment="main"> |
||||
<hr> |
||||
<zero-md th:src="@{/content/courses/1/main.md}"></zero-md> |
||||
</div> |
||||
</body> |
||||
</html> |
Before Width: | Height: | Size: 129 KiB After Width: | Height: | Size: 164 KiB |
Loading…
Reference in new issue