zitadel/internal/api/ui/login/password_handler.go
Max Peintner b432cf4963
fix(login): use label policy settings for favicon, translate titles (#4641)
* fix: render favicon from label policy

* translate main title

* translation

* i18n

* i18n

* i18nkey

* rm attr

* select user title

* Add description meta

* Update internal/api/ui/login/mfa_init_verify_handler.go

Co-authored-by: Livio Spring <livio.a@gmail.com>

* Update internal/api/ui/login/renderer.go

Co-authored-by: Livio Spring <livio.a@gmail.com>

* merge ifs

* use errors.internal

* check for i18ndescriptionkey

* missing i18n

Co-authored-by: Livio Spring <livio.a@gmail.com>
2022-11-07 08:55:12 +00:00

52 lines
1.4 KiB
Go

package login
import (
"net/http"
"github.com/zitadel/zitadel/internal/domain"
)
const (
tmplPassword = "password"
)
type passwordFormData struct {
Password string `schema:"password"`
}
func (l *Login) renderPassword(w http.ResponseWriter, r *http.Request, authReq *domain.AuthRequest, err error) {
var errID, errMessage string
if err != nil {
errID, errMessage = l.getErrorMessage(r, err)
}
data := l.getUserData(r, authReq, "Password.Title","Password.Description", errID, errMessage)
funcs := map[string]interface{}{
"showPasswordReset": func() bool {
if authReq.LoginPolicy != nil {
return !authReq.LoginPolicy.HidePasswordReset
}
return true
},
}
l.renderer.RenderTemplate(w, r, l.getTranslator(r.Context(), authReq), l.renderer.Templates[tmplPassword], data, funcs)
}
func (l *Login) handlePasswordCheck(w http.ResponseWriter, r *http.Request) {
data := new(passwordFormData)
authReq, err := l.getAuthRequestAndParseData(r, data)
if err != nil {
l.renderError(w, r, authReq, err)
return
}
err = l.authRepo.VerifyPassword(setContext(r.Context(), authReq.UserOrgID), authReq.ID, authReq.UserID, authReq.UserOrgID, data.Password, authReq.AgentID, domain.BrowserInfoFromRequest(r))
if err != nil {
if authReq.LoginPolicy.IgnoreUnknownUsernames {
l.renderLogin(w, r, authReq, err)
return
}
l.renderPassword(w, r, authReq, err)
return
}
l.renderNextStep(w, r, authReq)
}