mirror of
https://github.com/1f349/lavender.git
synced 2025-04-12 22:15:55 +01:00
Process post-form authentication checks
This commit is contained in:
parent
f345b9a4d0
commit
cb0387a925
@ -180,12 +180,47 @@ func (h *httpServer) loginPost(rw http.ResponseWriter, req *http.Request, _ http
|
||||
|
||||
// TODO: idk why login process data isn't working properly
|
||||
processData = formContext.GetLoginProcessData()
|
||||
if h.setLoginProcessCookie(rw, processData) {
|
||||
return
|
||||
|
||||
// if the state is basic and the user has no OTP secret or OTP digits then skip OTP
|
||||
if processData.State == process.StateBasic {
|
||||
var user *database.User
|
||||
if processData.Subject != "" {
|
||||
userRaw, err := h.db.GetUser(req.Context(), processData.Subject)
|
||||
if err == nil {
|
||||
user = &userRaw
|
||||
}
|
||||
}
|
||||
if user != nil && user.OtpSecret == "" && user.OtpDigits == 0 {
|
||||
processData.State = process.StateAuthenticated
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: figure this out
|
||||
logger.Logger.Debug("POST /login: form render data: ", formContext.Data())
|
||||
switch processData.State {
|
||||
case process.StateAuthenticated:
|
||||
// set the access and refresh tokens
|
||||
if h.setLoginDataCookie(rw, auth.UserAuth{
|
||||
Subject: processData.Subject,
|
||||
Factor: processData.State,
|
||||
UserInfo: auth.UserInfoFields{},
|
||||
}, processData.Email) {
|
||||
return
|
||||
}
|
||||
|
||||
case process.StateSudo:
|
||||
// sudo is not implemented yet
|
||||
logger.Logger.Error("Hit StateSudo")
|
||||
http.Error(rw, "This should not be possible yet", http.StatusNotImplemented)
|
||||
return
|
||||
|
||||
default:
|
||||
// update the process state
|
||||
if h.setLoginProcessCookie(rw, processData) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: figure this out (not sure what?)
|
||||
logger.Logger.Debug("POST /login: form render data", "data", formContext.Data())
|
||||
http.Redirect(rw, req, h.conf.BaseUrl.JoinPath("login").String(), http.StatusFound)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user