Skip to content

Commit

Permalink
Add globalInfo into templates model (#6823)
Browse files Browse the repository at this point in the history
#### What type of PR is this?

/kind improvement
/area core
/milestone 2.20.x

#### What this PR does / why we need it:

This PR adds globalInfo into template models and refactors password reset to adapt data binding.

Fixes #6821

#### Does this PR introduce a user-facing change?

```release-note
None
```
  • Loading branch information
JohnNiang authored Oct 11, 2024
1 parent d63eaed commit 98a1313
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 137 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package run.halo.app.security.preauth;

import java.util.Map;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;
import run.halo.app.infra.actuator.GlobalInfoService;

/**
* Pre-auth two-factor endpoints.
Expand All @@ -16,10 +18,12 @@
class PreAuthTwoFactorEndpoint {

@Bean
RouterFunction<ServerResponse> preAuthTwoFactorEndpoints() {
RouterFunction<ServerResponse> preAuthTwoFactorEndpoints(GlobalInfoService globalInfoService) {
return RouterFunctions.route()
.GET("/challenges/two-factor/totp",
request -> ServerResponse.ok().render("challenges/two-factor/totp")
request -> ServerResponse.ok().render("challenges/two-factor/totp", Map.of(
"globalInfo", globalInfoService.getGlobalInfo()
))
)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@
class="halo-form"
th:action="@{/password-reset/email/{resetToken}(resetToken=${resetToken})}"
method="post"
th:object="${form}"
>
<div class="alert alert-error" role="alert" th:if="${error}">
<strong th:text="${error}"></strong>
<strong th:if="${error == 'rate_limit_exceeded'}" th:text="#{error.rate_limit_exceeded}"></strong>
</div>
<div class="form-item">
<label for="password" th:text="#{form.password.label}">Password</label>
<th:block
th:replace="~{gateway_fragments/input :: password(id = 'password', name = 'password', required = 'true', minlength = 5, maxlength = 257, enableToggle = true)}"
></th:block>
<p class="alert alert-error" th:if="${#fields.hasErrors('password')}" th:errors="*{password}"></p>
</div>
<div class="form-item">
<label for="confirmPassword" th:text="#{form.confirmPassword.label}">Confirm Password</label>
<th:block
th:replace="~{gateway_fragments/input :: password(id = 'confirmPassword', name = 'confirmPassword', required = 'true', minlength = 5, maxlength = 257, enableToggle = true)}"
></th:block>
<p class="alert alert-error" th:if="${#fields.hasErrors('confirmPassword')}" th:errors="*{confirmPassword}"></p>
</div>
<div class="form-item">
<div class="alert" th:text="#{form.password.tips}"></div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
form.password.label=密码
form.confirmPassword.label=确认密码
form.password.tips=密码只能使用大小写字母 (A-Z, a-z)、数字 (0-9),以及以下特殊字符: !@#$%^&*。
form.submit=修改密码
form.submit=修改密码
error.rate_limit_exceeded=您的请求过于频繁,请稍后再试。
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
form.password.label=Password
form.confirmPassword.label=Confirm Password
form.password.tips=The password can only use uppercase and lowercase letters (A-Z, a-z), numbers (0-9), and the following special characters: !@#$%^&*
form.submit=Change password
form.submit=Change password
error.rate_limit_exceeded=Your request is too frequent, please try again later.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
form.password.label=Contraseña
form.confirmPassword.label=Confirmar Contraseña
form.password.tips=La contraseña solo puede usar letras mayúsculas y minúsculas (A-Z, a-z), números (0-9) y los siguientes caracteres especiales: !@#$%^&*.
form.submit=Cambiar Contraseña
form.submit=Cambiar Contraseña
error.rate_limit_exceeded=Su solicitud es demasiado frecuente, por favor intente nuevamente más tarde.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
form.password.label=密碼
form.confirmPassword.label=確認密碼
form.password.tips=密碼只能使用大小寫字母 (A-Z, a-z)、數字 (0-9),以及以下特殊字符: !@#$%^&*。
form.submit=修改密碼
form.submit=修改密碼
error.rate_limit_exceeded=您的請求過於頻繁,請稍後再試。
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@
<button type="submit" th:text="#{form.sent.submit}"></button>
</div>
</form>
<form th:unless="${sent}" class="halo-form" th:action="@{/password-reset/email}" method="post">
<form th:unless="${sent}" class="halo-form" th:action="@{/password-reset/email}" method="post" th:object="${form}">
<div class="alert alert-error" th:if="${param.error.size() > 0}">
<strong th:if="${param.error[0] == 'invalid_reset_token'}" th:text="#{error.invalid_reset_token}"></strong>
</div>
<div class="alert alert-error" th:if="${error}">
<strong th:text="${error}"></strong>
<strong th:if="${error == 'rate_limit_exceeded'}" th:text="#{error.rate_limit_exceeded}"></strong>
</div>
<div class="form-item">
<label for="email" th:text="#{form.email.label}"></label>
<div class="form-input">
<input type="email" id="email" name="email" autofocus required />
<input type="email" id="email" name="email" autofocus required th:field="*{email}"/>
</div>
<p class="alert alert-error" role="alert" th:if="${#fields.hasErrors('email')}" th:errors="*{email}"></p>
</div>
<div class="form-item">
<button type="submit" th:text="#{form.submit}"></button>
</div>
</form>
</th:block>
</th:block>
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
form.email.label=电子邮箱
form.submit=提交
form.sent.submit=返回到登录页面
form.message.success=检查您的电子邮件中是否有重置密码的链接。如果几分钟内没有出现,请检查您的垃圾邮件文件夹。
form.message.success=检查您的电子邮件中是否有重置密码的链接。如果几分钟内没有出现,请检查您的垃圾邮件文件夹。
error.rate_limit_exceeded=您的请求速度太快。请稍后再试。
error.invalid_reset_token=重置密码令牌无效。请重试。
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
form.email.label=Email
form.submit=Submit
form.sent.submit=Return to login
form.message.success=Check your email for a link to reset your password. If it doesn’t appear within a few minutes, check your spam folder.
form.message.success=Check your email for a link to reset your password. If it doesn’t appear within a few minutes, check your spam folder.
error.rate_limit_exceeded=You are making requests too quickly. Please try again later.
error.invalid_reset_token=The reset password token is invalid. Please try again.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
form.email.label=Correo Electrónico
form.submit=Enviar
form.sent.submit=Volver a la Página de Inicio de Sesión
form.message.success=Revisa tu correo electrónico para ver el enlace de restablecimiento de contraseña. Si no aparece en unos minutos, revisa tu carpeta de spam.
form.message.success=Revisa tu correo electrónico para ver el enlace de restablecimiento de contraseña. Si no aparece en unos minutos, revisa tu carpeta de spam.
error.rate_limit_exceeded=Se ha superado el límite de intentos de restablecimiento de contraseña. Por favor, inténtalo de nuevo más tarde.
error.invalid_reset_token=El enlace de restablecimiento de contraseña no es válido o ha expirado. Por favor, solicita un nuevo enlace.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
form.email.label=電子郵件
form.submit=提交
form.sent.submit=返回到登入頁面
form.message.success=檢查您的電子郵件中是否有重置密碼的連結。如果幾分鐘內沒有出現,請檢查您的垃圾郵件資料夾。
form.message.success=檢查您的電子郵件中是否有重置密碼的連結。如果幾分鐘內沒有出現,請檢查您的垃圾郵件資料夾。
error.rate_limit_exceeded=您的請求過於頻繁。請稍後再試。
error.invalid_reset_token=重置密碼連結無效。請重試。

0 comments on commit 98a1313

Please sign in to comment.