예제 #1
0
파일: controller.go 프로젝트: klenin/orc
func (this *Controller) CheckSid() (id int, result error) {
	userSid := sessions.GetValue("sid", this.Request)
	if !sessions.CheckSession(this.Response, this.Request) || userSid == nil {
		return -1, errors.New("Данные в куках отсутствуют.")
	}

	if err := this.GetModel("users").
		LoadWherePart(map[string]interface{}{"sid": userSid}).
		SelectRow([]string{"id"}).
		Scan(&id); err != nil {
		return -1, errors.New("Данные в куках отсутствуют.")
	}

	return id, nil
}
예제 #2
0
func (this *UserController) CheckSession() {
	var userHash string
	var result interface{}

	sid := sessions.GetValue("sid", this.Request)
	if sid == nil {
		result = map[string]interface{}{"result": "no"}

	} else {
		err := this.GetModel("users").
			LoadWherePart(map[string]interface{}{"sid": sid}).
			SelectRow([]string{"sid"}).
			Scan(&userHash)
		if err != sql.ErrNoRows && sessions.CheckSession(this.Response, this.Request) {
			result = map[string]interface{}{"result": "ok"}
		} else {
			result = map[string]interface{}{"result": "no"}
		}
	}

	utils.SendJSReply(result, this.Response)
}