feat: add /api/auth/verify-email endpoint

This commit is contained in:
Derrick Hammer 2024-02-26 10:47:47 -05:00
parent e629618f25
commit 057db6a636
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 20 additions and 0 deletions

View File

@ -134,6 +134,21 @@ func (a AccountAPI) register(jc jape.Context) {
}
}
func (a AccountAPI) verifyEmail(jc jape.Context) {
var request VerifyEmailRequest
if jc.Decode(&request) != nil {
return
}
err := a.accounts.VerifyEmail(request.Email, request.Token)
if jc.Check("failed to verify email", err) != nil {
return
}
}
func (a AccountAPI) otpGenerate(jc jape.Context) {
user := middleware.GetUserFromContext(jc.Request.Context())
@ -220,6 +235,7 @@ func (a AccountAPI) Routes() (*httprouter.Router, error) {
return jape.Mux(map[string]jape.Handler{
"POST /api/auth/login": middleware.ApplyMiddlewares(a.login, authMw2fa, middleware.ProxyMiddleware),
"POST /api/auth/register": middleware.ApplyMiddlewares(a.register, middleware.ProxyMiddleware),
"POST /api/auth/verify-email": middleware.ApplyMiddlewares(a.verifyEmail, middleware.ProxyMiddleware),
"GET /api/auth/otp/generate": middleware.ApplyMiddlewares(a.otpGenerate, authMw, middleware.ProxyMiddleware),
"POST /api/auth/otp/verify": middleware.ApplyMiddlewares(a.otpVerify, authMw, middleware.ProxyMiddleware),
"POST /api/auth/otp/validate": middleware.ApplyMiddlewares(a.otpValidate, authMw, middleware.ProxyMiddleware),

View File

@ -26,3 +26,7 @@ type OTPValidateRequest struct {
type OTPDisableRequest struct {
Password string `json:"password"`
}
type VerifyEmailRequest struct {
Email string `json:"email"`
Token string `json:"token"`
}