mirror of
https://github.com/zitadel/zitadel.git
synced 2025-04-27 23:40:51 +00:00

Add functionality to provide http.Request and authError to actions for logging or other logic.
60 lines
1.7 KiB
Go
60 lines
1.7 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))
|
|
|
|
metadata, actionErr := l.runPostInternalAuthenticationActions(authReq, r, authMethodPassword, err)
|
|
if err == nil && actionErr == nil && len(metadata) > 0 {
|
|
_, err = l.command.BulkSetUserMetadata(r.Context(), authReq.UserID, authReq.UserOrgID, metadata...)
|
|
} else if actionErr != nil && err == nil {
|
|
err = actionErr
|
|
}
|
|
|
|
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)
|
|
}
|