示例#1
0
文件: user.go 项目: jango2015/wk
// get: /user/exists/sheldon
func (uc *UserController) Exists(ctx *wk.HttpContext) (result wk.HttpResult, err error) {
	valid := true
	if name := ctx.FV("name"); name != "" {
		valid = !userRepo.Exists(name)
	}
	return wk.Data(valid), nil
}
示例#2
0
文件: qr.go 项目: jango2015/wk
func showQrCode(ctx *wk.HttpContext) (result wk.HttpResult, err error) {
	text := ctx.FV("text")
	if text == "" {
		err = errors.New("text is invalid")
	} else {
		result = &QrCodeResult{
			Text: text,
		}
	}
	return
}
示例#3
0
文件: user.go 项目: jango2015/wk
// post: /user/edit/1
func (uc *UserController) EditPost(ctx *wk.HttpContext) (result wk.HttpResult, err error) {
	var id int
	if id, err = parseId(ctx); err != nil {
		return
	}

	u := User{
		Id:       id,
		Location: ctx.FV("location"),
		Gender:   ctx.FV("gender"),
		Skills:   ctx.Request.Form["skill"],
	}
	if userRepo.Update(u) {
		return wk.Redirect(fmt.Sprintf("/user/view/%d", id), false), nil
	}
	return wk.View("user/edit.html"), nil
}
示例#4
0
文件: user.go 项目: jango2015/wk
// get/post: /user/add
func (uc *UserController) AddPost(ctx *wk.HttpContext) (result wk.HttpResult, err error) {
	id := 0
	if name := ctx.FV("name"); name == "" {
		ctx.ViewData["errmsg"] = "name is required"
	} else if name == "error" {
		ctx.ViewData["errmsg"] = "name is error"
	} else if userRepo.Exists(name) {
		ctx.ViewData["errmsg"] = "name exists"
	} else {
		u := User{
			Name:     ctx.FV("name"),
			Location: ctx.FV("location"),
			Gender:   ctx.FV("gender"),
			Skills:   ctx.Request.Form["skill"],
		}
		id = userRepo.Add(u)
	}

	if id <= 0 {
		ctx.ViewData["ctx"] = ctx
		return wk.View("user/add.html"), nil
	}
	return wk.Redirect(fmt.Sprintf("/user/view/%d", id), false), nil
}
示例#5
0
文件: session.go 项目: jango2015/wk
// url: /session/remove?k=test
func (c *Session) Remove(ctx *wk.HttpContext) (wk.HttpResult, error) {
	err := ctx.Session.Remove(ctx.FV("k"))
	return wk.Data(err == nil), err
}
示例#6
0
文件: session.go 项目: jango2015/wk
// url: /session/get?k=test
func (c *Session) Get(ctx *wk.HttpContext) (result wk.HttpResult, err error) {
	v, _, err := ctx.Session.Get(ctx.FV("k"))
	return wk.Data(v), err
}
示例#7
0
文件: session.go 项目: jango2015/wk
// url: /session/add?k=test&v=101
func (c *Session) Add(ctx *wk.HttpContext) (wk.HttpResult, error) {
	ok, err := ctx.Session.Add(ctx.FV("k"), ctx.FV("v"))
	return wk.Data(ok), err
}