Exemple #1
0
func (this *BlankController) GetBlankByRegId() {
	if !sessions.CheckSession(this.Response, this.Request) {
		http.Redirect(this.Response, this.Request, "/", http.StatusUnauthorized)
		return
	}

	request, err := utils.ParseJS(this.Request, this.Response)
	if err != nil {
		utils.SendJSReply(map[string]interface{}{"result": err.Error()}, this.Response)
		return
	}

	regId, err := strconv.Atoi(request["reg_id"].(string))
	if err != nil {
		utils.SendJSReply(map[string]interface{}{"result": err.Error()}, this.Response)
		return
	}

	blank := new(models.BlankManager).NewPersonalBlank(true).SetRegId(regId)
	result := blank.GetBlank()

	if len(result) == 0 {
		result = blank.SetPersonal(false).GetBlank()
	}

	utils.SendJSReply(
		map[string]interface{}{
			"result": "ok",
			"data":   result,
			"role":   this.isAdmin()},
		this.Response)
}
Exemple #2
0
func (this *BlankController) GetPersonBlankFromGroup() {
	userId, err := this.CheckSid()
	if err != nil {
		utils.SendJSReply(map[string]interface{}{"result": "Unauthorized"}, this.Response)
		return
	}

	request, err := utils.ParseJS(this.Request, this.Response)
	if err != nil {
		utils.SendJSReply(map[string]interface{}{"result": err.Error()}, this.Response)
		return
	}

	var personalForm bool
	switch request["personal"].(string) {
	case "true":
		personalForm = true
		break
	case "false":
		personalForm = false
		break
	default:
		panic("Invalid bool value")
	}

	faceId, err := strconv.Atoi(request["face_id"].(string))
	if err != nil {
		utils.SendJSReply(map[string]interface{}{"result": err.Error()}, this.Response)
		return
	}

	groupRegId, err := strconv.Atoi(request["group_reg_id"].(string))
	if err != nil {
		utils.SendJSReply(map[string]interface{}{"result": err.Error()}, this.Response)
		return
	}

	var regId int

	if faceId == -1 {
		if this.isAdmin() {
			db.QueryRow(db.QueryGetCaptFaceIdAndRegId, []interface{}{groupRegId}).Scan(&faceId, &regId)
		} else {
			if err := this.GetModel("faces").
				LoadWherePart(map[string]interface{}{"user_id": userId}).
				SelectRow([]string{"id"}).
				Scan(&faceId); err != nil {
				utils.SendJSReply(map[string]interface{}{"result": err.Error()}, this.Response)

				return
			}
			db.QueryRow(db.QueryGetCaptRegIdByGroupRegIdAndFaceId, []interface{}{groupRegId, faceId}).Scan(&regId)
		}
	} else {
		db.QueryRow(db.QueryGetRegIdByGroupRegIdAndFaceId, []interface{}{groupRegId, faceId}).Scan(&regId)
	}

	log.Println("faceId: ", faceId, ", groupRegId: ", groupRegId, ", regId: ", regId, ", formType: ", personalForm)

	blank := new(models.BlankManager).NewGroupBlank(personalForm)
	blank.SetGroupRegId(groupRegId).SetFaceId(faceId)

	utils.SendJSReply(
		map[string]interface{}{
			"result": "ok",
			"data":   blank.GetBlank(),
			"role":   this.isAdmin(),
			"regId":  regId},
		this.Response)
}