Example #1
0
func (this *DiscussController) MsgGet() {
	page := this.Input().Get("page")
	count := this.Input().Get("count")
	courseid := this.Input().Get("courseid")
	beego.Informational("page: ", page, "count: ", count, "courseid: ", courseid, "ip", this.Ctx.Input.IP())
	this.Ctx.Output.Body([]byte(`{"result":"ok","discuss":[{"name":"**","text":"**","ctime":21321321},{"name":"**","text":"**","ctime":21321321}]}`))
}
Example #2
0
func ViewLogin(c *context.Context) {
	cookie := c.GetCookie("MtimeCIUserId")
	if len(cookie) <= 0 {
		c.Redirect(302, "/login?url="+url.QueryEscape(c.Input.Uri()))
	}
	beego.Informational(cookie)
}
Example #3
0
func (this *CourseStatusController) Get() {
	var userid int64
	var courseid int64
	this.Ctx.Input.Bind(&userid, "userid")
	this.Ctx.Input.Bind(&courseid, "courseid")
	beego.Informational("userid: ", userid, "courseid: ", courseid, "ip", this.Ctx.Input.IP())
	status, err := models.GetCourseStatus(userid, courseid)
	if err != nil {
		beego.Error("err:", err.Error())
		ErrMap["msg"] = err.Error()
		re, _ := json.Marshal(ErrMap)
		this.Ctx.Output.Body(re)
		return
	}
	remap := Map{"result": "ok"}
	remap["status"] = status
	re, err := json.Marshal(remap)
	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)

	this.Ctx.Output.Body([]byte(`{"result":"ok","status":"subscribed"}`))
}
Example #4
0
func (this *AccountController) Post() {
	beego.Informational("login json: ", string(this.Ctx.Input.RequestBody), "ip:", this.Ctx.Input.IP())
	var user models.User
	err := json.Unmarshal(this.Ctx.Input.RequestBody, &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([]byte(`{"result":"ok","userid":123,"role":"student","name":"lu"}`))
	id, err := models.AddUser(user)
	if err != nil {
		beego.Error("err:", err.Error())
		ErrMap["msg"] = err.Error()
		if strings.Contains(err.Error(), "Duplicate entry") {
			ErrMap["msg"] = "该用户名已被注册"
		}
		re, _ := json.Marshal(ErrMap)
		this.Ctx.Output.Body(re)
		return
	}
	user.Id = id
	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)
}
Example #5
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"}`))
}
Example #6
0
// func DebugOutputColor(log string, level int) {
// 	switch level {
// 	case 1:
// 		color.Red(log)
// 	case 2:
// 		color.Yellow(log)
// 	case 3:
// 		color.Green(log)
// 	case 4:
// 		color.Blue(log)
// 	}
// }
func DebugOutputBeego(log string, level int) {
	switch level {
	case 1:
		beego.Error(log)
	case 2:
		beego.Notice(log)
	case 3:
		beego.Informational(log)
	case 4:
		beego.Debug(log)
	}
}
Example #7
0
func (this *DiscussController) Post() {
	beego.Informational("post json: ", string(this.Ctx.Input.RequestBody), "ip", this.Ctx.Input.IP())
	var discuss models.Discuss
	err := json.Unmarshal(this.Ctx.Input.RequestBody, &discuss)
	if err != nil {
		beego.Error("err:", err.Error())
		ErrMap["msg"] = err.Error()
		re, _ := json.Marshal(ErrMap)
		this.Ctx.Output.Body(re)
		return
	}
	_, err = models.AddDiscuss(discuss)
	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"}`))
}
Example #8
0
func (this *AccountController) Put() {
	beego.Informational("login json: ", string(this.Ctx.Input.RequestBody), "ip:", this.Ctx.Input.IP())
	var pwd Pwd
	err := json.Unmarshal(this.Ctx.Input.RequestBody, &pwd)
	if err != nil {
		beego.Error("err:", err.Error())
		ErrMap["msg"] = err.Error()
		re, _ := json.Marshal(ErrMap)
		this.Ctx.Output.Body(re)
		return
	}
	err = models.UpdatePassword(pwd.Id, pwd.Op, pwd.Np)
	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"}`))
}
Example #9
0
func (this *CourseStatusController) Put() {
	beego.Informational("login json: ", string(this.Ctx.Input.RequestBody), "ip", this.Ctx.Input.IP())
	var uc models.Usercourse
	err := json.Unmarshal(this.Ctx.Input.RequestBody, &uc)
	if err != nil {
		beego.Error("err:", err.Error())
		ErrMap["msg"] = err.Error()
		re, _ := json.Marshal(ErrMap)
		this.Ctx.Output.Body(re)
		return
	}
	err = models.UpdateCourseStatus(uc)
	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"}`))
}
Example #10
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)
}
Example #11
0
func (this *DiscussController) MsgPost() {
	beego.Informational("msgpost json: ", string(this.Ctx.Input.RequestBody), "ip", this.Ctx.Input.IP())
	this.Ctx.Output.Body([]byte(`{"result":"ok"}`))
}