当前位置: 首页>>代码示例>>Golang>>正文


Golang utils.SendJSReply函数代码示例

本文整理汇总了Golang中github.com/klenin/orc/utils.SendJSReply函数的典型用法代码示例。如果您正苦于以下问题:Golang SendJSReply函数的具体用法?Golang SendJSReply怎么用?Golang SendJSReply使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SendJSReply函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetBlankByRegId

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)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:32,代码来源:blank_controller.go

示例2: GetHistoryRequest

func (this *BlankController) GetHistoryRequest() {
	userId, err := this.CheckSid()
	if err != nil {
		utils.SendJSReply(map[string]interface{}{"result": "Unauthorized"}, this.Response)
		return
	}

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

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

	query := `SELECT params.id as param_id, params.name as param_name,
            param_types.name as type, param_values.value, forms.id as form_id
        FROM events
        INNER JOIN events_forms ON events_forms.event_id = events.id
        INNER JOIN forms ON events_forms.form_id = forms.id
        INNER JOIN registrations ON events.id = registrations.event_id
        INNER JOIN faces ON faces.id = registrations.face_id
        INNER JOIN users ON users.id = faces.user_id
        INNER JOIN params ON params.form_id = forms.id
        INNER JOIN param_types ON param_types.id = params.param_type_id
        INNER JOIN param_values ON param_values.param_id = params.id
            AND param_values.reg_id = registrations.id
        WHERE users.id = $1 AND events.id = $2 AND forms.personal = true;`

	utils.SendJSReply(map[string]interface{}{"result": "ok", "data": db.Query(query, []interface{}{userId, eventId})}, this.Response)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:35,代码来源:blank_controller.go

示例3: GetEventTypesByEventId

//-----------------------------------------------------------------------------
func (this *GridController) GetEventTypesByEventId() {
	if !sessions.CheckSession(this.Response, this.Request) {
		http.Redirect(this.Response, this.Request, "/", http.StatusUnauthorized)

		return
	}

	if !this.isAdmin() {
		http.Redirect(this.Response, this.Request, "/", http.StatusForbidden)

		return
	}

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

		return
	}

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

		return
	}

	query := `SELECT event_types.id, event_types.name FROM events_types
        INNER JOIN events ON events.id = events_types.event_id
        INNER JOIN event_types ON event_types.id = events_types.type_id
        WHERE events.id = $1 ORDER BY event_types.id;`
	result := db.Query(query, []interface{}{eventId})

	utils.SendJSReply(map[string]interface{}{"result": "ok", "data": result}, this.Response)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:36,代码来源:grid_controller.go

示例4: Logout

