Ejemplo n.º 1
0
// Confirm the request for ignore list
func ConfirmIgnoreList(entity models.Ignore_List, w http.ResponseWriter, enc Encoder, db gorp.SqlExecutor) (int, string) {

	if isInvalidIgnoreListConfirm(&entity) {
		return http.StatusBadRequest, Must(enc.EncodeOne(entity))
	}

	status := &models.DefaultStruct{
		Id:       http.StatusOK,
		Name:     messages.GetLocaleMessage(entity.Lang_key, "MSG_IGNORED_SUCCESSFUL"),
		Lang_key: entity.Lang_key,
	}

	ignored := GetIgnoreContact(db, entity.Confirmation_code)

	if ignored != nil {
		ignored.Confirmed = true
		ignored.Last_modified_date = entity.Last_modified_date
		UpdateIgnoreList(ignored, db)
	} else {
		status = &models.DefaultStruct{
			Id:       http.StatusBadRequest,
			Name:     messages.GetLocaleMessage(entity.Lang_key, "MSG_IGNOREME_CODE_INVALID"),
			Lang_key: entity.Lang_key,
		}
	}

	return http.StatusCreated, Must(enc.EncodeOne(status))
}
Ejemplo n.º 2
0
// 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
		}

	}
}
Ejemplo n.º 3
0
func DoLogin(entity models.UserLogin, session sessions.Session, enc Encoder, db gorp.SqlExecutor) (int, string) {

	status := &models.DefaultStruct{
		Id:       http.StatusForbidden,
		Name:     messages.GetLocaleMessage("en", "MSG_LOGIN_INVALID"),
		Lang_key: "en",
	}

	user := GetUserByLogin(entity, db)

	if user.Name != "" {

		err := sessionauth.AuthenticateSession(session, user)
		if err != nil {
			status.Name = messages.GetLocaleMessage("en", "MSG_SESSION_INIT_ERROR")
			return http.StatusForbidden, Must(enc.EncodeOne(status))
		}
		user.Authenticated = true
		user.UpdateLastLogin()
		status.Name = messages.GetLocaleMessage("en", "MSG_SUCCESSFUL_LOGIN")
		return http.StatusOK, Must(enc.EncodeOne(user))

	} else {

		sessionauth.Logout(session, user)
		session.Clear()
		return http.StatusForbidden, Must(enc.EncodeOne(status))

	}

	return http.StatusForbidden, Must(enc.EncodeOne(status))
}
Ejemplo n.º 4
0
func sendIgnoreMeSetup(email string, entity *models.Ignore_List, db gorp.SqlExecutor) string {

	var email_content string
	email_content = strings.Replace(email, "{{subject}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_IGNOREME_SUBJECT"), 1)

	email_content = strings.Replace(email_content, "{{broda_msg_header_greet}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_IGNOREME_GREET"), 1)
	email_content = strings.Replace(email_content, "{{warning}}", entity.Confirmation_code, 1)
	email_content = strings.Replace(email_content, "{{broda_msg_footer_greet}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_IGNOREME_FOOTER"), 1)
	email_content = strings.Replace(email_content, "{{warnabroda_headline}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_WARNABRODA_HEADLINE"), 1)
	email_content = strings.Replace(email_content, "{{follow_us}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_FOLLOW_US"), 1)
	email_content = strings.Replace(email_content, "{{terms}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_TERMS_SERVICE"), 1)

	// email_content = strings.Replace(email_content, "{{reply_url}}", ShortUrl(models.URL_IGNOREME+"/"+entity.WarnResp.Read_hash), 1)
	email_content = strings.Replace(email_content, "{{reply_url}}", ShortUrl(models.URL_IGNOREME), 1)
	email_content = strings.Replace(email_content, "{{reply_msg}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_IGNOREME_BUTTON"), 1)
	email_content = strings.Replace(email_content, "{{broda_msg_ignoreme_footer}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_IGNOREME_NOT"), 1)

	the7messages := GetRandomMessagesByLanguage(7, entity.Lang_key, db)

	for key, value := range the7messages {

		email_content = strings.Replace(email_content, "{{suggest_msg"+fmt.Sprint(key+1)+"}}", value.Name, 1)
		email_content = strings.Replace(email_content, "{{suggest_link"+fmt.Sprint(key+1)+"}}", ShortUrl(models.URL_WARNABRODA+"/#/"+fmt.Sprint(value.Id)), 1)
	}

	return email_content

}
Ejemplo n.º 5
0
func SendWhatsappIgnoreRequest(entity *models.Ignore_List, db gorp.SqlExecutor) {
	fmt.Println("SendWhatsappIgnoreRequest")

	message := strings.Replace(messages.GetLocaleMessage(entity.Lang_key, "MSG_SMS_IGNORE_CONFIRMATION_REQUEST"), "{{url}}", entity.Confirmation_code, 1)
	footer := messages.GetLocaleMessage(entity.Lang_key, "MSG_FOOTER")

	whatsMsg := models.Whatsapp{
		Id:      -1 * entity.Id,
		Number:  strings.Replace(entity.Contact, "+", "", 1),
		Message: message + "... " + footer,
		Type:    models.MSG_TYPE_IGNORE,
	}

	sendWhatsapp(&whatsMsg)
}
Ejemplo n.º 6
0
// Get a random subject from the previews loaded upon containers startup
func GetRandomSubject(lang_key string) models.DefaultStruct {

	var subject models.DefaultStruct

	subjects := GetSubjectsByLangKey(lang_key)

	// r := rand.New(rand.NewSource(99))
	rand.Seed(time.Now().UTC().UnixNano())

	if len(subjects) > 0 {

		var index = rand.Intn(len(subjects))

		if index < len(subjects) {
			subject = subjects[index]
		} else {
			subject = subjects[0]
		}

	} else {

		subject = models.DefaultStruct{0, messages.GetLocaleMessage(lang_key, "MSG_DEFAULT_SUBJECT"), lang_key, true, ""}
	}

	return subject
}
Ejemplo n.º 7
0
// opens the template, parse the variables sets the email struct and Send the confirmation code to confirm the ignored contact.
func SendEmailIgnoreme(entity *models.Ignore_List, db gorp.SqlExecutor) {
	//reads the e-mail template from a local file
	wab_email_template := wab_root + "/resource/ignoreme.html"
	template_byte, err := ioutil.ReadFile(wab_email_template)
	checkErr(err, "Ignore-me Email File Opening ERROR")
	template_email_string := string(template_byte[:])

	email_content := sendIgnoreMeSetup(template_email_string, entity, db)

	email := &models.Email{
		TemplatePath: wab_email_template,
		Content:      email_content,
		Subject:      messages.GetLocaleMessage(entity.Lang_key, "MSG_EMAIL_SUBJECT_ADD_IGNORE_LIST"),
		ToAddress:    entity.Contact,
		FromName:     models.WARN_A_BRODA,
		LangKey:      entity.Lang_key,
		Async:        false,
		UseContent:   true,
		HTMLContent:  true,
	}

	sent, response := SendMail(email)
	if sent {
		entity.Message = response
		UpdateIgnoreList(entity, db)
	}
}
Ejemplo n.º 8
0
func SendEmailReplyRequestAcknowledge(entity *models.WarningResp, db gorp.SqlExecutor) {
	fmt.Println("SendEmailReplyRequestAcknowledge")

	//reads the e-mail template from a local file
	wab_email_template := wab_root + "/resource/warning.html"
	template_byte, err := ioutil.ReadFile(wab_email_template)
	checkErr(err, "Email File Opening ERROR")
	template_email_string := string(template_byte[:])

	subject := messages.GetLocaleMessage(entity.Lang_key, "MSG_SUBJECT_REPLY_REQUEST") + ": " + entity.Resp_hash[:6]

	email_content := sendReplyAcknowledgeSetup(template_email_string, entity, db)

	email := &models.Email{
		TemplatePath: wab_email_template,
		Content:      email_content,
		Subject:      subject,
		ToAddress:    entity.Reply_to,
		FromName:     models.WARN_A_BRODA,
		LangKey:      entity.Lang_key,
		Async:        false,
		UseContent:   true,
		HTMLContent:  true,
	}

	SendMail(email)
}
Ejemplo n.º 9
0
func sendReplySetup(email string, entity *models.Warning, db gorp.SqlExecutor) string {
	fmt.Println("sendReplySetup")

	var email_content string
	email_content = strings.Replace(email, "{{subject}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_REPLY_BODY_GREETING"), 1)

	message := SelectMessage(db, entity.Id_message)

	mainBodyMsg := messages.GetLocaleMessage(entity.Lang_key, "MSG_REPLY_BODY_MAIN")
	mainBodyMsg = strings.Replace(mainBodyMsg, "{{contact_msg}}", "'"+entity.Contact+"'", 1)

	email_content = strings.Replace(email_content, "{{broda_msg_header_greet}}", mainBodyMsg, 1)
	email_content = strings.Replace(email_content, "{{warning}}", message.Name, 1)
	email_content = strings.Replace(email_content, "{{broda_msg_footer_greet}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_REPLY_READ_MSG"), 1)
	email_content = strings.Replace(email_content, "{{warnabroda_headline}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_WARNABRODA_HEADLINE"), 1)
	email_content = strings.Replace(email_content, "{{follow_us}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_FOLLOW_US"), 1)
	email_content = strings.Replace(email_content, "{{terms}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_TERMS_SERVICE"), 1)

	email_content = strings.Replace(email_content, "{{reply_url}}", ShortUrl(models.URL_REPLY+"/"+entity.WarnResp.Read_hash), 1)
	email_content = strings.Replace(email_content, "{{reply_msg}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_READ_REPLY_NOW"), 1)

	the7messages := GetRandomMessagesByLanguage(7, entity.Lang_key, db)

	for key, value := range the7messages {

		email_content = strings.Replace(email_content, "{{suggest_msg"+fmt.Sprint(key+1)+"}}", value.Name, 1)
		email_content = strings.Replace(email_content, "{{suggest_link"+fmt.Sprint(key+1)+"}}", ShortUrl(models.URL_WARNABRODA+"/#/"+fmt.Sprint(value.Id)), 1)
	}

	return email_content

}
Ejemplo n.º 10
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)
	}
}
Ejemplo n.º 11
0
func sendWarningSetup(mailSubject string, email string, entity *models.Warning, db gorp.SqlExecutor) string {
	fmt.Println("sendWarningSetup")

	var email_content string
	message := SelectMessage(db, entity.Id_message)
	email_content = strings.Replace(email, "{{subject}}", mailSubject, 1)
	email_content = strings.Replace(email_content, "{{broda_msg_header_greet}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_EMAIL_GREET"), 1)
	email_content = strings.Replace(email_content, "{{warning}}", message.Name, 1)
	email_content = strings.Replace(email_content, "{{broda_msg_footer_greet}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_FOOTER"), 1)
	email_content = strings.Replace(email_content, "{{warnabroda_headline}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_WARNABRODA_HEADLINE"), 1)
	email_content = strings.Replace(email_content, "{{follow_us}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_FOLLOW_US"), 1)
	email_content = strings.Replace(email_content, "{{terms}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_TERMS_SERVICE"), 1)

	if entity.WarnResp != nil {
		if entity.WarnResp.Id_contact_type == 1 {
			SendEmailReplyRequestAcknowledge(entity.WarnResp, db)
		} else {
			SendWhatsappReplyRequestAcknowledge(entity, db)
		}

		email_content = strings.Replace(email_content, "{{reply_url}}", ShortUrl(models.URL_REPLY+"/"+entity.WarnResp.Resp_hash), 1)
		email_content = strings.Replace(email_content, "{{reply_msg}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_REPLY_NOW"), 1)
	}

	the7messages := GetRandomMessagesByLanguage(7, entity.Lang_key, db)

	for key, value := range the7messages {

		email_content = strings.Replace(email_content, "{{suggest_msg"+fmt.Sprint(key+1)+"}}", value.Name, 1)
		email_content = strings.Replace(email_content, "{{suggest_link"+fmt.Sprint(key+1)+"}}", ShortUrl(models.URL_WARNABRODA+"/#/"+fmt.Sprint(value.Id)), 1)
	}

	return email_content

}
Ejemplo n.º 12
0
func DoLogout(enc Encoder, session sessions.Session, user sessionauth.User, db gorp.SqlExecutor) (int, string) {

	status := &models.DefaultStruct{
		Id:       http.StatusOK,
		Name:     messages.GetLocaleMessage("en", "MSG_LOGIN_REQUIRED"),
		Lang_key: "en",
	}

	if user.IsAuthenticated() {

		sessionauth.Logout(session, user)
		session.Clear()
		status.Name = messages.GetLocaleMessage("en", "MSG_SUCCESSFUL_LOGOUT")
	}

	updateUser := UserById(user.UniqueId().(int), db)

	updateUser.Authenticated = false
	db.Update(updateUser)

	return http.StatusOK, Must(enc.EncodeOne(status))
}
Ejemplo n.º 13
0
// Receives a warning tru, inserts the request and process the warning and then respond to the interface
//TODO: use (session sessions.Session, r *http.Request) to prevent flood
func AddWarning(entity models.Warning, enc Encoder, db gorp.SqlExecutor, r *http.Request) (int, string) {
	fmt.Println("AddWarning")
	if isInvalidWarning(&entity) {
		return http.StatusBadRequest, Must(enc.EncodeOne(entity))
	}

	status := &models.DefaultStruct{
		Id:       http.StatusOK,
		Name:     messages.GetLocaleMessage(entity.Lang_key, "MSG_WARNING_SENT_SUCCESS"),
		Lang_key: entity.Lang_key,
		Type:     models.MSG_TYPE_WARNING,
	}

	entity.Sent = false
	entity.Created_by = "system"
	//entity.Created_date = time.Now().String()

	err := db.Insert(&entity)
	checkErr(err, "INSERT WARNING ERROR")
	if err != nil {
		return http.StatusBadRequest, Must(enc.EncodeOne(entity))
	}

	ingnored := InIgnoreList(db, entity.Contact)

	if ingnored != nil && ingnored.Confirmed {
		status = &models.DefaultStruct{
			Id:       http.StatusBadRequest,
			Name:     messages.GetLocaleMessage(entity.Lang_key, "MSG_IGNORED_USER"),
			Lang_key: entity.Lang_key,
			Type:     models.MSG_TYPE_WARNING,
		}
	} else {
		processWarn(&entity, db, status)
	}

	return http.StatusCreated, Must(enc.EncodeOne(status))
}
Ejemplo n.º 14
0
func sendSMSWarn(entity *models.Warning, db gorp.SqlExecutor) {

	message := SelectMessage(db, entity.Id_message)
	sms_message := messages.GetLocaleMessage(entity.Lang_key, "MSG_SMS_GREET") + "\r\n" + "'" + message.Name + "'"
	if entity.WarnResp == nil {
		sms_message += "\r\n" + messages.GetLocaleMessage(entity.Lang_key, "MSG_FOOTER")
	} else {

		if entity.WarnResp.Id_contact_type == 1 {
			go SendEmailReplyRequestAcknowledge(entity.WarnResp, db)
		} else {
			go SendWhatsappReplyRequestAcknowledge(entity, db)
		}

		sms_message += "\r\n" + messages.GetLocaleMessage(entity.Lang_key, "MSG_REPLY_FOOTER") + " " + ShortUrl(models.URL_REPLY+"/"+entity.WarnResp.Resp_hash)
	}

	sms := &models.SMS{
		CredencialKey: os.Getenv("WARNACREDENCIAL"),
		Content:       sms_message,
		URLPath:       models.URL_MAIN_MOBILE_PRONTO,
		Scheme:        "http",
		Host:          models.URL_DOMAIN_MOBILE_PRONTO,
		Project:       os.Getenv("WARNAPROJECT"),
		AuxUser:       "WAB",
		MobileNumber:  strings.Replace(entity.Contact, "+", "", 1),
		SendProject:   "N",
	}

	sent, response := SendSMS(sms)

	if sent {
		entity.Message = response
		UpdateWarningSent(entity, db)
	}

}
Ejemplo n.º 15
0
func SendWhatsappReplyDone(entity *models.Warning, db gorp.SqlExecutor) {
	fmt.Println("SendWhatsappReplyDone")

	message := SelectMessage(db, entity.Id_message)

	whatsappMsg := messages.GetLocaleMessage(entity.Lang_key, "MSG_SMS_HEADER") + " \r\n \r\n"

	mainBodyMsg := messages.GetLocaleMessage(entity.Lang_key, "MSG_REPLY_BODY_MAIN")
	mainBodyMsg = strings.Replace(mainBodyMsg, "{{sent_msg}}", "'"+message.Name+"'", 1)
	mainBodyMsg = strings.Replace(mainBodyMsg, "{{contact_msg}}", "'"+entity.Contact+"'", 1)

	whatsappMsg += mainBodyMsg + " \r\n \r\n"
	whatsappMsg += messages.GetLocaleMessage(entity.Lang_key, "MSG_REPLY_BODY_LINK") + " \r\n \r\n"
	whatsappMsg += ShortUrl(models.URL_REPLY + "/" + entity.WarnResp.Read_hash)

	whatsMsg := models.Whatsapp{
		Id:      entity.WarnResp.Id,
		Number:  strings.Replace(entity.WarnResp.Reply_to, "+", "", 1),
		Message: whatsappMsg,
		Type:    models.MSG_TYPE_REPLY,
	}

	sendWhatsapp(&whatsMsg)
}
Ejemplo n.º 16
0
func ProcessWhatsapp(entity *models.Warning, db gorp.SqlExecutor) {
	fmt.Println("ProcessWhatsapp")

	var message string
	structMsg := SelectMessage(db, entity.Id_message)
	if IsLoadedInRedis(entity.Contact) {

		message = messages.GetLocaleMessage(entity.Lang_key, "MSG_WHATSAPP_HEADER_DEFAULT") + "\r\n \r\n"
		message += "'" + structMsg.Name + ".'\r\n \r\n"

		if entity.WarnResp != nil {
			message += messages.GetLocaleMessage(entity.Lang_key, "MSG_WHATSAPP_REPLY_DEFAULT") + " " + ShortUrl(models.URL_REPLY+"/"+entity.WarnResp.Resp_hash) + "\r\n \r\n"

			processReply(entity, db)

		} else {
			message += messages.GetLocaleMessage(entity.Lang_key, "MSG_WHATSAPP_WITHOUT_REPLY") + "\r\n"

		}

		message += strings.Replace(messages.GetLocaleMessage(entity.Lang_key, "MSG_WHATSAPP_FOOTER_DEFAULT"), "{{url_ignoreme}}", models.URL_IGNORE_REQUEST+"/"+entity.Contact, 1)

	} else {

		message = messages.GetLocaleMessage(entity.Lang_key, "MSG_WHATSAPP_HEADER_FIRSTTIMER") + "\r\n \r\n"
		message += "'" + structMsg.Name + ".'\r\n \r\n"

		if entity.WarnResp != nil {
			message += messages.GetLocaleMessage(entity.Lang_key, "MSG_WHATSAPP_REPLY_FIRSTTIMER") + " " + ShortUrl(models.URL_REPLY+"/"+entity.WarnResp.Resp_hash) + "\r\n \r\n"

			processReply(entity, db)

		}

		message += strings.Replace(messages.GetLocaleMessage(entity.Lang_key, "MSG_WHATSAPP_FOOTER_FIRSTTIMER"), "{{url_ignoreme}}", models.URL_IGNORE_REQUEST+"/"+entity.Contact, 1)

	}

	AddPhoneToRedis(entity.Contact)

	whatsMsg := models.Whatsapp{
		Id:      entity.Id,
		Number:  strings.Replace(entity.Contact, "+", "", 1),
		Message: message,
		Type:    models.MSG_TYPE_WARNING,
	}

	sendWhatsapp(&whatsMsg)
}
Ejemplo n.º 17
0
func SendWhatsappReplyRequestAcknowledge(entity *models.Warning, db gorp.SqlExecutor) {
	fmt.Println("SendWhatsappReplyRequestAcknowledge")

	msg := SelectMessage(db, entity.Id_message)

	replyRequest := messages.GetLocaleMessage(entity.Lang_key, "MSG_WHATSAPP_REPLY_REQUEST")
	replyRequest = strings.Replace(replyRequest, "{{msg}}", msg.Name, 1)
	replyRequest = strings.Replace(replyRequest, "{{contact}}", entity.Contact, 1) + " " + entity.WarnResp.Resp_hash[:6] + "\r\n" + messages.GetLocaleMessage(entity.Lang_key, "MSG_FOOTER")

	replyToWhatsMsg := models.Whatsapp{
		Id:      entity.Id,
		Number:  strings.Replace(entity.WarnResp.Reply_to, "+", "", 1),
		Message: replyRequest,
		Type:    "warning-reply",
	}

	sendWhatsapp(&replyToWhatsMsg)

}
Ejemplo n.º 18
0
// send a SMS with the confirmation code to confirm the ignored contact
func sendSMSIgnoreme(entity *models.Ignore_List, db gorp.SqlExecutor) {

	sms := &models.SMS{
		CredencialKey: os.Getenv("WARNACREDENCIAL"),
		Content:       strings.Replace(messages.GetLocaleMessage(entity.Lang_key, "MSG_SMS_IGNORE_CONFIRMATION_REQUEST"), "{{url}}", models.URL_IGNORE_REQUEST, 1) + entity.Confirmation_code,
		URLPath:       models.URL_MAIN_MOBILE_PRONTO,
		Scheme:        "http",
		Host:          models.URL_DOMAIN_MOBILE_PRONTO,
		Project:       os.Getenv("WARNAPROJECT"),
		AuxUser:       "WAB",
		MobileNumber:  strings.Replace(entity.Contact, "+", "", 1),
		SendProject:   "N",
	}

	sent, response := SendSMS(sms)

	if sent {
		entity.Message = response
		UpdateIgnoreList(entity, db)
	}
}
Ejemplo n.º 19
0
func sendReplyAcknowledgeSetup(email string, entity *models.WarningResp, db gorp.SqlExecutor) string {
	fmt.Println("sendReplyAcknowledgeSetup")

	var email_content string
	email_content = strings.Replace(email, "{{subject}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_SUBJECT_REPLY_REQUEST"), 1)
	email_content = strings.Replace(email_content, "{{broda_msg_header_greet}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_REPLY_SENDER_MSG"), 1)
	email_content = strings.Replace(email_content, "{{warning}}", entity.Reply_to, 1)
	email_content = strings.Replace(email_content, "{{broda_msg_footer_greet}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_FOOTER"), 1)
	email_content = strings.Replace(email_content, "{{warnabroda_headline}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_REPLY_HEADLINE"), 1)
	email_content = strings.Replace(email_content, "{{follow_us}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_FOLLOW_US"), 1)
	email_content = strings.Replace(email_content, "{{terms}}", messages.GetLocaleMessage(entity.Lang_key, "MSG_TERMS_SERVICE"), 1)

	the7messages := GetRandomMessagesByLanguage(7, entity.Lang_key, db)

	for key, value := range the7messages {

		email_content = strings.Replace(email_content, "{{suggest_msg"+fmt.Sprint(key+1)+"}}", value.Name, 1)
		email_content = strings.Replace(email_content, "{{suggest_link"+fmt.Sprint(key+1)+"}}", ShortUrl(models.URL_WARNABRODA+"/#/"+fmt.Sprint(value.Id)), 1)
	}

	return email_content

}
Ejemplo n.º 20
0
// Add the request to be ignored for future warnings, it requires further confimation
func AddIgnoreList(entity models.Ignore_List, w http.ResponseWriter, enc Encoder, db gorp.SqlExecutor) (int, string) {

	if isInvalidIgnoreList(&entity) {
		return http.StatusBadRequest, Must(enc.EncodeOne(entity))
	}

	status := &models.DefaultStruct{
		Id:       http.StatusOK,
		Name:     messages.GetLocaleMessage(entity.Lang_key, "MSG_CONFIRM_IGNOREME"),
		Lang_key: entity.Lang_key,
		Type:     models.MSG_TYPE_IGNORE,
	}

	if MoreThanTwoRequestByIp(db, &entity) {
		status = &models.DefaultStruct{
			Id:       http.StatusBadRequest,
			Name:     messages.GetLocaleMessage(entity.Lang_key, "MSG_TOO_MANY_IGNOREME_REQUESTS"),
			Lang_key: entity.Lang_key,
			Type:     models.MSG_TYPE_IGNORE,
		}
		return http.StatusUnauthorized, Must(enc.EncodeOne(status))
	}

	ingnored := InIgnoreList(db, entity.Contact)

	if ingnored != nil && ingnored.Confirmed {

		status = &models.DefaultStruct{
			Id:       http.StatusBadRequest,
			Name:     messages.GetLocaleMessage(entity.Lang_key, "MSG_CONTACT_ALREADY_IGNORED"),
			Lang_key: entity.Lang_key,
		}

		return http.StatusUnauthorized, Must(enc.EncodeOne(status))

	} else if ingnored != nil {
		status = &models.DefaultStruct{
			Id:       http.StatusBadRequest,
			Name:     messages.GetLocaleMessage(entity.Lang_key, "MSG_IGNORE_REQUEST_EXISTS"),
			Lang_key: entity.Lang_key,
		}

		return http.StatusUnauthorized, Must(enc.EncodeOne(status))
	}

	rand.Seed(time.Now().UTC().UnixNano())
	entity.Created_by = "user"
	entity.Confirmed = false
	entity.Confirmation_code = randomString(6)

	errIns := db.Insert(&entity)
	checkErr(errIns, "INSERT IGNORE FAIL")

	if strings.Contains(entity.Contact, "@") {
		status.Name += " via e-mail."
		go SendEmailIgnoreme(&entity, db)
	} else if strings.Contains(entity.Contact, "+55") {
		status.Name += " via SMS."
		go sendSMSIgnoreme(&entity, db)
	}

	//w.Header().Set("Location", fmt.Sprintf("/warnabroda/ignore-list/%d", entity.Id))
	return http.StatusCreated, Must(enc.EncodeOne(status))
}