mirror of
https://github.com/zitadel/zitadel.git
synced 2025-04-16 02:11:30 +00:00

* fix: typo ZITADEL uppercase for OTP Issuer * fix: password validation after change in current user agent * fix: otp validation after setup in current user agent * add waiting * add waiting * show u2f state * regenerate css * add useragentID to webauthn verify * return mfa attribute in mgmt * switch between providers * use preferredLoginName for webauthn display * some fixes * correct translations for login * add some missing event translations * fix usersession test * remove unnecessary cancel button on password change done
71 lines
2.2 KiB
Go
71 lines
2.2 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
http_mw "github.com/caos/zitadel/internal/api/http/middleware"
|
|
"github.com/caos/zitadel/internal/auth_request/model"
|
|
)
|
|
|
|
const (
|
|
tmplChangePassword = "changepassword"
|
|
tmplChangePasswordDone = "changepassworddone"
|
|
)
|
|
|
|
type changePasswordData struct {
|
|
OldPassword string `schema:"change-old-password"`
|
|
NewPassword string `schema:"change-new-password"`
|
|
NewPasswordConfirmation string `schema:"change-password-confirmation"`
|
|
}
|
|
|
|
func (l *Login) handleChangePassword(w http.ResponseWriter, r *http.Request) {
|
|
data := new(changePasswordData)
|
|
authReq, err := l.getAuthRequestAndParseData(r, data)
|
|
if err != nil {
|
|
l.renderError(w, r, authReq, err)
|
|
return
|
|
}
|
|
userAgentID, _ := http_mw.UserAgentIDFromCtx(r.Context())
|
|
err = l.authRepo.ChangePassword(setContext(r.Context(), authReq.UserOrgID), authReq.UserID, data.OldPassword, data.NewPassword, userAgentID)
|
|
if err != nil {
|
|
l.renderChangePassword(w, r, authReq, err)
|
|
return
|
|
}
|
|
l.renderChangePasswordDone(w, r, authReq)
|
|
}
|
|
|
|
func (l *Login) renderChangePassword(w http.ResponseWriter, r *http.Request, authReq *model.AuthRequest, err error) {
|
|
var errType, errMessage string
|
|
if err != nil {
|
|
errMessage = l.getErrorMessage(r, err)
|
|
}
|
|
data := passwordData{
|
|
baseData: l.getBaseData(r, authReq, "Change Password", errType, errMessage),
|
|
profileData: l.getProfileData(authReq),
|
|
}
|
|
policy, description, _ := l.getPasswordComplexityPolicy(r, authReq.UserOrgID)
|
|
if policy != nil {
|
|
data.PasswordPolicyDescription = description
|
|
data.MinLength = policy.MinLength
|
|
if policy.HasUppercase {
|
|
data.HasUppercase = UpperCaseRegex
|
|
}
|
|
if policy.HasLowercase {
|
|
data.HasLowercase = LowerCaseRegex
|
|
}
|
|
if policy.HasSymbol {
|
|
data.HasSymbol = SymbolRegex
|
|
}
|
|
if policy.HasNumber {
|
|
data.HasNumber = NumberRegex
|
|
}
|
|
}
|
|
l.renderer.RenderTemplate(w, r, l.renderer.Templates[tmplChangePassword], data, nil)
|
|
}
|
|
|
|
func (l *Login) renderChangePasswordDone(w http.ResponseWriter, r *http.Request, authReq *model.AuthRequest) {
|
|
var errType, errMessage string
|
|
data := l.getUserData(r, authReq, "Password Change Done", errType, errMessage)
|
|
l.renderer.RenderTemplate(w, r, l.renderer.Templates[tmplChangePasswordDone], data, nil)
|
|
}
|