func (this *RegistrationController) Logout() {
	userId, err := this.CheckSid()
	if err != nil {
		http.Redirect(this.Response, this.Request, "/", http.StatusUnauthorized)
		utils.SendJSReply(map[string]string{"result": "badSid"}, this.Response)

		return
	}

	var enabled bool
	if err = this.GetModel("users").
		LoadWherePart(map[string]interface{}{"id": userId}).
		SelectRow([]string{"enabled"}).
		Scan(&enabled); utils.HandleErr("[RegistrationController::Logout]: ", err, this.Response) {
		utils.SendJSReply(map[string]string{"result": err.Error()}, this.Response)

		return
	}

	params := map[string]interface{}{"enabled": enabled, "sid": " "}
	where := map[string]interface{}{"id": userId}
	this.GetModel("users").Update(this.isAdmin(), userId, params, where)
	sessions.ClearSession(this.Response)
	utils.SendJSReply(map[string]string{"result": "ok"}, this.Response)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:25,代码来源:registration_controller.go

示例5: GetListHistoryEvents

func (this *BlankController) GetListHistoryEvents() {
	userId, err := this.CheckSid()
	if err != nil {
		utils.SendJSReply(map[string]interface{}{"result": "Unauthorized"}, this.Response)

		return
	}

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

		return
	}

	ids := map[string]interface{}{"form_id": make([]interface{}, 0)}
	if data["form_ids"] == nil || len(data["form_ids"].([]interface{})) == 0 {
		utils.SendJSReply(map[string]interface{}{"result": "Нет данных о формах анкеты"}, this.Response)

		return
	}

	for _, v := range data["form_ids"].([]interface{}) {
		ids["form_id"] = append(ids["form_id"].([]interface{}), int(v.(float64)))
	}

	eventsForms := this.GetModel("events_forms")
	events := eventsForms.
		LoadWherePart(ids).
		SetCondition(models.OR).
		Select_([]string{"event_id"})

	if len(events) == 0 {
		utils.SendJSReply(map[string]interface{}{"result": "Нет данных"}, this.Response)

		return
	}

	query := `SELECT DISTINCT events.id, events.name FROM events
        INNER JOIN events_forms ON events_forms.event_id = events.id
        INNER JOIN forms ON events_forms.form_id = forms.id
        INNER JOIN registrations ON registrations.event_id = events.id
        INNER JOIN faces ON faces.id = registrations.face_id
        INNER JOIN users ON users.id = faces.user_id
        WHERE users.id=$1 AND events.id IN (`

	var i int
	params := []interface{}{userId}

	for i = 2; i < len(events); i++ {
		query += "$" + strconv.Itoa(i) + ", "
		params = append(params, int(events[i-2].(map[string]interface{})["event_id"].(int)))
	}

	query += "$" + strconv.Itoa(i) + ")"
	params = append(params, int(events[i-2].(map[string]interface{})["event_id"].(int)))

	utils.SendJSReply(map[string]interface{}{"result": "ok", "data": db.Query(query, params)}, this.Response)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:59,代码来源:blank_controller.go

示例6: EditParams

//-----------------------------------------------------------------------------
func (this *BlankController) EditParams() {
	userId, err := this.CheckSid()
	if err != nil {
		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
	}

	date := time.Now().Format("2006-01-02T15:04:05Z00:00")

	for _, v := range request["data"].([]interface{}) {
		paramValId, err := strconv.Atoi(v.(map[string]interface{})["param_val_id"].(string))
		if err != nil {
			utils.SendJSReply(map[string]interface{}{"result": err.Error()}, this.Response)
			return
		}

		query := `SELECT params.name, params.required, params.editable
            FROM params
            INNER JOIN param_values ON param_values.param_id = params.id
            WHERE param_values.id = $1;`
		result := db.Query(query, []interface{}{paramValId})

		name := result[0].(map[string]interface{})["name"].(string)
		required := result[0].(map[string]interface{})["required"].(bool)
		editable := result[0].(map[string]interface{})["editable"].(bool)
		value := v.(map[string]interface{})["value"].(string)

		if required && utils.MatchRegexp("^[ \t\v\r\n\f]{0,}$", value) {
			utils.SendJSReply(map[string]interface{}{"result": "Заполните параметр '" + name + "'"}, this.Response)
			return
		}

		if !this.isAdmin() && !editable {
			continue
		}

		if value == "" {
			value = " "
		}

		params := map[string]interface{}{"value": value, "date": date, "user_id": userId}
		where := map[string]interface{}{"id": paramValId}
		this.GetModel("param_values").Update(this.isAdmin(), userId, params, where)
	}

	utils.SendJSReply(map[string]interface{}{"result": "Изменения сохранены"}, this.Response)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:54,代码来源:blank_controller.go

示例7: SendEmailWellcomeToProfile

func (this *UserController) SendEmailWellcomeToProfile() {
	if !this.isAdmin() {
		http.Redirect(this.Response, this.Request, "/", http.StatusForbidden)
		return
	}

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

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

	query := `SELECT param_values.value
        FROM param_values
        INNER JOIN registrations ON registrations.id = param_values.reg_id
        INNER JOIN params ON params.id = param_values.param_id
        INNER JOIN events ON events.id = registrations.event_id
        INNER JOIN faces ON faces.id = registrations.face_id
        INNER JOIN users ON users.id = faces.user_id
        WHERE params.id in (4, 5, 6, 7) AND users.id = $1 ORDER BY params.id;`
	data := db.Query(query, []interface{}{userId})

	if len(data) < 4 {
		utils.SendJSReply(map[string]interface{}{"result": "Нет регистрационных данных пользователя."}, this.Response)
		return
	}

	to := data[1].(map[string]interface{})["value"].(string) + " "
	to += data[2].(map[string]interface{})["value"].(string) + " "
	to += data[3].(map[string]interface{})["value"].(string)
	email := data[0].(map[string]interface{})["value"].(string)

	token := utils.GetRandSeq(HASH_SIZE)
	if !mailer.SendEmailWellcomeToProfile(to, email, token) {
		utils.SendJSReply(map[string]interface{}{"result": "Проверьте правильность email."}, this.Response)
		return
	}

	params := map[string]interface{}{"token": token, "enabled": true}
	where := map[string]interface{}{"id": userId}
	this.GetModel("users").Update(this.isAdmin(), userId, params, where)

	utils.SendJSReply(map[string]interface{}{"result": "Письмо отправлено"}, this.Response)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:50,代码来源:user_controller.go

示例8: GetEditHistoryData

//-----------------------------------------------------------------------------
func (this *BlankController) GetEditHistoryData() {
	data, 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(data["reg_id"].(string))
	if err != nil {
		utils.SendJSReply(map[string]interface{}{"result": err.Error()}, this.Response)
		return
	}

	formType := data["personal"].(string)
	if formType != "true" && formType != "false" {
		utils.SendJSReply(map[string]interface{}{"result": "Invalid form type"}, this.Response)
		return
	}

	query := `SELECT params.id as param_id, forms.id as form_id, p.date as edit_date,
        array_to_string(ARRAY(
            SELECT param_values.value
                FROM events
                INNER JOIN events_forms ON events_forms.event_id = events.id
                INNER JOIN forms ON events_forms.form_id = forms.id
                INNER JOIN registrations ON events.id = registrations.event_id
                INNER JOIN faces ON faces.id = registrations.face_id
                INNER JOIN users ON users.id = faces.user_id
                INNER JOIN params ON params.form_id = forms.id
                INNER JOIN param_types ON param_types.id = params.param_type_id
                INNER JOIN param_values ON param_values.param_id = params.id
                    AND registrations.id = param_values.reg_id
                WHERE (params.id in (5, 6, 7) AND events.id = 1) and users.id = p.user_id
        ), ' ') as login
        FROM events
        INNER JOIN events_forms ON events_forms.event_id = events.id
        INNER JOIN forms ON events_forms.form_id = forms.id
        INNER JOIN registrations ON events.id = registrations.event_id
        INNER JOIN faces ON faces.id = registrations.face_id
        INNER JOIN users ON users.id = faces.user_id
        INNER JOIN params ON params.form_id = forms.id
        INNER JOIN param_types ON param_types.id = params.param_type_id
        INNER JOIN param_values as p ON p.param_id = params.id
            AND p.reg_id = registrations.id
        WHERE registrations.id = $1 AND forms.personal = $2;`

	utils.SendJSReply(map[string]interface{}{"result": "ok", "data": db.Query(query, []interface{}{regId, formType})}, this.Response)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:49,代码来源:blank_controller.go

示例9: GroupRegistrationsLoad

func (this *Handler) GroupRegistrationsLoad() {
	userId, err := this.CheckSid()
	if err != nil {
		http.Error(this.Response, "Unauthorized", 400)
		return
	}

	limit, err := strconv.Atoi(this.Request.PostFormValue("rows"))
	if err != nil {
		http.Error(this.Response, err.Error(), 400)
		return
	}

	page, err := strconv.Atoi(this.Request.PostFormValue("page"))
	if err != nil {
		http.Error(this.Response, err.Error(), 400)
		return
	}

	sidx := this.Request.FormValue("sidx")
	start := limit*page - limit

	query := `SELECT group_registrations.id, group_registrations.event_id,
            group_registrations.group_id
        FROM group_registrations
        INNER JOIN events ON events.id = group_registrations.event_id
        INNER JOIN groups ON groups.id = group_registrations.group_id
        INNER JOIN persons ON persons.group_id = groups.id
        INNER JOIN faces ON faces.id = persons.face_id
        INNER JOIN users ON users.id = faces.user_id
        WHERE users.id = $1 AND events.team = $2 ORDER BY $3 LIMIT $4 OFFSET $5;`
	rows := db.Query(query, []interface{}{userId, true, sidx, limit, start})

	query = `SELECT COUNT(*) FROM (SELECT group_registrations.id
        FROM group_registrations
        INNER JOIN events ON events.id = group_registrations.event_id
        INNER JOIN groups ON groups.id = group_registrations.group_id
        INNER JOIN persons ON persons.group_id = groups.id
        INNER JOIN faces ON faces.id = persons.face_id
        INNER JOIN users ON users.id = faces.user_id
        WHERE users.id = $1 AND events.team = $2 GROUP BY group_registrations.id) as count;`

	var count int
	db.QueryRow(query, []interface{}{userId, true}).Scan(&count)

	var totalPages int
	if count > 0 {
		totalPages = int(math.Ceil(float64(count) / float64(limit)))
	} else {
		totalPages = 0
	}

	result := make(map[string]interface{}, 2)
	result["rows"] = rows
	result["page"] = page
	result["total"] = totalPages
	result["records"] = count

	utils.SendJSReply(result, this.Response)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:60,代码来源:load.go

示例10: ResetPassword

func (this *UserController) ResetPassword() {
	userId, err := this.CheckSid()
	if err != nil {
		http.Redirect(this.Response, this.Request, "/", http.StatusUnauthorized)
		return
	}

	request, err := utils.ParseJS(this.Request, this.Response)
	if err != nil {
		utils.SendJSReply(err.Error(), this.Response)
		return
	}

	pass := request["pass"].(string)
	if !utils.MatchRegexp("^.{6,36}$", pass) {
		utils.SendJSReply(map[string]interface{}{"result": "badPassword"}, this.Response)
		return
	}

	var id int
	if request["id"] == nil {
		id = userId

	} else {
		id, err = strconv.Atoi(request["id"].(string))
		if utils.HandleErr("[UserController::ResetPassword] strconv.Atoi: ", err, this.Response) {
			utils.SendJSReply(map[string]interface{}{"result": err.Error()}, this.Response)
			return
		}
	}

	var enabled bool
	salt := strconv.Itoa(int(time.Now().Unix()))
	where := map[string]interface{}{"id": id}

	user := this.GetModel("users")
	user.LoadWherePart(where).
		SelectRow([]string{"enabled"}).
		Scan(&enabled)

	params := map[string]interface{}{"enabled": enabled, "salt": salt, "pass": utils.GetMD5Hash(pass + salt)}
	user.Update(this.isAdmin(), id, params, where)

	utils.SendJSReply(map[string]interface{}{"result": "ok"}, this.Response)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:45,代码来源:user_controller.go

示例11: GetGroupBlank

func (this *BlankController) GetGroupBlank() {
	request, err := utils.ParseJS(this.Request, this.Response)
	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
	}

	utils.SendJSReply(
		map[string]interface{}{
			"result": "ok",
			"data":   new(models.BlankManager).NewGroupBlank(false).SetGroupRegId(groupRegId).GetTeamBlank()},
		this.Response)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:19,代码来源:blank_controller.go

示例12: IsRegGroup

func (this *GroupController) IsRegGroup() {
	_, err := this.CheckSid()
	if err != nil {
		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)
	}

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

	addDelFlag := !db.IsExists("group_registrations", []string{"group_id"}, []interface{}{groupId})
	utils.SendJSReply(map[string]interface{}{"result": "ok", "addDelFlag": addDelFlag}, this.Response)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:20,代码来源:group_controller.go

示例13: Login

func (this *RegistrationController) Login() {
	data, err := utils.ParseJS(this.Request, this.Response)
	if utils.HandleErr("[RegistrationController::Login]: ", err, this.Response) {
		utils.SendJSReply(map[string]interface{}{"result": err.Error()}, this.Response)

		return
	}

	login := data["login"].(string)
	pass := data["password"].(string)

	var id int
	var enabled bool
	var passHash, salt string
	result := make(map[string]interface{}, 1)

	if err = this.GetModel("users").
		LoadWherePart(map[string]interface{}{"login": login}).
		SelectRow([]string{"id", "pass", "salt", "enabled"}).
		Scan(&id, &passHash, &salt, &enabled); err != nil {
		result["result"] = "invalidCredentials"

	} else if enabled == false {
		result["result"] = "notEnabled"

	} else if passHash != utils.GetMD5Hash(pass+salt) {
		result["result"] = "badPassword"

	} else {
		result["result"] = "ok"

		sid := utils.GetRandSeq(HASH_SIZE)
		params := map[string]interface{}{"sid": sid, "enabled": true}
		where := map[string]interface{}{"id": id}
		this.GetModel("users").Update(this.isAdmin(), id, params, where)
		sessions.SetSession(this.Response, map[string]interface{}{"sid": sid})
	}

	utils.SendJSReply(result, this.Response)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:40,代码来源:registration_controller.go

示例14: GroupsLoad

func (this *Handler) GroupsLoad() {
	userId, err := this.CheckSid()
	if err != nil {
		http.Error(this.Response, "Unauthorized", 400)
		return
	}

	limit, err := strconv.Atoi(this.Request.PostFormValue("rows"))
	if err != nil {
		http.Error(this.Response, err.Error(), 400)
		return
	}

	page, err := strconv.Atoi(this.Request.PostFormValue("page"))
	if err != nil {
		http.Error(this.Response, err.Error(), 400)
		return
	}

	sidx := this.Request.FormValue("sidx")
	start := limit*page - limit

	query := `SELECT groups.id, groups.name, groups.face_id
        FROM groups
        INNER JOIN persons ON persons.group_id = groups.id
        INNER JOIN faces ON faces.id = persons.face_id
        INNER JOIN users ON users.id = faces.user_id
        WHERE users.id = $1 ORDER BY $2 LIMIT $3 OFFSET $4;`
	rows := db.Query(query, []interface{}{userId, sidx, limit, start})

	query = `SELECT COUNT(*) FROM (SELECT groups.id FROM groups
        INNER JOIN persons ON persons.group_id = groups.id
        INNER JOIN faces ON faces.id = persons.face_id
        INNER JOIN users ON users.id = faces.user_id
        WHERE users.id = $1) as count;`
	count := int(db.Query(query, []interface{}{userId})[0].(map[string]interface{})["count"].(int))

	var totalPages int
	if count > 0 {
		totalPages = int(math.Ceil(float64(count) / float64(limit)))
	} else {
		totalPages = 0
	}

	result := make(map[string]interface{}, 2)
	result["rows"] = rows
	result["page"] = page
	result["total"] = totalPages
	result["records"] = count

	utils.SendJSReply(result, this.Response)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:52,代码来源:load.go

示例15: CheckSession

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)
}
开发者ID:FooBarrior,项目名称:orc,代码行数:22,代码来源:user_controller.go


注:本文中的github.com/klenin/orc/utils.SendJSReply函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。