// ResendVerification attempts to send and generate the verification token
// once more.
// On successful execution, either account activation or new email verification
// will be sent.
ResendVerification attempts to send and generate the verification token
once more.
On successful execution, either account activation or new email verification
will be sent.
// ResendVerification attempts to send and generate the verification token // once more . // On successful execution either account activation or new email verification // will be sent .
func (h *Handler) ResendVerification(w http.ResponseWriter, r *http.Request) {
	ctx := r.Context()
	_, id, err := httpflow.ExtractSession(ctx)
	if err != nil {
		httpflow.RespondError(h.log, w, r, err)
		return
	}
	usr, err := h.db.FetchUserByID(ctx, id)
	if err != nil {
		httpflow.RespondError(h.log, w, r, err)
		return
	}
	usrC := usr.ExposeCore()
	if usrC.Verification.IsEmpty() {
		err = httpflow.NewError(nil, http.StatusBadRequest, "verification has not been initiated")
		httpflow.RespondError(h.log, w, r, err)
		return
	}
	tok, err := usrC.InitVerification(h.token.verif)
	if err != nil {
		if errors.Is(err, ErrTooManyTokens) {
			secs := int(time.Until(usrC.Verification.NextAt.Time).Seconds())
			w.Header().Add("Retry-After", strconv.Itoa(secs))
		}
		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
	}
	if usrC.IsActivated() {
		go h.email.SendEmailVerification(ctx, usrC.UnverifiedEmail.String, tok)
	} else {
		go h.email.SendAccountActivation(ctx, usrC.Email, tok)
	}
	httpflow.Respond(h.log, w, r, nil, http.StatusAccepted)
}
func ( h * Handler ) ResendVerification ( w http . ResponseWriter , r * http . Request ) { ctx := r . Context ( ) _ , id , err := httpflow . ExtractSession ( ctx ) if err != nil { httpflow . RespondError ( h . log , w , r , err ) return } usr , err := h . db . FetchUserByID ( ctx , id ) if err != nil { httpflow . RespondError ( h . log , w , r , err ) return } usrC := usr . ExposeCore ( ) if usrC . Verification . IsEmpty ( ) { err = httpflow . NewError ( nil , http . StatusBadRequest , " " ) httpflow . RespondError ( h . log , w , r , err ) return } tok , err := usrC . InitVerification ( h . token . verif ) if err != nil { if errors . Is ( err , ErrTooManyTokens ) { secs := int ( time . Until ( usrC . Verification . NextAt . Time ) . Seconds ( ) ) w . Header ( ) . Add ( " " , strconv . Itoa ( secs ) ) } 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 } if usrC . IsActivated ( ) { go h . email . SendEmailVerification ( ctx , usrC . UnverifiedEmail . String , tok ) } else { go h . email . SendAccountActivation ( ctx , usrC . Email , tok ) } httpflow . Respond ( h . log , w , r , nil , http . StatusAccepted ) }
ResendVerification attempts to send and generate the verification token
once more.
ResendVerification attempts to send and generate the verification token once more .