feat: add /s5/account endpoint
This commit is contained in:
parent
897fec75ad
commit
ef872bf344
|
@ -33,5 +33,6 @@ func getRoutes(h *s5.HttpHandler, portal interfaces.Portal) map[string]jape.Hand
|
|||
"POST /s5/account/register": h.AccountRegister,
|
||||
"GET /s5/account/login": h.AccountLoginChallenge,
|
||||
"POST /s5/account/login": h.AccountLogin,
|
||||
"GET /s5/account": s5.AuthMiddleware(h.AccountInfo, portal),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -518,6 +518,20 @@ func (h *HttpHandler) AccountLogin(jc jape.Context) {
|
|||
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) {
|
||||
authCookie := http.Cookie{
|
||||
Name: "s5-auth-token",
|
||||
|
|
|
@ -22,3 +22,10 @@ type AccountLoginRequest struct {
|
|||
type AccountLoginChallengeResponse struct {
|
||||
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"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue