mirror of
https://github.com/zitadel/zitadel.git
synced 2025-04-23 19:01:31 +00:00

* fix: import user, and label policy command side * feat: Import user and hide loginname suffix (#1464) * fix: import user * fix: label policy * fix: label policy * fix: label policy * fix: migrations * fix: migrations * fix: migrations * fix: label policy * loginSuffix in login ui * suffix * fix cursor on disabled user selection Co-authored-by: Livio Amstutz <livio.a@gmail.com> (cherry picked from commit 03ddb8fc388494d6ec99b1db9e16d16c28ee9649) * feat: Import user and hide loginname suffix (#1464) * fix: import user * fix: label policy * fix: label policy * fix: label policy * fix: migrations * fix: migrations * fix: migrations * fix: label policy * loginSuffix in login ui * suffix * fix cursor on disabled user selection Co-authored-by: Livio Amstutz <livio.a@gmail.com> (cherry picked from commit 03ddb8fc388494d6ec99b1db9e16d16c28ee9649) * feat: Import user and hide loginname suffix (#1464) * fix: import user * fix: label policy * fix: label policy * fix: label policy * fix: migrations * fix: migrations * fix: migrations * fix: label policy * loginSuffix in login ui * suffix * fix cursor on disabled user selection Co-authored-by: Livio Amstutz <livio.a@gmail.com> (cherry picked from commit 03ddb8fc388494d6ec99b1db9e16d16c28ee9649) * fix: label policy events * loginname placeholder * fix: tests * fix: tests * Update internal/command/iam_policy_label_model.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: Livio Amstutz <livio.a@gmail.com>
82 lines
2.2 KiB
Go
82 lines
2.2 KiB
Go
package handler
|
|
|
|
import (
|
|
"github.com/caos/zitadel/internal/domain"
|
|
"net/http"
|
|
|
|
http_mw "github.com/caos/zitadel/internal/api/http/middleware"
|
|
)
|
|
|
|
const (
|
|
tmplLogin = "login"
|
|
)
|
|
|
|
type loginData struct {
|
|
LoginName string `schema:"loginName"`
|
|
Register bool `schema:"register"`
|
|
}
|
|
|
|
func (l *Login) handleLogin(w http.ResponseWriter, r *http.Request) {
|
|
authReq, err := l.getAuthRequest(r)
|
|
if err != nil {
|
|
l.renderError(w, r, authReq, err)
|
|
return
|
|
}
|
|
if authReq == nil {
|
|
http.Redirect(w, r, l.zitadelURL, http.StatusFound)
|
|
return
|
|
}
|
|
l.renderNextStep(w, r, authReq)
|
|
}
|
|
|
|
func (l *Login) handleLoginName(w http.ResponseWriter, r *http.Request) {
|
|
authReq, err := l.getAuthRequest(r)
|
|
if err != nil {
|
|
l.renderError(w, r, authReq, err)
|
|
return
|
|
}
|
|
l.renderLogin(w, r, authReq, nil)
|
|
}
|
|
|
|
func (l *Login) handleLoginNameCheck(w http.ResponseWriter, r *http.Request) {
|
|
data := new(loginData)
|
|
authReq, err := l.getAuthRequestAndParseData(r, data)
|
|
if err != nil {
|
|
l.renderError(w, r, authReq, err)
|
|
return
|
|
}
|
|
if data.Register {
|
|
if authReq.LoginPolicy != nil && authReq.LoginPolicy.AllowExternalIDP && authReq.AllowedExternalIDPs != nil && len(authReq.AllowedExternalIDPs) > 0 {
|
|
l.handleRegisterOption(w, r)
|
|
return
|
|
}
|
|
l.handleRegister(w, r)
|
|
return
|
|
}
|
|
userAgentID, _ := http_mw.UserAgentIDFromCtx(r.Context())
|
|
loginName := data.LoginName
|
|
err = l.authRepo.CheckLoginName(r.Context(), authReq.ID, loginName, userAgentID)
|
|
if err != nil {
|
|
l.renderLogin(w, r, authReq, err)
|
|
return
|
|
}
|
|
l.renderNextStep(w, r, authReq)
|
|
}
|
|
|
|
func (l *Login) renderLogin(w http.ResponseWriter, r *http.Request, authReq *domain.AuthRequest, err error) {
|
|
var errType, errMessage string
|
|
if err != nil {
|
|
errMessage = l.getErrorMessage(r, err)
|
|
}
|
|
data := l.getUserData(r, authReq, "Login", errType, errMessage)
|
|
funcs := map[string]interface{}{
|
|
"hasUsernamePasswordLogin": func() bool {
|
|
return authReq.LoginPolicy != nil && authReq.LoginPolicy.AllowUsernamePassword
|
|
},
|
|
"hasExternalLogin": func() bool {
|
|
return authReq.LoginPolicy != nil && authReq.LoginPolicy.AllowExternalIDP && authReq.AllowedExternalIDPs != nil && len(authReq.AllowedExternalIDPs) > 0
|
|
},
|
|
}
|
|
l.renderer.RenderTemplate(w, r, l.renderer.Templates[tmplLogin], data, funcs)
|
|
}
|