func createUser(w http.ResponseWriter, r *http.Request) error {
	registrationEnabled, _ := config.GetBool("auth:user-registration")
	if !registrationEnabled {
		token := r.Header.Get("Authorization")
		t, err := app.AuthScheme.Auth(token)
		if err != nil {
			return createDisabledErr
		}
		if !permission.Check(t, permission.PermUserCreate) {
			return createDisabledErr
		}
	}
	email := InputValue(r, "email")
	password := InputValue(r, "password")
	evt, err := event.New(&event.Opts{
		Target:     userTarget(email),
		Kind:       permission.PermUserCreate,
		RawOwner:   event.Owner{Type: event.OwnerTypeUser, Name: email},
		CustomData: event.FormToCustomData(InputFields(r, "password")),
		Allowed:    event.Allowed(permission.PermUserReadEvents, permission.Context(permTypes.CtxUser, email)),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	u := auth.User{
		Email:    email,
		Password: password,
	}
	_, err = app.AuthScheme.Create(&u)
	if err != nil {
		return handleAuthError(err)
	}
	w.WriteHeader(http.StatusCreated)
	return nil
}
func createUser(w http.ResponseWriter, r *http.Request) error {
	registrationEnabled, _ := config.GetBool("auth:user-registration")
	if !registrationEnabled {
		token := r.Header.Get("Authorization")
		t, err := app.AuthScheme.Auth(token)
		if err != nil {
			return createDisabledErr
		}
		if !permission.Check(t, permission.PermUserCreate) {
			return createDisabledErr
		}
	}
	email := InputValue(r, "email")
	password := InputValue(r, "password")
	evt, err := event.New(&event.Opts{
		Target:     userTarget(email),
		Kind:       permission.PermUserCreate,
		RawOwner:   event.Owner{Type: event.OwnerTypeUser, Name: email},
		CustomData: event.FormToCustomData(InputFields(r, "password")),
		Allowed:    event.Allowed(permission.PermUserReadEvents, permission.Context(permTypes.CtxUser, email)),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	u := auth.User{
		Email:    email,
		Password: password,
	}
	_, err = app.AuthScheme.Create(&u)
	if err != nil {
		return handleAuthError(err)
	}
	w.WriteHeader(http.StatusCreated)
	return nil
}
func createUser ( w http . ResponseWriter , r * http . Request ) error { registrationEnabled , _ := config . GetBool ( " " ) if ! registrationEnabled { token := r . Header . Get ( " " ) t , err := app . AuthScheme . Auth ( token ) if err != nil { return createDisabledErr } if ! permission . Check ( t , permission . PermUserCreate ) { return createDisabledErr } } email := InputValue ( r , " " ) password := InputValue ( r , " " ) evt , err := event . New ( & event . Opts { Target : userTarget ( email ) , Kind : permission . PermUserCreate , RawOwner : event . Owner { Type : event . OwnerTypeUser , Name : email } , CustomData : event . FormToCustomData ( InputFields ( r , " " ) ) , Allowed : event . Allowed ( permission . PermUserReadEvents , permission . Context ( permTypes . CtxUser , email ) ) , } ) if err != nil { return err } defer func ( ) { evt . Done ( err ) } ( ) u := auth . User { Email : email , Password : password , } _ , err = app . AuthScheme . Create ( & u ) if err != nil { return handleAuthError ( err ) } w . WriteHeader ( http . StatusCreated ) return nil }
// title: user create
// path: /users
// method: POST
// consume: application/x-www-form-urlencoded
// responses:
//   201: User created
//   400: Invalid data
//   401: Unauthorized
//   403: Forbidden
//   409: User already exists
title : user create path : / users method : POST consume : application / x - www - form - urlencoded responses : 201 : User created 400 : Invalid data 401 : Unauthorized 403 : Forbidden 409 : User already exists