generated from datumforge/go-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
forgotpass.go
46 lines (37 loc) · 1.28 KB
/
forgotpass.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package route
import (
"net/http"
echo "github.com/datumforge/echox"
"github.com/datumforge/datum/internal/httpserve/handlers"
)
// ForgotPassword is a service for users to request a password reset email. The email
// address must be provided in the POST request and the user must exist in the
// database. This endpoint always returns 204 regardless of whether the user exists or
// not to avoid leaking information about users in the database.
func registerForgotPasswordHandler(router *echo.Echo, h *handlers.Handler) (err error) {
_, err = router.AddRoute(echo.Route{
Name: "ForgotPassword",
Method: http.MethodPost,
Path: "/forgot-password",
Handler: func(c echo.Context) error {
return h.ForgotPassword(c)
},
}.ForGroup(V1Version, restrictedEndpointsMW))
if err != nil {
return err
}
// we need to handle the redirect from /.well-known 302 -> /v1/forgot-password with a 200
_, err = router.AddRoute(echo.Route{
Name: "ForgotPasswordRedirect",
Method: http.MethodGet,
Path: "/forgot-password",
Handler: func(c echo.Context) error {
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
return c.JSON(http.StatusOK, "OK")
},
}.ForGroup(V1Version, restrictedEndpointsMW))
if err != nil {
return err
}
return
}