Пример #1
0
func (this *AccountController) AddCourseHour() {
	beego.Informational("login json: ", string(this.Ctx.Input.RequestBody), "ip:", this.Ctx.Input.IP())
	type ach struct {
		Uname      string `json:"studentusername"`
		Coursehour int    `json:"coursehour"`
	}
	var ac ach
	err := json.Unmarshal(this.Ctx.Input.RequestBody, &ac)
	if err != nil {
		beego.Error("err:", err.Error())
		ErrMap["msg"] = err.Error()
		re, _ := json.Marshal(ErrMap)
		this.Ctx.Output.Body(re)
		return
	}
	user, err := models.GetUserByUserName(ac.Uname)
	if err != nil {
		beego.Error("err:", err.Error())
		ErrMap["msg"] = err.Error()
		re, _ := json.Marshal(ErrMap)
		this.Ctx.Output.Body(re)
		return
	}
	err = models.UpdateUserCourseHour(user.Id, ac.Coursehour)
	if err != nil {
		beego.Error("err:", err.Error())
		ErrMap["msg"] = err.Error()
		re, _ := json.Marshal(ErrMap)
		this.Ctx.Output.Body(re)
		return
	}
	this.Ctx.Output.Body([]byte(`{"result":"ok"}`))
}
Пример #2
0
func (this *LoginController) Post() {
	beego.Informational("login json: ", string(this.Ctx.Input.RequestBody), "ip", this.Ctx.Input.IP())
	var uandp models.User
	err := json.Unmarshal(this.Ctx.Input.RequestBody, &uandp)
	if err != nil {
		beego.Error("err:", err.Error())
		ErrMap["msg"] = err.Error()
		re, _ := json.Marshal(ErrMap)
		this.Ctx.Output.Body(re)
		return
	}
	user, err := models.GetUserByUserName(uandp.Username)
	if err != nil {
		beego.Error("err:", err.Error())
		ErrMap["msg"] = "用户名或密码错误"
		re, _ := json.Marshal(ErrMap)
		this.Ctx.Output.Body(re)
		return
	}
	if user.Password != uandp.Password {
		ErrMap["msg"] = "用户名或密码错误"
		re, _ := json.Marshal(ErrMap)
		this.Ctx.Output.Body(re)
		return
	}
	user.Result = "ok"
	re, err := json.Marshal(user)
	if err != nil {
		beego.Error("err:", err.Error())
		ErrMap["msg"] = err.Error()
		re, _ := json.Marshal(ErrMap)
		this.Ctx.Output.Body(re)
		return
	}
	this.Ctx.Output.Body(re)
}