本文整理匯總了Golang中igps/page.Params.Account方法的典型用法代碼示例。如果您正苦於以下問題:Golang Params.Account方法的具體用法?Golang Params.Account怎麽用?Golang Params.Account使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類igps/page.Params
的用法示例。
在下文中一共展示了Params.Account方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: settings
// settings is the logic implementation of the Settings page.
func settings(p *page.Params) {
p.Custom["ImgFormats"] = imgFormats
fv := p.Request.PostFormValue
if fv("submitSettings") == "" {
// No form submitted. Initial values:
p.Custom["GoogleAccount"] = p.Account.Email
p.Custom["ContactEmail"] = p.Account.ContactEmail
p.Custom["LocationName"] = p.Account.LocationName
if p.Account.LogsPageSize > 0 {
p.Custom["LogsPageSize"] = p.Account.LogsPageSize
}
p.Custom["MapPrevSize"] = p.Account.MapPrevSize
p.Custom["MobMapPrevSize"] = p.Account.MobMapPrevSize
p.Custom["MobMapImgFormat"] = p.Account.MobMapImgFormat
if p.Account.MobPageWidth > 0 {
p.Custom["MobPageWidth"] = p.Account.MobPageWidth
}
return
}
p.Custom["GoogleAccount"] = fv("googleAccount")
p.Custom["ContactEmail"] = fv("contactEmail")
p.Custom["LocationName"] = fv("locationName")
p.Custom["LogsPageSize"] = fv("logsPageSize")
p.Custom["MapPrevSize"] = fv("mapPrevSize")
p.Custom["MobMapPrevSize"] = fv("mobMapPrevSize")
p.Custom["MobMapImgFormat"] = fv("mobMapImgFormat")
p.Custom["MobPageWidth"] = fv("mobPageWidth")
// Checks:
switch {
case !checkGoogleAccounts(p, fv("googleAccount")):
case !checkContactEmail(p, fv("contactEmail")):
case !checkLocationName(p, fv("locationName")):
case !checkLogsPageSize(p, fv("logsPageSize")):
case !checkMapPrevSize(p, "Map preview size", fv("mapPrevSize")):
case !checkMapPrevSize(p, "Mobile Map preview size", fv("mobMapPrevSize")):
case !checkMobMapImgFormat(p, fv("mobMapImgFormat")):
case !checkMobPageWidth(p, fv("mobPageWidth")):
}
if p.ErrorMsg != nil {
return
}
// All data OK, save Account
c := p.AppCtx
// Create a "copy" of the account, only set it if saving succeeds.
// Have to set ALL fields (else their values would be lost when (re)saved)!
var logsPageSize, mobPageWidth int
if fv("logsPageSize") != "" {
logsPageSize, _ = strconv.Atoi(fv("logsPageSize"))
}
if fv("mobPageWidth") != "" {
mobPageWidth, _ = strconv.Atoi(fv("mobPageWidth"))
}
acc := ds.Account{
Email: p.User.Email, Lemail: strings.ToLower(p.User.Email), UserID: p.User.ID,
ContactEmail: fv("contactEmail"), LocationName: fv("locationName"), LogsPageSize: logsPageSize,
MapPrevSize: fv("mapPrevSize"), MobMapPrevSize: fv("mobMapPrevSize"),
MobMapImgFormat: fv("mobMapImgFormat"), MobPageWidth: mobPageWidth,
Created: p.Account.Created, KeyID: p.Account.KeyID,
}
key := datastore.NewKey(c, ds.ENameAccount, "", p.Account.KeyID, nil)
if _, p.Err = datastore.Put(c, key, &acc); p.Err == nil {
p.InfoMsg = "Settings saved successfully."
p.Account = &acc
// Update cache with the new Account
cache.CacheAccount(c, p.Account)
}
}
示例2: register
// 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 <[email protected]>"
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)
}
}