feat: add /s5/account endpoint

This commit is contained in:
Derrick Hammer 2024-01-17 11:52:54 -05:00
parent 897fec75ad
commit ef872bf344
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 22 additions and 0 deletions

View File

@ -33,5 +33,6 @@ func getRoutes(h *s5.HttpHandler, portal interfaces.Portal) map[string]jape.Hand
"POST /s5/account/register": h.AccountRegister, "POST /s5/account/register": h.AccountRegister,
"GET /s5/account/login": h.AccountLoginChallenge, "GET /s5/account/login": h.AccountLoginChallenge,
"POST /s5/account/login": h.AccountLogin, "POST /s5/account/login": h.AccountLogin,
"GET /s5/account": s5.AuthMiddleware(h.AccountInfo, portal),
} }
} }

View File

@ -518,6 +518,20 @@ func (h *HttpHandler) AccountLogin(jc jape.Context) {
setAuthCookie(jwt, jc) setAuthCookie(jwt, jc)
} }
func (h *HttpHandler) AccountInfo(jc jape.Context) {
_, user := h.portal.Accounts().AccountExists(jc.Request.Context().Value(AuthUserIDKey).(uint64))
info := &AccountInfoResponse{
Email: user.Email,
QuotaExceeded: false,
EmailConfirmed: false,
IsRestricted: false,
Tier: 0,
}
jc.Encode(info)
}
func setAuthCookie(jwt string, jc jape.Context) { func setAuthCookie(jwt string, jc jape.Context) {
authCookie := http.Cookie{ authCookie := http.Cookie{
Name: "s5-auth-token", Name: "s5-auth-token",

View File

@ -22,3 +22,10 @@ type AccountLoginRequest struct {
type AccountLoginChallengeResponse struct { type AccountLoginChallengeResponse struct {
Challenge string `json:"challenge"` Challenge string `json:"challenge"`
} }
type AccountInfoResponse struct {
Email string `json:"email"`
QuotaExceeded bool `json:"quotaExceeded"`
EmailConfirmed bool `json:"emailConfirmed"`
IsRestricted bool `json:"isRestricted"`
Tier uint8 `json:"tier"`
}