// Recover checks the token in the URL and applies the provided password
// to the user account data structure.
// On successful execution, an email will be sent notifying about password
// change.
Recover checks the token in the URL and applies the provided password
to the user account data structure.
On successful execution, an email will be sent notifying about password
change.
// Recover checks the token in the URL and applies the provided password // to the user account data structure . // On successful execution an email will be sent notifying about password // change .
func (h *Handler) Recover(w http.ResponseWriter, r *http.Request) {
	usr, tok, err := h.FetchByToken(r)
	if err != nil {
		httpflow.RespondError(h.log, w, r, err)
		return
	}
	var cInp CoreInput
	if err = httpflow.DecodeJSON(r, &cInp); err != nil {
		httpflow.RespondError(h.log, w, r, err)
		return
	}
	ctx := r.Context()
	usrC := usr.ExposeCore()
	if err = usrC.Recover(tok, cInp.Password); err != nil {
		httpflow.RespondError(h.log, w, r, err)
		return
	}
	err = h.session.manager.RevokeByUserKey(ctx, usrC.ID.String())
	if err != nil {
		httpflow.RespondError(h.log, w, r, err)
		return
	}
	if err = h.db.UpdateUser(ctx, usr); err != nil {
		httpflow.RespondError(h.log, w, r, err)
		return
	}
	go h.email.SendPasswordChanged(ctx, usrC.Email, true)
	httpflow.Respond(h.log, w, r, nil, http.StatusNoContent)
}
func ( h * Handler ) Recover ( w http . ResponseWriter , r * http . Request ) { usr , tok , err := h . FetchByToken ( r ) if err != nil { httpflow . RespondError ( h . log , w , r , err ) return } var cInp CoreInput if err = httpflow . DecodeJSON ( r , & cInp ) ; err != nil { httpflow . RespondError ( h . log , w , r , err ) return } ctx := r . Context ( ) usrC := usr . ExposeCore ( ) if err = usrC . Recover ( tok , cInp . Password ) ; err != nil { httpflow . RespondError ( h . log , w , r , err ) return } err = h . session . manager . RevokeByUserKey ( ctx , usrC . ID . String ( ) ) if err != nil { httpflow . RespondError ( h . log , w , r , err ) return } if err = h . db . UpdateUser ( ctx , usr ) ; err != nil { httpflow . RespondError ( h . log , w , r , err ) return } go h . email . SendPasswordChanged ( ctx , usrC . Email , true ) httpflow . Respond ( h . log , w , r , nil , http . StatusNoContent ) }
Recover checks the token in the URL and applies the provided password
to the user account data structure.
Recover checks the token in the URL and applies the provided password to the user account data structure .