28 lines
636 B
Go
28 lines
636 B
Go
package handlers
|
|
|
|
import (
|
|
"authentication/helper"
|
|
"authentication/services"
|
|
"net/http"
|
|
)
|
|
|
|
func ForgotPassword(w http.ResponseWriter, r *http.Request) {
|
|
|
|
email, err := helper.ExtractEmailFromToken(r.Header.Get("Authorization"))
|
|
if err != nil {
|
|
helper.RespondWithError(w, http.StatusInternalServerError, err.Error())
|
|
return
|
|
}
|
|
|
|
allowed, err := services.ForgotPassword(email)
|
|
if err != nil {
|
|
helper.RespondWithError(w, http.StatusBadGateway, "Failed to process forgot password request")
|
|
return
|
|
}
|
|
|
|
if !allowed {
|
|
helper.RespondWithError(w, http.StatusForbidden, "Password reset not allowed for this email")
|
|
return
|
|
}
|
|
}
|