示例#1
0
文件: user.go 项目: extrame/goblet
func (u *User) UpdateMany(cx *goblet.Context) {
	rec := new(UserModule)
	cx.Fill(rec)
	var err error
	if rec.Name != "" && rec.Pwd != "" {
		var has bool
		if has, err = goblet.DB.Where("name = ? and pwd = ?", rec.Name, rec.Pwd).Get(rec); err == nil && has {
			cx.AddLoginId(rec.Id)
			cx.RespondOK()
		} else {
			cx.RespondWithStatus("用户名或密码错误", http.StatusForbidden)
		}
	} else {
		cx.RespondWithStatus("用户名或密码为空", http.StatusForbidden)
	}

}
示例#2
0
文件: user.go 项目: extrame/goblet
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)
		}
	}
}
示例#3
0
文件: user.go 项目: extrame/goblet
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)
}