Ejemplo n.º 1
0
func sendErrorMail(c appengine.Context, err error) {
	msg := &mail.Message{
		Sender:  "Flat Scan Sender <*****@*****.**>",
		Subject: "Error",
		Body:    err.Error(),
	}

	c.Errorf("%s", msg.Body)
	err = mail.SendToAdmins(c, msg)
}
Ejemplo n.º 2
0
Archivo: api.go Proyecto: beaubol/cyph
func signup(h HandlerArgs) (interface{}, int) {
	isNewSignup := false

	betaSignup := getBetaSignupFromRequest(h)

	if strings.Contains(betaSignup.Email, "@") {
		key := datastore.NewKey(h.Context, "BetaSignup", betaSignup.Email, 0, nil)

		existingBetaSignup := new(BetaSignup)

		if err := datastore.Get(h.Context, key, existingBetaSignup); err == nil {
			if existingBetaSignup.Comment != "" {
				betaSignup.Comment = existingBetaSignup.Comment
			}
			if existingBetaSignup.Country != "" {
				betaSignup.Country = existingBetaSignup.Country
			}
			if existingBetaSignup.Language != "" {
				betaSignup.Language = existingBetaSignup.Language
			}
			if existingBetaSignup.Name != "" {
				betaSignup.Name = existingBetaSignup.Name
			}
			if existingBetaSignup.Referer != "" {
				betaSignup.Referer = existingBetaSignup.Referer
			}
			if existingBetaSignup.Time != 0 {
				betaSignup.Time = existingBetaSignup.Time
			}
		} else {
			isNewSignup = true
		}

		if _, err := datastore.Put(h.Context, key, &betaSignup); err != nil {
			return err.Error(), http.StatusInternalServerError
		}

		jsonBetaSignup, _ := json.Marshal(betaSignup)
		mail.SendToAdmins(h.Context, &mail.Message{
			Sender:  "*****@*****.**",
			Subject: "NEW SIGNUP LADS",
			Body:    string(jsonBetaSignup),
		})
	}

	return isNewSignup, http.StatusOK
}
Ejemplo n.º 3
0
func sendMail(to []string, cc []string, bcc []string, msg *Message) error {
	c, ok := msg.Context.(appengine.Context)
	if !ok {
		return errNoContext
	}
	var toAdmins bool
	gaeMsg := &mail.Message{
		Sender:   msg.From,
		ReplyTo:  msg.ReplyTo,
		To:       prepareAddrs(to, &toAdmins),
		Cc:       prepareAddrs(cc, &toAdmins),
		Bcc:      prepareAddrs(bcc, &toAdmins),
		Subject:  msg.Subject,
		Body:     msg.TextBody,
		HTMLBody: msg.HTMLBody,
		Headers:  make(nmail.Header),
	}
	for _, v := range msg.Attachments {
		gaeMsg.Attachments = append(gaeMsg.Attachments, mail.Attachment{
			Name:      v.Name,
			Data:      v.Data,
			ContentID: v.ContentID,
		})
	}
	for _, v := range allowedHeaders {
		if value := msg.Headers[v]; value != "" {
			gaeMsg.Headers[v] = append(gaeMsg.Headers[v], value)
		}
	}
	if toAdmins {
		if err := mail.SendToAdmins(c, gaeMsg); err != nil {
			return nil
		}
	}
	return mail.Send(c, gaeMsg)
}
Ejemplo n.º 4
0
func handler(w http.ResponseWriter, r *http.Request) {

	c := appengine.NewContext(r)

	var err error
	var summaries *PlayerSummariesResult
RETRY:
	for i := 0; i < 3; i++ {
		summaries, err = fetchPlayerSummaries(c)
		if err == nil {
			break RETRY
		}
	}
	if err != nil {
		c.Errorf("failed to retrieve player status: %v", err)
		return
	}

	for _, playerSummary := range summaries.Response.Players {

		playerName := playerSummary.Personaname

		online := playerSummary.Gameextrainfo == "Team Fortress 2"

		if online {
			c.Debugf("%v %s is Online", playerName, time.Now())
		} else {
			c.Debugf("%v %s is Offline", playerName, time.Now())
		}

		record, err := GetRecord(c, playerSummary.Steamid)
		if err != nil {
			c.Errorf("failure to get record %v", err)
			return
		}

		newlyOnline := online && !record.Online
		newlyOffline := !online && record.Online

		if newlyOnline || newlyOffline {
			record.Online = online
			err = SaveRecord(c, record)
			if err != nil {
				c.Errorf("failure to save record %v", err)
				return
			}
		}

		if newlyOnline {
			msg := &mail.Message{
				Sender:  "*****@*****.**",
				Subject: fmt.Sprintf("%s is playing Team Fortress 2", playerName),
			}
			if err := mail.SendToAdmins(c, msg); err != nil {
				c.Errorf("Couldn't send email: %v", err)
				return
			}
			c.Debugf("Sending email")
		}

	}
}