The portal in English and Turkish: a catalogue per language, a switcher at the foot of every page, landing.language, Turkish numbers and dates
Every template and handler message in internal/web goes through a JSON
catalogue under internal/web/locales/<code>/, with English as the fallback.
The language is the person's choice (a cookie set by /_lang/{code}), else
Accept-Language, else landing.language. Tests refuse a key some language
lacks, a translation with other arguments than English, and template text
left in English.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
30f7f3474a
commit
11231d8c2b
113 files changed
+8091
-1981
No files matched your search
+33
-16
@@ -142,8 +142,8 @@ func (p *AccountPages) oidcStart(w http.ResponseWriter, r *http.Request) {
|
||||
pr, err := o.providerFor(r.Context())
|
||||
if err != nil {
|
||||
p.log.Warn("the identity provider did not answer", "issuer", o.cfg.Issuer, "err", err)
|
||||
renderStatus(w, http.StatusBadGateway, "login", loginData{SignupOpen: p.accounts.SignupOpen(), Version: p.version,
|
||||
CSRF: setLoginToken(w, r), SSO: o.cfg.Label, Error: "the sign-in service did not answer; try again shortly"})
|
||||
renderStatus(w, r, http.StatusBadGateway, "login", loginData{SignupOpen: p.accounts.SignupOpen(), Version: p.version,
|
||||
CSRF: setLoginToken(w, r), SSO: o.cfg.Label, Error: langOf(r).T("sso.err.no_answer")})
|
||||
return
|
||||
}
|
||||
state, nonce, verifier := randomToken(), randomToken(), oauth2.GenerateVerifier()
|
||||
@@ -154,20 +154,19 @@ func (p *AccountPages) oidcStart(w http.ResponseWriter, r *http.Request) {
|
||||
http.StatusFound)
|
||||
}
|
||||
|
||||
// errOIDC is a sign-in through the provider that did not work, said plainly.
|
||||
var errOIDC = errors.New("signing in through the provider did not work; start again")
|
||||
|
||||
func (p *AccountPages) oidcCallback(w http.ResponseWriter, r *http.Request) {
|
||||
noStore(w)
|
||||
o := p.oidc
|
||||
fail := func(why string, err error) {
|
||||
p.log.Warn("an OIDC sign-in was refused", "why", why, "err", err)
|
||||
http.SetCookie(w, &http.Cookie{Name: oidcCookie, Path: "/login/oidc", MaxAge: -1})
|
||||
msg := errOIDC.Error()
|
||||
if errors.Is(err, errOIDCAccount) {
|
||||
msg = err.Error()
|
||||
l := langOf(r)
|
||||
msg := l.T("sso.err.failed")
|
||||
var ae accountError
|
||||
if errors.As(err, &ae) {
|
||||
msg = ae.in(l)
|
||||
}
|
||||
renderStatus(w, http.StatusForbidden, "login", loginData{SignupOpen: p.accounts.SignupOpen(),
|
||||
renderStatus(w, r, http.StatusForbidden, "login", loginData{SignupOpen: p.accounts.SignupOpen(),
|
||||
Version: p.version, CSRF: setLoginToken(w, r), SSO: o.cfg.Label, Error: msg})
|
||||
}
|
||||
c, err := r.Cookie(oidcCookie)
|
||||
@@ -233,10 +232,22 @@ func (p *AccountPages) oidcCallback(w http.ResponseWriter, r *http.Request) {
|
||||
// errOIDCAccount is a provider's person the gateway will not let in, with why.
|
||||
var errOIDCAccount = errors.New("")
|
||||
|
||||
type accountError string
|
||||
// accountError is the sentence for the person, by its key and the address it
|
||||
// names, so the page can say it in their language; Error is the English, for
|
||||
// the log.
|
||||
type accountError struct {
|
||||
key string
|
||||
args []any
|
||||
}
|
||||
|
||||
func (e accountError) Error() string { return string(e) }
|
||||
func (e accountError) Is(t error) bool { return t == errOIDCAccount }
|
||||
func (e accountError) Error() string { return english.T(e.key, e.args...) }
|
||||
func (e accountError) Is(t error) bool { return t == errOIDCAccount }
|
||||
func (e accountError) in(l *Lang) string { return l.T(e.key, e.args...) }
|
||||
|
||||
func init() {
|
||||
registerKeys("sso.err.no_email", "sso.err.unverified", "sso.err.no_account",
|
||||
"sso.err.pending", "sso.err.suspended", "sso.err.state")
|
||||
}
|
||||
|
||||
// oidcUser is the account a provider's person signs in as: found by their
|
||||
// verified email, made when the gateway makes accounts this way, with the
|
||||
@@ -246,10 +257,10 @@ func (p *AccountPages) oidcUser(ctx context.Context, claims map[string]any) (sto
|
||||
email, _ := claims["email"].(string)
|
||||
email = store.NormalizeEmail(email)
|
||||
if email == "" {
|
||||
return store.User{}, accountError("the provider gave no email address; ask it to send the email claim")
|
||||
return store.User{}, accountError{key: "sso.err.no_email"}
|
||||
}
|
||||
if v, ok := claims["email_verified"].(bool); ok && !v {
|
||||
return store.User{}, accountError("the provider has not verified " + email)
|
||||
return store.User{}, accountError{"sso.err.unverified", []any{email}}
|
||||
}
|
||||
u, err := o.st.UserByEmail(ctx, email)
|
||||
switch {
|
||||
@@ -266,12 +277,18 @@ func (p *AccountPages) oidcUser(ctx context.Context, claims map[string]any) (sto
|
||||
}
|
||||
p.log.Info("an account was made for a person the identity provider vouched for", "email", email)
|
||||
case errors.Is(err, store.ErrNotFound):
|
||||
return store.User{}, accountError("there is no account for " + email + " on this gateway; ask an administrator for one")
|
||||
return store.User{}, accountError{"sso.err.no_account", []any{email}}
|
||||
case err != nil:
|
||||
return store.User{}, err
|
||||
}
|
||||
if !u.CanSignIn() {
|
||||
return store.User{}, accountError("the account for " + email + " is " + string(u.State))
|
||||
switch u.State {
|
||||
case store.UserPending:
|
||||
return store.User{}, accountError{"sso.err.pending", []any{email}}
|
||||
case store.UserSuspended:
|
||||
return store.User{}, accountError{"sso.err.suspended", []any{email}}
|
||||
}
|
||||
return store.User{}, accountError{"sso.err.state", []any{email, string(u.State)}}
|
||||
}
|
||||
|
||||
groups := claimStrings(claims[or(o.cfg.GroupsClaim, "groups")])
|
||||
|
||||
Reference in new issue
Block a user