lot of new functionalities
This commit is contained in:
52
servers/web/auth/lost_password.go
Normal file
52
servers/web/auth/lost_password.go
Normal file
@@ -0,0 +1,52 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user