示例#1
0
func ProcessSMS(warning *models.Warning, db gorp.SqlExecutor, status *models.DefaultStruct) {

	if isWarnSentLimitByIpOver(warning, db) {
		status.Id = http.StatusBadRequest
		status.Name = strings.Replace(messages.GetLocaleMessage(warning.Lang_key, "MSG_SMS_QUOTA_EXCEEDED"), "{{ip}}", warning.Ip, 1)
		status.Lang_key = warning.Lang_key
	} else {
		go sendSMSWarn(warning, db)
	}
}
// After registered in the Database, the warn is processed in order to verify:
// - @isSameWarnSentByIp
// - @isSameWarnSentTwiceOrMoreDifferentIp
// - if none of above occurs the warn is processed by its type(Email, SMS, Whatsapp, etc...)
//		- @routers.email.ProcessEmail
//		- @routers.sms.ProcessSMS
func processWarn(warning *models.Warning, db gorp.SqlExecutor, status *models.DefaultStruct) {
	fmt.Println("processWarn")

	status.Lang_key = warning.Lang_key
	if isSameWarnSentByIp(warning, db) {
		status.Id = http.StatusBadRequest
		status.Name = strings.Replace(messages.GetLocaleMessage(warning.Lang_key, "MSG_SMS_SAME_WARN_BY_IP"), "{{ip}}", warning.Ip, 1)
		status.Name = strings.Replace(status.Name, "{{time}}", "2", 1)
	} else if isSameWarnSentTwiceOrMoreDifferentIp(warning, db) {
		status.Id = http.StatusBadRequest
		status.Name = strings.Replace(messages.GetLocaleMessage(warning.Lang_key, "MSG_SMS_SAME_WARN_DIFF_IP"), "{{time}}", "2", 1)
	} else {
		if warning.WarnResp != nil && warning.WarnResp.Reply_to != "" {
			ProcessWarnReply(warning, db)
		} else {
			warning.WarnResp = nil
		}

		switch warning.Id_contact_type {
		case 1:
			go ProcessEmail(warning, db)
		case 2:
			ProcessSMS(warning, db, status)
		case 3:
			go ProcessWhatsapp(warning, db)
		default:
			return
		}

	}
}
func UpdateContact_type(entity models.DefaultStruct, enc Encoder, db gorp.SqlExecutor, parms martini.Params) (int, string) {
	id, err := strconv.Atoi(parms["id"])
	obj, _ := db.Get(models.DefaultStruct{}, id)
	if err != nil || obj == nil {
		checkErr(err, "GET CONTACT TYPE FAILED")
		// Invalid id, or does not exist
		return http.StatusBadRequest, ""
	}
	oldEntity := obj.(*models.DefaultStruct)

	entity.Id = oldEntity.Id
	_, err = db.Update(&entity)
	if err != nil {
		checkErr(err, "UPDATE CONTACT TYPE FAILED")
		return http.StatusBadRequest, ""
	}
	return http.StatusOK, Must(enc.EncodeOne(entity))
}