You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: auth_local.go
    path of file: ./repos/cds/engine/api
    
    the code of the file until where you have to start completion: package api

import (
	"context"
	"net/http"
	"time"

	localdriver "github.com/ovh/cds/engine/api/driver/local"
	"github.com/ovh/cds/engine/api/event_v2"

	"github.com/rockbears/log"

	"github.com/ovh/cds/engine/api/authentication"
	"github.com/ovh/cds/engine/api/authentication/local"
	"github.com/ovh/cds/engine/api/group"
	"github.com/ovh/cds/engine/api/mail"
	"github.com/ovh/cds/engine/api/user"
	"github.com/ovh/cds/engine/gorpmapper"
	"github.com/ovh/cds/engine/service"
	"github.com/ovh/cds/sdk"
)

// postAuthLocalSignupHandler creates a new registration that need to be verified to create a new user.
func (api *API) postAuthLocalSignupHandler() service.Handler {
	return func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
		authDriver, okDriver := api.AuthenticationDrivers[sdk.ConsumerLocal]
		if !okDriver || authDriver.GetManifest().SignupDisabled {
			return sdk.WithStack(sdk.ErrSignupDisabled)
		}

		localDriver := authDriver.GetDriver().(*localdriver.LocalDriver)

		// Extract and validate signup request
		var reqData sdk.AuthConsumerSigninRequest
		if err := service.UnmarshalBody(r, &reqData); err != nil {
			return err
		}
		if err := localDriver.CheckSignupRequest(reqData); err != nil {
			return err
		}

		tx, err := api.mustDB().Begin()
		if err != nil {
			re
    
func (api *API) postAuthLocalAskResetHandler() service.Handler {
	return func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
		authDriver, okDriver := api.AuthenticationDrivers[sdk.ConsumerLocal]
		if !okDriver {
			return sdk.WithStack(sdk.ErrForbidden)
		}

		localDriver := authDriver.GetDriver().(*localdriver.LocalDriver)

		var email string

		// If there is a consumer, send directly to the primary contact for the user.
		consumer := getUserConsumer(ctx)
		if consumer != nil {
			email = consumer.GetEmail()
		} else {
			var reqData sdk.AuthConsumerSigninRequest
			if err := service.UnmarshalBody(r, &reqData); err != nil {
				return err
			}
			if err := localDriver.CheckAskResetRequest(reqData); err != nil {
				return err
			}
			email = reqData.String("email")
		}

		tx, err := api.mustDB().Begin()
		if err != nil {
			return sdk.WithStack(err)
		}
		defer tx.Rollback() // nolint

		contact, err := user.LoadContactByTypeAndValue(ctx, tx, sdk.UserContactTypeEmail, email)
		if err != nil {
			// If there is no contact for given email, return ok to prevent email exploration
			if sdk.ErrorIs(err, sdk.ErrNotFound) {
				log.Warn(ctx, "api.postAuthLocalAskResetHandler> no contact found for email %s: %v", email, err)
				return service.WriteJSON(w, nil, http.StatusOK)
			}
			return err
		}

		existingLocalConsumer, err := authentication.LoadUserConsumerByTypeAndUserID(ctx, tx, sdk.ConsumerLocal, contact.UserID)
		if err != nil && !sdk.ErrorIs(err, sdk.ErrNotFound) {
			return err
		}
		if existingLocalConsumer == nil {
			// If a user exists for given email but has no local consumer we want to create it.
			existingLocalConsumer, err = local.NewConsumer(ctx, tx, contact.UserID)
			if err != nil {
				return err
			}
		}
		if err := authentication.LoadUserConsumerOptions.WithAuthentifiedUser(ctx, tx, existingLocalConsumer); err != nil {
			return err
		}

		resetToken, err := local.NewResetConsumerToken(api.Cache, existingLocalConsumer.ID)
		if err != nil {
			return err
		}

		// Insert the authentication
		if err := mail.SendMailAskResetToken(ctx, contact.Value, existingLocalConsumer.AuthConsumerUser.AuthentifiedUser.Username, resetToken,
			api.Config.URL.UI+"/auth/reset?token=%s",
			api.Config.URL.API,
		); err != nil {
			return sdk.WrapError(err, "cannot send reset token email at %s", contact.Value)
		}

		if err := tx.Commit(); err != nil {
			return sdk.WithStack(err)
		}

		return service.WriteJSON(w, nil, http.StatusOK)
	}
}