mirror of
https://github.com/thomiceli/opengist.git
synced 2025-07-12 19:01:50 +02:00
Add translation strings (#269)
This commit is contained in:
@ -16,6 +16,7 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/thomiceli/opengist/internal/config"
|
||||
"github.com/thomiceli/opengist/internal/db"
|
||||
"github.com/thomiceli/opengist/internal/i18n"
|
||||
"github.com/thomiceli/opengist/internal/utils"
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/language"
|
||||
@ -48,8 +49,8 @@ func register(ctx echo.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
setData(ctx, "title", tr(ctx, "auth.new-account"))
|
||||
setData(ctx, "htmlTitle", "New account")
|
||||
setData(ctx, "title", trH(ctx, "auth.new-account"))
|
||||
setData(ctx, "htmlTitle", trH(ctx, "auth.new-account"))
|
||||
setData(ctx, "disableForm", disableForm)
|
||||
setData(ctx, "disableSignup", disableSignup)
|
||||
setData(ctx, "isLoginPage", false)
|
||||
@ -68,30 +69,30 @@ func processRegister(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
if disableSignup == true {
|
||||
return errorRes(403, "Signing up is disabled", nil)
|
||||
return errorRes(403, tr(ctx, "error.signup-disabled"), nil)
|
||||
}
|
||||
|
||||
if getData(ctx, "DisableLoginForm") == true {
|
||||
return errorRes(403, "Signing up via registration form is disabled", nil)
|
||||
return errorRes(403, tr(ctx, "error.signup-disabled-form"), nil)
|
||||
}
|
||||
|
||||
setData(ctx, "title", "New account")
|
||||
setData(ctx, "htmlTitle", "New account")
|
||||
setData(ctx, "title", trH(ctx, "auth.new-account"))
|
||||
setData(ctx, "htmlTitle", trH(ctx, "auth.new-account"))
|
||||
|
||||
sess := getSession(ctx)
|
||||
|
||||
dto := new(db.UserDTO)
|
||||
if err := ctx.Bind(dto); err != nil {
|
||||
return errorRes(400, "Cannot bind data", err)
|
||||
return errorRes(400, tr(ctx, "error.cannot-bind-data"), err)
|
||||
}
|
||||
|
||||
if err := ctx.Validate(dto); err != nil {
|
||||
addFlash(ctx, utils.ValidationMessages(&err), "error")
|
||||
addFlash(ctx, utils.ValidationMessages(&err, getData(ctx, "locale").(*i18n.Locale)), "error")
|
||||
return html(ctx, "auth_form.html")
|
||||
}
|
||||
|
||||
if exists, err := db.UserExists(dto.Username); err != nil || exists {
|
||||
addFlash(ctx, "Username already exists", "error")
|
||||
addFlash(ctx, tr(ctx, "flash.auth.username-exists"), "error")
|
||||
return html(ctx, "auth_form.html")
|
||||
}
|
||||
|
||||
@ -126,8 +127,8 @@ func processRegister(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
func login(ctx echo.Context) error {
|
||||
setData(ctx, "title", tr(ctx, "auth.login"))
|
||||
setData(ctx, "htmlTitle", "Login")
|
||||
setData(ctx, "title", trH(ctx, "auth.login"))
|
||||
setData(ctx, "htmlTitle", trH(ctx, "auth.login"))
|
||||
setData(ctx, "disableForm", getData(ctx, "DisableLoginForm"))
|
||||
setData(ctx, "isLoginPage", true)
|
||||
return html(ctx, "auth_form.html")
|
||||
@ -135,7 +136,7 @@ func login(ctx echo.Context) error {
|
||||
|
||||
func processLogin(ctx echo.Context) error {
|
||||
if getData(ctx, "DisableLoginForm") == true {
|
||||
return errorRes(403, "Logging in via login form is disabled", nil)
|
||||
return errorRes(403, tr(ctx, "error.login-disabled-form"), nil)
|
||||
}
|
||||
|
||||
var err error
|
||||
@ -143,7 +144,7 @@ func processLogin(ctx echo.Context) error {
|
||||
|
||||
dto := &db.UserDTO{}
|
||||
if err = ctx.Bind(dto); err != nil {
|
||||
return errorRes(400, "Cannot bind data", err)
|
||||
return errorRes(400, tr(ctx, "error.cannot-bind-data"), err)
|
||||
}
|
||||
password := dto.Password
|
||||
|
||||
@ -154,7 +155,7 @@ func processLogin(ctx echo.Context) error {
|
||||
return errorRes(500, "Cannot get user", err)
|
||||
}
|
||||
log.Warn().Msg("Invalid HTTP authentication attempt from " + ctx.RealIP())
|
||||
addFlash(ctx, "Invalid credentials", "error")
|
||||
addFlash(ctx, tr(ctx, "flash.auth.invalid-credentials"), "error")
|
||||
return redirect(ctx, "/login")
|
||||
}
|
||||
|
||||
@ -163,7 +164,7 @@ func processLogin(ctx echo.Context) error {
|
||||
return errorRes(500, "Cannot check for password", err)
|
||||
}
|
||||
log.Warn().Msg("Invalid HTTP authentication attempt from " + ctx.RealIP())
|
||||
addFlash(ctx, "Invalid credentials", "error")
|
||||
addFlash(ctx, tr(ctx, "flash.auth.invalid-credentials"), "error")
|
||||
return redirect(ctx, "/login")
|
||||
}
|
||||
|
||||
@ -178,7 +179,7 @@ func processLogin(ctx echo.Context) error {
|
||||
func oauthCallback(ctx echo.Context) error {
|
||||
user, err := gothic.CompleteUserAuth(ctx.Response(), ctx.Request())
|
||||
if err != nil {
|
||||
return errorRes(400, "Cannot complete user auth: "+err.Error(), err)
|
||||
return errorRes(400, tr(ctx, "error.complete-oauth-login", err.Error()), err)
|
||||
}
|
||||
|
||||
currUser := getUserLogged(ctx)
|
||||
@ -190,7 +191,7 @@ func oauthCallback(ctx echo.Context) error {
|
||||
return errorRes(500, "Cannot update user "+title.String(user.Provider)+" id", err)
|
||||
}
|
||||
|
||||
addFlash(ctx, "Account linked to "+title.String(user.Provider), "success")
|
||||
addFlash(ctx, tr(ctx, "flash.auth.account-linked-oauth", title.String(user.Provider)), "success")
|
||||
return redirect(ctx, "/settings")
|
||||
}
|
||||
|
||||
@ -198,7 +199,7 @@ func oauthCallback(ctx echo.Context) error {
|
||||
userDB, err := db.GetUserByProvider(user.UserID, user.Provider)
|
||||
if err != nil {
|
||||
if getData(ctx, "DisableSignup") == true {
|
||||
return errorRes(403, "Signing up is disabled", nil)
|
||||
return errorRes(403, tr(ctx, "error.signup-disabled"), nil)
|
||||
}
|
||||
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
@ -216,7 +217,7 @@ func oauthCallback(ctx echo.Context) error {
|
||||
|
||||
if err = userDB.Create(); err != nil {
|
||||
if db.IsUniqueConstraintViolation(err) {
|
||||
addFlash(ctx, "Username "+user.NickName+" already exists in Opengist", "error")
|
||||
addFlash(ctx, tr(ctx, "flash.auth.username-exists"), "error")
|
||||
return redirect(ctx, "/login")
|
||||
}
|
||||
|
||||
@ -246,7 +247,7 @@ func oauthCallback(ctx echo.Context) error {
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
addFlash(ctx, "Could not get user keys", "error")
|
||||
addFlash(ctx, tr(ctx, "flash.auth.user-sshkeys-not-retrievable"), "error")
|
||||
log.Error().Err(err).Msg("Could not get user keys")
|
||||
}
|
||||
|
||||
@ -262,7 +263,7 @@ func oauthCallback(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
if err = sshKey.Create(); err != nil {
|
||||
addFlash(ctx, "Could not create ssh key", "error")
|
||||
addFlash(ctx, tr(ctx, "flash.auth.user-sshkeys-not-created"), "error")
|
||||
log.Error().Err(err).Msg("Could not create ssh key")
|
||||
}
|
||||
}
|
||||
@ -360,7 +361,7 @@ func oauth(ctx echo.Context) error {
|
||||
return errorRes(500, "Cannot unlink account from "+title.String(provider), err)
|
||||
}
|
||||
|
||||
addFlash(ctx, "Account unlinked from "+title.String(provider), "success")
|
||||
addFlash(ctx, tr(ctx, "flash.auth.account-unlinked-oauth", title.String(provider)), "success")
|
||||
return redirect(ctx, "/settings")
|
||||
}
|
||||
}
|
||||
@ -368,7 +369,7 @@ func oauth(ctx echo.Context) error {
|
||||
ctxValue := context.WithValue(ctx.Request().Context(), gothic.ProviderParamKey, provider)
|
||||
ctx.SetRequest(ctx.Request().WithContext(ctxValue))
|
||||
if provider != GitHubProvider && provider != GitLabProvider && provider != GiteaProvider && provider != OpenIDConnect {
|
||||
return errorRes(400, "Unsupported provider", nil)
|
||||
return errorRes(400, tr(ctx, "error.oauth-unsupported"), nil)
|
||||
}
|
||||
|
||||
gothic.BeginAuthHandler(ctx.Response(), ctx.Request())
|
||||
|
Reference in New Issue
Block a user