Пример #1
0
func (this *RegisterController) Post() {
	data := RegisterData{}
	//get client data
	data.Mac = this.GetString("mac")
	data.Mid = this.GetString("mid")
	data.Psn = this.GetString("psn")
	//check auth
	uname, pwd, ok := this.Ctx.Request.BasicAuth()
	if !ok {
		beego.Info("get client  Request.BasicAuth failed!")
		data.Code = -1
		writeContent, _ := json.Marshal(data)
		this.Ctx.WriteString(string(writeContent))
		return
	}
	user := models.Userinfo{
		Username: uname,
		Password: pwd,
	}
	ok = models.CheckAccount(&user)
	if !ok {
		beego.Info("user/pwd not matched!")
		data.Code = -1
		writeContent, _ := json.Marshal(data)
		this.Ctx.WriteString(string(writeContent))
		return
	}
	//register
	deviceinfo := models.Deviceinfo{
		Mac: data.Mac,
		Mid: data.Mid,
		Psn: data.Psn,
	}
	data.Guid, data.Code = models.RegisterDeivce(&deviceinfo)
	writeContent, _ := json.Marshal(data)
	this.Ctx.WriteString(string(writeContent))
}
Пример #2
0
func (this *RegisterController) Post() {
	data := RegisterData{}
	//check auth
	uname, pwd, ok := this.Ctx.Request.BasicAuth()
	if !ok {
		beego.Info("get client  Request.BasicAuth failed!")
		data.Code = -1
		writeContent, _ := json.Marshal(data)
		this.Ctx.WriteString(string(writeContent))
		return
	}
	user := models.Userinfo{
		Username: uname,
		Password: pwd,
	}
	ok = models.CheckAccount(&user)
	if !ok {
		beego.Info("user/pwd not matched!")
		data.Code = -1
		writeContent, _ := json.Marshal(data)
		this.Ctx.WriteString(string(writeContent))
		return
	}

	//get client data
	var deviceinfo models.Deviceinfo
	err := json.Unmarshal(this.Ctx.Input.RequestBody, &deviceinfo)
	if err != nil {
		beego.Error(err)
		data.Code = -6
		writeContent, _ := json.Marshal(data)
		this.Ctx.WriteString(string(writeContent))
		return
	}
	if deviceinfo.Mac == "" || deviceinfo.Mid == 0 || deviceinfo.Psn == 0 {
		beego.Error(" input content error!")
		data.Code = -6
		writeContent, _ := json.Marshal(data)
		this.Ctx.WriteString(string(writeContent))
		return
	}
	data.Mac = deviceinfo.Mac
	data.Mid = deviceinfo.Mid
	data.Psn = deviceinfo.Psn
	//register
	var act string
	act, data.Guid, data.Code = models.RegisterDeivce(&deviceinfo)

	//action不为空,加入返回值
	if act != "" {
		ret := RegisterActData{
			Mac:  data.Mac,
			Mid:  data.Mid,
			Psn:  data.Psn,
			Guid: data.Guid,
			Code: data.Code,
			Act:  act,
		}
		writeContent, _ := json.Marshal(ret)
		this.Ctx.WriteString(string(writeContent))
		return
	} else {
		writeContent, _ := json.Marshal(data)
		this.Ctx.WriteString(string(writeContent))
		return
	}
}