52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package auth
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func (h *Handler) LostPasswordInit(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method == "POST" {
|
|
r.ParseForm()
|
|
email := r.FormValue("email")
|
|
if email != "" {
|
|
_, err := h.applicationHandler.InitiateLostPassword(email)
|
|
if err != nil {
|
|
log.Error().Err(err).Msg("Failed to initiate password reset")
|
|
http.Redirect(w, r, "/app/", http.StatusFound)
|
|
return
|
|
}
|
|
|
|
http.Redirect(w, r, "/app/", http.StatusFound)
|
|
}
|
|
}
|
|
h.renderer.LostPasswordInit(w, r)
|
|
}
|
|
|
|
func (h *Handler) LostPasswordRecover(w http.ResponseWriter, r *http.Request) {
|
|
r.ParseForm()
|
|
|
|
key := r.FormValue("key")
|
|
recover, err := h.applicationHandler.GetPasswordRecoveryData(key)
|
|
if err != nil {
|
|
log.Error().Err(err).Msg("Failed to get password recovery data")
|
|
h.renderer.LostPasswordRecoverKO(w, r, key)
|
|
return
|
|
}
|
|
|
|
if r.Method == "POST" {
|
|
newpassword := r.FormValue("password")
|
|
_, err := h.applicationHandler.RecoverLostPassword(key, newpassword)
|
|
if err != nil {
|
|
log.Error().Err(err).Msg("Failed to recover password")
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
http.Redirect(w, r, "/app/", http.StatusFound)
|
|
return
|
|
}
|
|
|
|
h.renderer.LostPasswordRecover(w, r, recover)
|
|
} |