Пример #1
0
func (u *User) Create(cx *goblet.Context) {
	rec := new(UserModule)
	if rec.Name != "" && rec.Pwd != "" {
		if _, err := goblet.DB.Insert(rec); err != nil {
			cx.AddRespond("err", err)
			cx.RespondStatus(http.StatusBadRequest)
		} else {
			cx.AddRespond("user", rec)
		}
	}
}
Пример #2
0
func (u *User) New(cx *goblet.Context) {
	if len(u.CreateOnlyByPermits) > 0 {
		var user UserModule
		if id, has := cx.GetLoginId(); has {
			if has, err := goblet.DB.Id(id).Get(&user); err == nil && has {
				for _, permit := range u.CreateOnlyByPermits {
					if _, ok := user.Permits[permit]; ok {
						cx.RespondOK()
					}
				}
			}
		}
	}
	cx.RespondStatus(http.StatusMethodNotAllowed)
}