func NewInvite(w http.ResponseWriter, req *http.Request) {
	k := handler.GetAPIKey(req)
	if !k.HasPermission(internal.PermGenerateInvites, nil) {
		httputils.ErrorOut(w, http.StatusUnauthorized, "unauthorized")
		return
	}

	var input inputInviteType
	err := httputils.DecodeBody(w, req.Body, &input)
	if err != nil {
		httputils.ErrorOut(w, http.StatusBadRequest, "incorrect body")
		return
	}

	addrHash, err := hash.NewFromHash(input.AddrHash)
	if err != nil {
		httputils.ErrorOut(w, http.StatusBadRequest, "incorrect address")
		return
	}

	validUntil := internal.TimeNow().Add(time.Duration(input.Days) * 24 * time.Hour)
	token, err := signature.NewInviteToken(*addrHash, config.Routing.RoutingID, validUntil, config.Routing.KeyPair.PrivKey)
	if err != nil {
		httputils.ErrorOut(w, http.StatusInternalServerError, "cannot generate invite token")
		return
	}

	_ = httputils.JSONOut(w, http.StatusCreated, jsonOut{
		"hash":   addrHash.String(),
		"token":  token.String(),
		"expiry": validUntil.Unix(),
	})
}
// NewInvite handler will generate a new invite token for a given address
NewInvite handler will generate a new invite token for a given address
// NewInvite handler will generate a new invite token for a given address
func NewInvite(w http.ResponseWriter, req *http.Request) {
	k := handler.GetAPIKey(req)
	if !k.HasPermission(internal.PermGenerateInvites, nil) {
		httputils.ErrorOut(w, http.StatusUnauthorized, "unauthorized")
		return
	}
	var input inputInviteType
	err := httputils.DecodeBody(w, req.Body, &input)
	if err != nil {
		httputils.ErrorOut(w, http.StatusBadRequest, "incorrect body")
		return
	}
	addrHash, err := hash.NewFromHash(input.AddrHash)
	if err != nil {
		httputils.ErrorOut(w, http.StatusBadRequest, "incorrect address")
		return
	}
	validUntil := internal.TimeNow().Add(time.Duration(input.Days) * 24 * time.Hour)
	token, err := signature.NewInviteToken(*addrHash, config.Routing.RoutingID, validUntil, config.Routing.KeyPair.PrivKey)
	if err != nil {
		httputils.ErrorOut(w, http.StatusInternalServerError, "cannot generate invite token")
		return
	}
	_ = httputils.JSONOut(w, http.StatusCreated, jsonOut{
		"hash":   addrHash.String(),
		"token":  token.String(),
		"expiry": validUntil.Unix(),
	})
}
func NewInvite ( w http . ResponseWriter , req * http . Request ) { k := handler . GetAPIKey ( req ) if ! k . HasPermission ( internal . PermGenerateInvites , nil ) { httputils . ErrorOut ( w , http . StatusUnauthorized , " " ) return } var input inputInviteType err := httputils . DecodeBody ( w , req . Body , & input ) if err != nil { httputils . ErrorOut ( w , http . StatusBadRequest , " " ) return } addrHash , err := hash . NewFromHash ( input . AddrHash ) if err != nil { httputils . ErrorOut ( w , http . StatusBadRequest , " " ) return } validUntil := internal . TimeNow ( ) . Add ( time . Duration ( input . Days ) * 24 * time . Hour ) token , err := signature . NewInviteToken ( * addrHash , config . Routing . RoutingID , validUntil , config . Routing . KeyPair . PrivKey ) if err != nil { httputils . ErrorOut ( w , http . StatusInternalServerError , " " ) return } _ = httputils . JSONOut ( w , http . StatusCreated , jsonOut { " " : addrHash . String ( ) , " " : token . String ( ) , " " : validUntil . Unix ( ) , } ) }
NewInvite handler will generate a new invite token for a given address
NewInvite handler will generate a new invite token for a given address