mirror of
https://github.com/zitadel/zitadel.git
synced 2025-04-23 05:21:32 +00:00

* begin init checks for projections * first projection checks * debug notification providers with query fixes * more projections and first index * more projections * more projections * finish projections * fix tests (remove db name) * create tables in setup * fix logging / error handling * add tenant to views * rename tenant to instance_id * add instance_id to all projections * add instance_id to all queries * correct instance_id on projections * add instance_id to failed_events * use separate context for instance * implement features projection * implement features projection * remove unique constraint from setup when migration failed * add error to failed setup event * add instance_id to primary keys * fix IAM projection * remove old migrations folder * fix keysFromYAML test
89 lines
2.5 KiB
Go
89 lines
2.5 KiB
Go
package login
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/caos/zitadel/internal/api/authz"
|
|
http_mw "github.com/caos/zitadel/internal/api/http/middleware"
|
|
"github.com/caos/zitadel/internal/domain"
|
|
"github.com/caos/zitadel/internal/errors"
|
|
)
|
|
|
|
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.consolePath, 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.renderLogin(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
|
|
}
|
|
if authReq == nil {
|
|
l.renderLogin(w, r, nil, errors.ThrowInvalidArgument(nil, "LOGIN-adrg3", "Errors.AuthRequest.NotFound"))
|
|
return
|
|
}
|
|
userAgentID, _ := http_mw.UserAgentIDFromCtx(r.Context())
|
|
instanceID := authz.GetInstance(r.Context()).ID
|
|
loginName := data.LoginName
|
|
err = l.authRepo.CheckLoginName(r.Context(), authReq.ID, loginName, userAgentID, instanceID)
|
|
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 errID, errMessage string
|
|
if err != nil {
|
|
errID, errMessage = l.getErrorMessage(r, err)
|
|
}
|
|
data := l.getUserData(r, authReq, "Login", errID, 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.getTranslator(authReq), l.renderer.Templates[tmplLogin], data, funcs)
|
|
}
|