func regenerateAPIToken(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	email := r.URL.Query().Get("user")
	if email == "" {
		email = t.GetUserName()
	}
	allowed := permission.Check(t, permission.PermUserUpdateToken,
		permission.Context(permTypes.CtxUser, email),
	)
	if !allowed {
		return permission.ErrUnauthorized
	}
	evt, err := event.New(&event.Opts{
		Target:     userTarget(email),
		Kind:       permission.PermUserUpdateToken,
		Owner:      t,
		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, err := auth.GetUserByEmail(email)
	if err != nil {
		return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
	}
	apiKey, err := u.RegenerateAPIKey()
	if err != nil {
		return err
	}
	w.Header().Add("Content-Type", "application/json")
	return json.NewEncoder(w).Encode(apiKey)
}
func regenerateAPIToken(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	email := r.URL.Query().Get("user")
	if email == "" {
		email = t.GetUserName()
	}
	allowed := permission.Check(t, permission.PermUserUpdateToken,
		permission.Context(permTypes.CtxUser, email),
	)
	if !allowed {
		return permission.ErrUnauthorized
	}
	evt, err := event.New(&event.Opts{
		Target:     userTarget(email),
		Kind:       permission.PermUserUpdateToken,
		Owner:      t,
		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, err := auth.GetUserByEmail(email)
	if err != nil {
		return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
	}
	apiKey, err := u.RegenerateAPIKey()
	if err != nil {
		return err
	}
	w.Header().Add("Content-Type", "application/json")
	return json.NewEncoder(w).Encode(apiKey)
}
func regenerateAPIToken ( w http . ResponseWriter , r * http . Request , t auth . Token ) ( err error ) { email := r . URL . Query ( ) . Get ( " " ) if email == " " { email = t . GetUserName ( ) } allowed := permission . Check ( t , permission . PermUserUpdateToken , permission . Context ( permTypes . CtxUser , email ) , ) if ! allowed { return permission . ErrUnauthorized } evt , err := event . New ( & event . Opts { Target : userTarget ( email ) , Kind : permission . PermUserUpdateToken , Owner : t , 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 , err := auth . GetUserByEmail ( email ) if err != nil { return & errors . HTTP { Code : http . StatusNotFound , Message : err . Error ( ) } } apiKey , err := u . RegenerateAPIKey ( ) if err != nil { return err } w . Header ( ) . Add ( " " , " " ) return json . NewEncoder ( w ) . Encode ( apiKey ) }
// title: regenerate token
// path: /users/api-key
// method: POST
// produce: application/json
// responses:
//   200: OK
//   401: Unauthorized
//   404: User not found
title : regenerate token path : / users / api - key method : POST produce : application / json responses : 200 : OK 401 : Unauthorized 404 : User not found