// Register handles new user's creation and insertion into the data store.
// On successful execution, a session will be created and account activation
// email will sent.
Register handles new user's creation and insertion into the data store.
On successful execution, a session will be created and account activation
email will sent.
// Register handles new user ' s creation and insertion into the data store . // On successful execution a session will be created and account activation // email will sent .
func (h *Handler) Register(w http.ResponseWriter, r *http.Request) {
	inp, err := h.ext.parse(r)
	if err != nil {
		httpflow.RespondError(h.log, w, r, err)
		return
	}
	ctx := r.Context()
	usr, err := h.ext.create(ctx, inp)
	if err != nil {
		httpflow.RespondError(h.log, w, r, err)
		return
	}
	usrC := usr.ExposeCore()
	tok, err := usrC.InitVerification(h.token.verif)
	if err != nil {
		httpflow.RespondError(h.log, w, r, err)
		return
	}
	if err = h.db.CreateUser(ctx, usr); err != nil {
		httpflow.RespondError(h.log, w, r, err)
		return
	}
	sm := h.session.manager
	if inp.ExposeCore().RememberMe {
		sm = sm.Clone(sessionup.ExpiresIn(h.session.duration))
	}
	if err = sm.Init(w, r, usrC.ID.String()); err != nil {
		httpflow.RespondError(h.log, w, r, err)
		return
	}
	go h.email.SendAccountActivation(ctx, usrC.Email, tok)
	w.Header().Add("Location", "/") 
	httpflow.Respond(h.log, w, r, usr, http.StatusCreated)
}
func ( h * Handler ) Register ( w http . ResponseWriter , r * http . Request ) { inp , err := h . ext . parse ( r ) if err != nil { httpflow . RespondError ( h . log , w , r , err ) return } ctx := r . Context ( ) usr , err := h . ext . create ( ctx , inp ) if err != nil { httpflow . RespondError ( h . log , w , r , err ) return } usrC := usr . ExposeCore ( ) tok , err := usrC . InitVerification ( h . token . verif ) if err != nil { httpflow . RespondError ( h . log , w , r , err ) return } if err = h . db . CreateUser ( ctx , usr ) ; err != nil { httpflow . RespondError ( h . log , w , r , err ) return } sm := h . session . manager if inp . ExposeCore ( ) . RememberMe { sm = sm . Clone ( sessionup . ExpiresIn ( h . session . duration ) ) } if err = sm . Init ( w , r , usrC . ID . String ( ) ) ; err != nil { httpflow . RespondError ( h . log , w , r , err ) return } go h . email . SendAccountActivation ( ctx , usrC . Email , tok ) w . Header ( ) . Add ( " " , " " ) httpflow . Respond ( h . log , w , r , usr , http . StatusCreated ) }
Register handles new user's creation and insertion into the data store.
Register handles new user ' s creation and insertion into the data store .
// id will be retrieved from the session