Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improve ui of logout page #6810

Merged
merged 7 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.springframework.http.MediaType;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.web.server.WebFilterExchange;
import org.springframework.security.web.server.authentication.logout.DelegatingServerLogoutHandler;
import org.springframework.security.web.server.authentication.logout.RedirectServerLogoutSuccessHandler;
Expand All @@ -21,6 +23,7 @@
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;
import run.halo.app.core.user.service.UserService;
import run.halo.app.security.authentication.SecurityConfigurer;
import run.halo.app.security.authentication.rememberme.RememberMeServices;

Expand Down Expand Up @@ -55,13 +58,18 @@ public LogoutSuccessHandler(ServerLogoutHandler... logoutHandler) {
}

@Bean
RouterFunction<ServerResponse> logoutPage() {
RouterFunction<ServerResponse> logoutPage(UserService userService) {
return RouterFunctions.route()
.GET("/logout", request -> {
var user = ReactiveSecurityContextHolder.getContext()
.map(SecurityContext::getAuthentication)
.map(Authentication::getName)
.flatMap(userService::getUser);
var exchange = request.exchange();
var contextPath = exchange.getRequest().getPath().contextPath().value();
return ServerResponse.ok().render("logout", Map.of(
"action", contextPath + "/logout"
"action", contextPath + "/logout",
"user", user
));
})
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<form th:fragment="form" class="halo-form" id="logout-form" name="logout-form" th:action="@{/logout}" method="post">
<div class="user-info" th:object="${user}">
<img th:if="*{spec.avatar}" th:src="*{spec.avatar}" class="user-avatar" />
<div class="user-details">
<span th:text="#{form.currentUser.label}"></span>
<span class="user-name" th:text="|*{spec.displayName}(@*{metadata.name})|"></span>
</div>
</div>
<div class="form-item">
<button type="submit" th:text="#{form.submit}"></button>
</div>
</form>

<div class="form-item">
<a href="javascript:history.back()" class="cancel-link" th:text="#{form.cancel}"> </a>
</div>
</form>
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
form.submit=退出登录
form.submit=退出登录
form.cancel=取消
form.currentUser.label=当前登录的用户:
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
form.submit=Logout
form.submit=Logout
form.cancel=Cancel
form.currentUser.label=Currently logged in user:
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
form.submit=Cerrar Sesión
form.submit=Cerrar Sesión
form.cancel=Cancelar
form.currentUser.label=Usuario actualmente conectado:
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
form.submit=退出登入
form.submit=退出登入
form.cancel=取消
form.currentUser.label=當前登入的使用者:
47 changes: 44 additions & 3 deletions application/src/main/resources/templates/logout.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,55 @@
<!doctype html>
<!DOCTYPE html>
<html
xmlns:th="https://www.thymeleaf.org"
th:replace="~{gateway_fragments/layout:: layout(title = |#{title} - ${site.title}|, head = null, body = ~{::body})}"
th:replace="~{gateway_fragments/layout:: layout(title = |#{title} - ${site.title}|, head = ~{::head}, body = ~{::body})}"
>
<th:block th:fragment="body">
<div class="gateway-wrapper">
<div class="gateway-wrapper logout-page-wrapper">
<div th:replace="~{gateway_fragments/common::haloLogo}"></div>
<div class="halo-form-wrapper">
<h1 class="form-title" th:text="#{form.title}"></h1>
<form th:replace="~{gateway_fragments/logout::form}"></form>
</div>
<div th:replace="~{gateway_fragments/common::languageSwitcher}"></div>
</div>
</th:block>

<th:block th:fragment="head">
<style>
.logout-page-wrapper .user-info {
border-radius: var(--rounded-lg);
padding: var(--spacing-xs);
gap: var(--spacing-lg);
display: flex;
margin-bottom: 2em;
align-items: center;
border: 1px dashed #dfe6ecb3;
}

.logout-page-wrapper .user-avatar {
width: 4em;
border-radius: 100%;
}

.logout-page-wrapper .user-details {
color: var(--color-text);
font-size: var(--text-sm);
gap: var(--spacing-xs);
display: flex;
flex-direction: column;
}

.logout-page-wrapper .user-name {
font-weight: 600;
color: #333;
}

.logout-page-wrapper .cancel-link {
color: var(--color-link);
font-size: var(--text-sm);
text-decoration: none;
text-align: center;
}
</style>
</th:block>
</html>
Loading