本文整理汇总了Golang中github.com/astaxie/beego.UrlFor函数的典型用法代码示例。如果您正苦于以下问题:Golang UrlFor函数的具体用法?Golang UrlFor怎么用?Golang UrlFor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UrlFor函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Profile
// 个人信息
func (this *MainController) Profile() {
beego.ReadFromRequest(&this.Controller)
user, _ := models.UserGetById(this.userId)
if this.isPost() {
flash := beego.NewFlash()
user.Email = this.GetString("email")
user.Update()
password1 := this.GetString("password1")
password2 := this.GetString("password2")
if password1 != "" {
if len(password1) < 6 {
flash.Error("密码长度必须大于6位")
flash.Store(&this.Controller)
this.redirect(beego.UrlFor(".Profile"))
} else if password2 != password1 {
flash.Error("两次输入的密码不一致")
flash.Store(&this.Controller)
this.redirect(beego.UrlFor(".Profile"))
} else {
user.Salt = string(utils.RandomCreateBytes(10))
user.Password = libs.Md5([]byte(password1 + user.Salt))
user.Update()
}
}
flash.Success("修改成功!")
flash.Store(&this.Controller)
this.redirect(beego.UrlFor(".Profile"))
}
this.Data["pageTitle"] = "个人信息"
this.Data["user"] = user
this.display()
}
示例2: DoRegister
func (this *AuthController) DoRegister() {
this.CheckRequestFrequency(3, 15, 30)
this.Layout = "layout.html"
this.TplNames = "register.html"
valid := validation.Validation{}
form := RegisterForm{}
if err := this.ParseForm(&form); err != nil {
beego.Error(err)
}
b, err := valid.Valid(form)
if err != nil {
beego.Error(err)
}
if !b {
this.registerPageWithErrors(form, valid.Errors)
return
}
//验证用户名
user := models.User{Username: form.Username}
if err := user.ValidUsername(); err != nil {
valid.SetError("username", err.Error())
this.registerPageWithErrors(form, valid.Errors)
return
} else {
if user.Read("Username") == nil {
valid.SetError("username", fmt.Sprintf("%s已被使用,请使用其他用户名!", form.Username))
this.registerPageWithErrors(form, valid.Errors)
return
}
}
//验证email未被注册
user.Email = form.Email
if user.Read("Email") == nil {
valid.SetError("email", "已被使用,请直接使用此电邮登录")
this.registerPageWithErrors(form, valid.Errors)
return
}
//通过所有验证
actCode, _ := user.GenerateActivateCode()
user.SetPassword(form.Password)
if err := user.Insert(); err != nil {
beego.Error(err)
this.Abort("500")
return
}
sub := sendcloud.NewSubstitution()
sub.AddTo(user.Email)
sub.AddSub("%appname%", setting.AppName)
sub.AddSub("%name%", user.Username)
sub.AddSub("%url%", setting.AppUrl+beego.UrlFor("AuthController.Activate", ":code", actCode))
if err := setting.Sendcloud.SendTemplate("gotalk_register", setting.AppName+"欢迎你", setting.From, setting.FromName, sub); err != nil {
beego.Error(err)
}
this.FlashWrite("notice", fmt.Sprintf("注册成功!欢迎你, %s。建议你再花点时间上传头像、验证电子邮件!", user.Username))
this.LogUserIn(&user, false)
userEditUrl := beego.UrlFor("UserController.Edit", ":username", user.Username)
this.Redirect(userEditUrl, 302)
return
}
示例3: Post
//add new user
func (c *User) Post() {
var v M.ValidMap
var err error
var msg string
c.Data["xsrfdata"] = template.HTML(c.XsrfFormHtml())
c.TplNames = "user/form.tpl"
d := M.User{}
flash := beego.NewFlash()
err = c.ParseForm(&d)
if err != nil {
beego.Error(err)
flash.Notice(T("internal"))
flash.Store(&c.Controller)
c.Redirect(beego.UrlFor("User.Index"), 302)
return
}
d.GToken = sql.NullString{c.Ctx.Request.Form["gtoken"][0], true}
d.Active = true
if d.Id == 0 {
v, err = DM.Insert(&d)
msg = T("user_created")
} else {
v, err = DM.Update(&d)
msg = T("user_updated", map[string]interface{}{"Login": d.Login})
c.Data["isEdit"] = true
}
if err != nil {
beego.Error(err)
}
if !v.HasErrors() {
flash.Notice(msg)
flash.Store(&c.Controller)
c.Redirect(beego.UrlFor("User.Index"), 302)
return
}
M.ExpandFormErrors(&v, c.Data)
c.Data["user"] = d
c.Data["roles"] = c.rolesList()
}
示例4: Get
// update criteria
func (c *Crit) Get() {
c.Data["isEdit"] = true
c.TplNames = "crit/form.tpl"
c.Data["xsrfdata"] = template.HTML(c.XsrfFormHtml())
id, err := strconv.Atoi(c.Ctx.Input.Param(":id"))
if err != nil {
beego.Error(err)
id = 0
}
var crit M.Crit
if DM.FindByPk(&crit, id) != nil {
flash := beego.NewFlash()
flash.Notice(T("crit_not_found"))
flash.Store(&c.Controller)
c.Redirect(beego.UrlFor("Crit.Index"), 302)
return
}
var deps []M.Dep
err = DM.FindAll(&M.Dep{}, &deps, M.Sf{"Id", "Title"}, M.Where{})
if err != nil {
beego.Error(err)
}
c.Data["deps"] = deps
c.Data["crit"] = crit
}
示例5: Remove
//remove criteria
func (c *Crit) Remove() {
s := T("crit_not_found")
crit := M.Crit{}
id, err := strconv.Atoi(c.Ctx.Input.Param(":id"))
if err == nil {
err = DM.DeleteByPk(&crit, id)
}
if err != nil {
beego.Error(err)
} else {
s = T("crit_removed", map[string]interface{}{"Title": crit.Title})
}
if c.IsAjax() {
c.Data["json"] = RJson{s, err == nil}
return
}
flash := beego.NewFlash()
flash.Notice(s)
flash.Store(&c.Controller)
c.Redirect(beego.UrlFor("Crit.Index"), 302)
}
示例6: Logs
// 任务执行日志列表
func (this *TaskController) Logs() {
taskId, _ := this.GetInt("id")
page, _ := this.GetInt("page")
if page < 1 {
page = 1
}
task, err := models.TaskGetById(taskId)
if err != nil {
this.showMsg(err.Error())
}
result, count := models.TaskLogGetList(page, this.pageSize, "task_id", task.Id)
list := make([]map[string]interface{}, len(result))
for k, v := range result {
row := make(map[string]interface{})
row["id"] = v.Id
row["start_time"] = beego.Date(time.Unix(v.CreateTime, 0), "Y-m-d H:i:s")
row["process_time"] = float64(v.ProcessTime) / 1000
row["ouput_size"] = libs.SizeFormat(float64(len(v.Output)))
row["status"] = v.Status
list[k] = row
}
this.Data["pageTitle"] = "任务执行日志"
this.Data["list"] = list
this.Data["task"] = task
this.Data["pageBar"] = libs.NewPager(page, int(count), this.pageSize, beego.UrlFor("TaskController.Logs", "id", taskId), true).ToString()
this.display()
}
示例7: Get
//view concrete user
func (c *User) Get() {
var u M.User
var err error
c.Data["xsrfdata"] = template.HTML(c.XsrfFormHtml())
c.Data["isEdit"] = true
c.TplNames = "user/form.tpl"
id, err := strconv.Atoi(c.Ctx.Input.Param(":id"))
if err == nil {
err = DM.FindByPk(&u, id)
}
if err != nil {
flash := beego.NewFlash()
flash.Notice(T("user_not_found"))
flash.Store(&c.Controller)
c.Redirect(beego.UrlFor("User.Index"), 302)
return
}
c.Data["user"] = u
c.Data["roles"] = c.rolesList()
}
示例8: Remove
func (c *Lang) Remove() {
s := T("lang_not_found")
d := M.Lang{}
id, err := strconv.Atoi(c.Ctx.Input.Param(":id"))
if err == nil {
err = DM.DeleteByPkWithFetch(&d, id)
}
if err == nil {
s = T("lang_removed")
err = c.cleanLang(d.Code)
}
if err != nil {
beego.Error(err)
}
if c.IsAjax() {
c.Data["json"] = RJson{s, err == nil}
return
}
flash := beego.NewFlash()
flash.Notice(s)
flash.Store(&c.Controller)
c.Redirect(beego.UrlFor("Lang.Index"), 302)
}
示例9: Remove
//remove user
func (c *User) Remove() {
s := T("user_not_found")
d := M.User{}
id, err := strconv.Atoi(c.Ctx.Input.Param(":id"))
if err == nil {
err = DM.DeleteByPk(&d, id)
}
if err != nil {
beego.Error(err)
} else {
s = T("user_removed", map[string]interface{}{"Login": d.Login})
}
if c.IsAjax() {
c.Data["json"] = RJson{s, err == nil}
return
}
flash := beego.NewFlash()
flash.Notice(s)
flash.Store(&c.Controller)
c.Redirect(beego.UrlFor("User.Index"), 302)
}
示例10: Edit
//edit candidate
func (c *Cand) Edit() {
flash := beego.NewFlash()
var deps []M.Dep
var err error
if err := DM.FindAll(&M.Dep{}, &deps, M.Sf{}, M.Where{}); err != nil {
beego.Error("Department find error: ", err)
flash.Error(T("internal"))
flash.Store(&c.Controller)
return
}
var id int
if id, err = strconv.Atoi(c.Ctx.Input.Param(":id")); err != nil {
beego.Error(err)
}
var cand M.Cand
if DM.FindByPk(&cand, id) != nil {
flash.Notice(T("nocand"))
flash.Store(&c.Controller)
c.Redirect(beego.UrlFor("Cand.Index"), 302)
return
}
c.Data["cand"] = cand
c.Data["deps"] = deps
c.Data["xsrfdata"] = template.HTML(c.XsrfFormHtml())
}
示例11: Post
//save concrete or new department
func (c *Dep) Post() {
var v M.ValidMap
var err error
var msg string
c.Data["xsrfdata"] = template.HTML(c.XsrfFormHtml())
c.TplNames = "dep/form.tpl"
d := M.Dep{}
flash := beego.NewFlash()
err = c.ParseForm(&d)
if err != nil {
beego.Error(err)
flash.Notice(T("internal"))
flash.Store(&c.Controller)
c.Redirect(beego.UrlFor("Dep.Index"), 302)
return
}
if d.Id == 0 {
v, err = DM.Insert(&d, "Title")
msg = T("dep_created")
} else {
v, err = DM.Update(&d, "Title")
msg = T("dep_updated", map[string]interface{}{"Title": d.Title})
c.Data["isEdit"] = true
}
if err != nil {
beego.Error(err)
}
if !v.HasErrors() {
flash.Notice(msg)
flash.Store(&c.Controller)
c.Redirect(beego.UrlFor("Dep.Index"), 302)
return
}
M.ExpandFormErrors(&v, c.Data)
c.Data["dep"] = d
}
示例12: Get
//show auth form
func (c *Main) Get() {
if c.GetSession("uid") != nil {
c.Redirect(beego.UrlFor("User.Index"), 302)
}
c.Data["xsrfdata"] = template.HTML(c.XsrfFormHtml())
c.TplNames = "loginform.tpl"
c.Data["title"] = "HRKB"
}
示例13: Del
func (this *CompanyController) Del() {
id, _ := strconv.Atoi(this.Ctx.Input.Param(":id"))
beego.Debug("id=", id)
o := orm.NewOrm()
if num, err := o.Delete(&models.Company{Id: int64(id)}); err == nil {
beego.Debug(num)
this.Redirect(beego.UrlFor("CompanyController.Index"), 302)
} else {
beego.Error(err)
}
}
示例14: Store
func (this *CategoryController) Store() {
pid, _ := strconv.Atoi(this.GetString("Pid"))
name := this.GetString("Name")
o := orm.NewOrm()
category := new(models.Category)
category.Pid = int64(pid)
category.Name = name
//category := &models.Category{Pid:int64(pid),Name:name}
o.Insert(category)
this.Redirect(beego.UrlFor("CategoryController.Index"), 302)
}
示例15: List
// 任务列表
func (this *TaskController) List() {
page, _ := this.GetInt("page")
if page < 1 {
page = 1
}
groupId, _ := this.GetInt("groupid")
filters := make([]interface{}, 0)
if groupId > 0 {
filters = append(filters, "group_id", groupId)
}
result, count := models.TaskGetList(page, this.pageSize, filters...)
list := make([]map[string]interface{}, len(result))
for k, v := range result {
row := make(map[string]interface{})
row["id"] = v.Id
row["name"] = v.TaskName
row["cron_spec"] = v.CronSpec
row["status"] = v.Status
row["description"] = v.Description
e := jobs.GetEntryById(v.Id)
if e != nil {
row["next_time"] = beego.Date(e.Next, "Y-m-d H:i:s")
row["prev_time"] = "-"
if e.Prev.Unix() > 0 {
row["prev_time"] = beego.Date(e.Prev, "Y-m-d H:i:s")
} else if v.PrevTime > 0 {
row["prev_time"] = beego.Date(time.Unix(v.PrevTime, 0), "Y-m-d H:i:s")
}
row["running"] = 1
} else {
row["next_time"] = "-"
if v.PrevTime > 0 {
row["prev_time"] = beego.Date(time.Unix(v.PrevTime, 0), "Y-m-d H:i:s")
} else {
row["prev_time"] = "-"
}
row["running"] = 0
}
list[k] = row
}
// 分组列表
groups, _ := models.TaskGroupGetList(1, 100)
this.Data["pageTitle"] = "任务列表"
this.Data["list"] = list
this.Data["groups"] = groups
this.Data["groupid"] = groupId
this.Data["pageBar"] = libs.NewPager(page, int(count), this.pageSize, beego.UrlFor("TaskController.List", "groupid", groupId), true).ToString()
this.display()
}