mirror of
https://github.com/zitadel/zitadel.git
synced 2025-04-21 22:41:31 +00:00

* feat: user service v2 remove user * feat: user service v2 add user human * feat: user service v2 change user human * feat: user service v2 change user human unit tests * feat: user service v2 reactivate, deactivate, lock, unlock user * feat: user service v2 integration tests * fix: merge back origin/main * lint: linter corrections * fix: move permission check for isVerfied and password change * fix: add deprecated notices and other review comments * fix: consistent naming in proto * fix: errors package renaming * fix: remove / delete user renaming in integration test * fix: machine user status changes through user v2 api * fix: linting changes * fix: linting changes * fix: changes from review * fix: changes from review * fix: changes from review * fix: changes from review * fix: changes from review --------- Co-authored-by: Tim Möhlmann <tim+github@zitadel.com> Co-authored-by: Livio Spring <livio.a@gmail.com>
69 lines
2.2 KiB
Go
69 lines
2.2 KiB
Go
package login
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
)
|
|
|
|
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
|
|
}
|
|
_, err = l.command.ChangePassword(setContext(r.Context(), authReq.UserOrgID), authReq.UserOrgID, authReq.UserID, data.OldPassword, data.NewPassword)
|
|
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 *domain.AuthRequest, err error) {
|
|
var errType, errMessage string
|
|
if err != nil {
|
|
errType, errMessage = l.getErrorMessage(r, err)
|
|
}
|
|
translator := l.getTranslator(r.Context(), authReq)
|
|
data := passwordData{
|
|
baseData: l.getBaseData(r, authReq, translator, "PasswordChange.Title", "PasswordChange.Description", errType, errMessage),
|
|
profileData: l.getProfileData(authReq),
|
|
}
|
|
policy := l.getPasswordComplexityPolicy(r, authReq.UserOrgID)
|
|
if policy != nil {
|
|
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, translator, l.renderer.Templates[tmplChangePassword], data, nil)
|
|
}
|
|
|
|
func (l *Login) renderChangePasswordDone(w http.ResponseWriter, r *http.Request, authReq *domain.AuthRequest) {
|
|
translator := l.getTranslator(r.Context(), authReq)
|
|
data := l.getUserData(r, authReq, translator, "PasswordChange.Title", "PasswordChange.Description", "", "")
|
|
l.renderer.RenderTemplate(w, r, translator, l.renderer.Templates[tmplChangePasswordDone], data, nil)
|
|
}
|