// 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
		}

	}
}
示例#2
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)
	}
}