64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"git.thequux.com/thequux/ipasso/util/startup"
|
|
"github.com/julienschmidt/httprouter"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
func init() {
|
|
startup.Routes.Add(func(router *httprouter.Router) {
|
|
router.Handler("GET", "/login/info", LoginStateMw(http.HandlerFunc(stateServlet)))
|
|
})
|
|
}
|
|
|
|
type LoginState string
|
|
|
|
var (
|
|
LS_Valid LoginState = "VALID"
|
|
LS_LoggedOut LoginState = "EXPLICIT_LOGOUT"
|
|
LS_Unknown LoginState = "UNKNOWN"
|
|
LS_Invalid LoginState = "INVALID"
|
|
)
|
|
|
|
type PublicLoginState struct {
|
|
State LoginState `json:"login_state"`
|
|
Expiration *time.Time `json:"expiration,omitempty"`
|
|
UserId string `json:"uid,omitempty"`
|
|
LdapDn string `json:"ldap_dn,omitempty"`
|
|
|
|
Groups []string `json:"groups,omitempty"`
|
|
DisplayName string `json:"display_name,omitempty"`
|
|
GivenName string `json:"given_name,omitempty"`
|
|
FamilyName string `json:"family_name,omitempty"`
|
|
Email string `json:"email,omitempty"`
|
|
}
|
|
|
|
func GetPublicState(s *Session) PublicLoginState {
|
|
ret := PublicLoginState{
|
|
State: s.State,
|
|
}
|
|
if s.Session != nil {
|
|
ret.Expiration = &s.Session.Expiration
|
|
ret.UserId = s.Session.UserID
|
|
ret.LdapDn = s.Session.LdapDN
|
|
}
|
|
|
|
if s.Cache != nil {
|
|
ret.Groups = s.Cache.Groups
|
|
ret.DisplayName = s.Cache.DisplayName
|
|
ret.GivenName = s.Cache.GivenName
|
|
ret.FamilyName = s.Cache.FamilyName
|
|
ret.Email = s.Cache.Email
|
|
}
|
|
|
|
return ret
|
|
}
|
|
|
|
func stateServlet(w http.ResponseWriter, req *http.Request) {
|
|
session := GetSession(req.Context(), true)
|
|
data := GetPublicState(session)
|
|
RenderPage(w, req, "status", data)
|
|
}
|