func createUser(w http.ResponseWriter, r *http.Request) error { var u auth.User err := json.NewDecoder(r.Body).Decode(&u) if err != nil { return &errors.HTTP{Code: http.StatusBadRequest, Message: err.Error()} } if !validation.ValidateEmail(u.Email) { return &errors.HTTP{Code: http.StatusBadRequest, Message: emailError} } if !validation.ValidateLength(u.Password, passwordMinLen, passwordMaxLen) { return &errors.HTTP{Code: http.StatusBadRequest, Message: passwordError} } gURL := repository.ServerURL() c := gandalf.Client{Endpoint: gURL} if _, err := c.NewUser(u.Email, keyToMap(u.Keys)); err != nil { return fmt.Errorf("Failed to create user in the git server: %s", err) } if err := u.Create(); err == nil { rec.Log(u.Email, "create-user") if limit, err := config.GetUint("quota:apps-per-user"); err == nil { quota.Create(u.Email, uint(limit)) } w.WriteHeader(http.StatusCreated) return nil } if _, err = auth.GetUserByEmail(u.Email); err == nil { err = &errors.HTTP{Code: http.StatusConflict, Message: "This email is already registered"} } return err }
MinParams: 2, } var createAppQuota = action.Action{ Name: "create-app-quota", Forward: func(ctx action.FWContext) (action.Result, error) { var app App switch ctx.Params[0].(type) { case App: app = ctx.Params[0].(App) case *App: app = *ctx.Params[0].(*App) default: return nil, errors.New("First parameter must be App or *App.") } if limit, err := config.GetUint("quota:units-per-app"); err == nil { if limit == 0 { return nil, errors.New("app creation is disallowed") } quota.Create(app.Name, uint(limit)) quota.Reserve(app.Name, app.Name+"-0") } return app.Name, nil }, Backward: func(ctx action.BWContext) { quota.Delete(ctx.FWResult.(string)) }, MinParams: 1, } // insertApp is an action that inserts an app in the database in Forward and