Пример #1
0
// CacheAccount puts the specified Account into the cache (memcache).
func CacheAccount(c appengine.Context, acc *ds.Account) {
	mk := prefixAccForUID + acc.UserID

	if err := memcache.Set(c, &memcache.Item{Key: mk, Value: acc.Encode(), Expiration: cachedAccExpiration}); err != nil {
		c.Warningf("Failed to set %s in memcache: %v", mk, err)
	}
}
Пример #2
0
// register is the logic implementation of the Register page.
func register(p *page.Params) {
	// Register page is special. Unlike with other pages we do have to check User and Account here
	// Because even though Register page works with User, logged in user is not required for this page!

	// User might have logged out on a separate tab
	if p.User == nil {
		return
	}
	// User might have registered on a different tab
	if p.Account != nil {
		return
	}

	fv := p.Request.PostFormValue

	if fv("submitRegister") == "" {
		// No form submitted. Initial values:
		p.Custom["GoogleAccount"] = p.User.Email
		return
	}

	p.Custom["GoogleAccount"] = fv("googleAccount")
	p.Custom["ContactEmail"] = fv("contactEmail")
	p.Custom["AcceptTermsAndPolicy"] = fv("acceptTermsAndPolicy")

	// Checks:
	switch {
	case !checkGoogleAccounts(p, fv("googleAccount")):
	case !checkContactEmail(p, fv("contactEmail")):
	case !checkAcceptTermsAndPolicy(p, fv("acceptTermsAndPolicy")):
	}

	// UNTIL PROJECT GOES PUBLIC, DISABLE REGISTRATION:
	if !appengine.IsDevAppServer() && p.ErrorMsg == nil {
		p.ErrorMsg = "REGISTRATION IS CURRENTLY DISABLED! Contact the administrator if you would like to register!"
		return
	}
	// END OF: UNTIL PROJECT GOES PUBLIC, DISABLE REGISTRATION

	if p.ErrorMsg != nil {
		return
	}

	// All data OK, save new Account
	c := p.AppCtx
	acc := ds.Account{Email: p.User.Email, Lemail: strings.ToLower(p.User.Email), UserID: p.User.ID, ContactEmail: fv("contactEmail"), Created: time.Now()}
	var key *datastore.Key
	if key, p.Err = datastore.Put(c, datastore.NewIncompleteKey(c, ds.ENameAccount, nil), &acc); p.Err == nil {
		p.Custom["Created"] = true
		acc.KeyID = key.IntID()
		p.Account = &acc
		// Put new Account into the cache
		cache.CacheAccount(c, p.Account)
	}

	// Send registration email (Account info email)
	const adminEmail = "Andras Belicza <*****@*****.**>"
	msg := &mail.Message{
		Sender:  adminEmail,
		To:      []string{acc.Email},
		Bcc:     []string{adminEmail},
		ReplyTo: adminEmail,
		Subject: "[IczaGPS] Account Info",
		Body:    fmt.Sprintf(accountInfoMail, acc.Email),
	}
	if len(acc.ContactEmail) > 0 {
		msg.Cc = []string{acc.ContactEmail}
	}
	if err := mail.Send(c, msg); err == nil {
		c.Infof("Sent successful registration email.")
	} else {
		c.Errorf("Couldn't send email: %v", err)
	}
}