本文整理匯總了Golang中github.com/silvasur/mailremind/model.User.Location方法的典型用法代碼示例。如果您正苦於以下問題:Golang User.Location方法的具體用法?Golang User.Location怎麽用?Golang User.Location使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/silvasur/mailremind/model.User
的用法示例。
在下文中一共展示了User.Location方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: schedToSchedTL
func schedToSchedTL(sched schedule.Schedule, u model.User) scheduleTpldata {
loc := u.Location()
schedtl := scheduleTpldata{
Start: sched.Start.In(loc).Format(bestTimeFmtEver),
}
if f := sched.Freq; f.Count > 0 {
schedtl.RepetitionEnabled = true
schedtl.Count = int(f.Count)
switch f.Unit {
case schedule.Minute:
schedtl.UnitIsMinute = true
case schedule.Hour:
schedtl.UnitIsHour = true
case schedule.Day:
schedtl.UnitIsDay = true
case schedule.Week:
schedtl.UnitIsWeek = true
case schedule.Month:
schedtl.UnitIsMonth = true
case schedule.Year:
schedtl.UnitIsYear = true
}
}
if end := sched.End; !end.IsZero() {
schedtl.EndEnabled = true
schedtl.End = end.In(loc).Format(bestTimeFmtEver)
}
return schedtl
}
示例2: jobToTpldata
func jobToTpldata(job model.Job, user model.User) *jobTpldata {
excerpt := string(job.Content())
if len(excerpt) > 100 {
excerpt = string([]rune(excerpt)[0:100]) + " (...)"
}
return &jobTpldata{
ID: job.ID().String(),
Subject: job.Subject(),
Excerpt: excerpt,
Next: job.Next().In(user.Location()).Format("2006-Jan-02 15:04:05"),
}
}
示例3: interpretForm
func (jt *jobeditTpldata) interpretForm(form url.Values, u model.User) (subject string, content []byte, ms schedule.MultiSchedule, ok bool) {
loc := u.Location()
l1 := len(form["Start"])
l2 := len(form["RepetitionEnabled"])
l3 := len(form["Count"])
l4 := len(form["Unit"])
l5 := len(form["EndEnabled"])
l6 := len(form["End"])
if (l1 != l2) || (l2 != l3) || (l3 != l4) || (l4 != l5) || (l5 != l6) {
jt.Error = "Form corrupted. Changes were not saved"
ok = false
return
}
subject = form.Get("Subject")
content = []byte(form.Get("Content"))
jt.Subject = subject
jt.Content = string(content)
ok = true
for i, _start := range form["Start"] {
if i >= maxSchedules {
break
}
if _start == "" {
continue
}
start, err := time.ParseInLocation(bestTimeFmtEver, _start, loc)
if err != nil {
ok = false
continue
}
count := uint64(0)
var unit schedule.TimeUnit
var end time.Time
if form["RepetitionEnabled"][i] == "yes" {
if count, err = strconv.ParseUint(form["Count"][i], 10, 64); err != nil {
ok = false
continue
}
switch form["Unit"][i] {
case "Minute":
unit = schedule.Minute
case "Hour":
unit = schedule.Hour
case "Day":
unit = schedule.Day
case "Week":
unit = schedule.Week
case "Month":
unit = schedule.Month
case "Year":
unit = schedule.Year
default:
ok = false
continue
}
if form["EndEnabled"][i] == "yes" {
if end, err = time.ParseInLocation(bestTimeFmtEver, form["End"][i], loc); err != nil {
ok = false
continue
}
}
}
sched := schedule.Schedule{
Start: start,
Freq: schedule.Frequency{
Count: uint(count),
Unit: unit,
},
End: end,
}
ms = append(ms, sched)
jt.Schedules[i] = schedToSchedTL(sched, u)
}
if !ok {
jt.Error = "Some schedules were wrong (wrong time format, negative repetition counts)"
return
}
if len(ms) == 0 {
jt.Error = "No schedule."
ok = false
}
return
}
示例4: settings
func settings(user model.User, sess *sessions.Session, req *http.Request) (interface{}, model.User) {
if user == nil {
return &settingsTpldata{Error: "You need to be logged in to do that.", Fatal: true}, nil
}
outdata := &settingsTpldata{Timezones: make(map[string]bool)}
tznow := user.Location().String()
for _, tz := range timeLocs {
outdata.Timezones[tz] = (tz == tznow)
}
if req.Method != "POST" {
return outdata, user
}
if err := req.ParseForm(); err != nil {
outdata.Error = "Could not parse form"
return outdata, user
}
switch req.FormValue("M") {
case "setpasswd":
if req.FormValue("Password") == "" {
outdata.Error = "Password must not be empty."
return outdata, user
}
if req.FormValue("Password") != req.FormValue("RepeatPassword") {
outdata.Error = "Passwords must be equal."
return outdata, user
}
hash, err := bcrypt.GenerateFromPassword([]byte(req.FormValue("Password")), bcrypt.DefaultCost)
if err != nil {
log.Printf("Error hashing password: %s", err)
outdata.Error = "Error while saving password."
return outdata.Error, user
}
if err := user.SetPWHash(hash); err != nil {
log.Printf("Error setting pwhash: %s", err)
outdata.Error = "Could not save new password."
} else {
outdata.Success = "Password changed"
}
case "settimezone":
loc, err := time.LoadLocation(req.FormValue("Timezone"))
if err != nil {
outdata.Error = "Unknown Timezone"
return outdata, user
}
if err := user.SetLocation(loc); err != nil {
log.Printf("Error setting location: %s", err)
outdata.Error = "Could not save new timezone."
} else {
outdata.Success = "New timezone saved."
}
}
return outdata, user
}