本文整理匯總了Golang中github.com/easykoo/go-blog/middleware.Context.AddMessage方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.AddMessage方法的具體用法?Golang Context.AddMessage怎麽用?Golang Context.AddMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/easykoo/go-blog/middleware.Context
的用法示例。
在下文中一共展示了Context.AddMessage方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SaveBlog
func SaveBlog(ctx *middleware.Context, blog model.Blog) {
if blog.Title == "" || blog.Content == "" {
ctx.AddError(Translate(ctx.S.Get("Lang").(string), "message.error.save.failed"))
} else {
tags := ctx.R.PostForm["tags"]
blog.SetTags(tags)
signedUser := ctx.S.Get("SignedUser").(model.User)
blog.UpdateUser = signedUser.Username
if blog.Version == 0 {
blog.State = "DRAFT"
blog.Priority = 5
blog.Author = signedUser
blog.CreateUser = signedUser.Username
err := blog.Insert()
PanicIf(err)
} else {
err := blog.Update()
PanicIf(err)
}
dbBlog, err := blog.GetBlogById()
PanicIf(err)
ctx.Set("Blog", dbBlog)
ctx.AddMessage(Translate(ctx.S.Get("Lang").(string), "message.save.success"))
}
tags, err := blog.GetAllTags()
PanicIf(err)
ctx.Set("Tags", tags)
ctx.HTML(200, "blog/edit", ctx)
}
示例2: RegisterHandler
func RegisterHandler(ctx *middleware.Context, formErr binding.Errors, user model.UserRegisterForm) {
switch ctx.R.Method {
case "POST":
ctx.JoinFormErrors(formErr)
if !ctx.HasError() {
dbUser := model.User{Username: user.Username, Password: user.Password, Email: user.Email}
if exist, err := dbUser.ExistUsername(); exist {
PanicIf(err)
ctx.AddFieldError("username", Translate(ctx.S.Get("Lang").(string), "message.error.already.exists"))
}
if exist, err := dbUser.ExistEmail(); exist {
PanicIf(err)
ctx.AddFieldError("email", Translate(ctx.S.Get("Lang").(string), "message.error.already.exists"))
}
if !ctx.HasError() {
dbUser.Password = Md5(user.Password)
err := dbUser.Insert()
PanicIf(err)
ctx.AddMessage(Translate(ctx.S.Get("Lang").(string), "message.register.success"))
} else {
ctx.Set("User", user)
}
ctx.HTML(200, "user/register", ctx)
} else {
ctx.Set("User", user)
ctx.HTML(200, "user/register", ctx)
}
default:
ctx.HTML(200, "user/register", ctx)
}
}
示例3: PasswordHandler
func PasswordHandler(ctx *middleware.Context, formErr binding.Errors, password model.Password) {
switch ctx.R.Method {
case "POST":
ctx.JoinFormErrors(formErr)
if !ctx.HasError() {
if password.CurrentPassword == password.ConfirmPassword {
ctx.AddError(Translate(ctx.S.Get("Lang").(string), "message.error.password.not.changed"))
} else {
user := &model.User{Id: password.Id}
dbUser, err := user.GetUserById(user.Id)
PanicIf(err)
if dbUser.Password == Md5(password.CurrentPassword) {
dbUser.Password = Md5(password.ConfirmPassword)
err := dbUser.Update()
PanicIf(err)
ctx.AddMessage(Translate(ctx.S.Get("Lang").(string), "message.change.success"))
} else {
ctx.AddError(Translate(ctx.S.Get("Lang").(string), "message.error.wrong.password"))
}
}
}
default:
}
ctx.HTML(200, "profile/password", ctx)
}
示例4: SettingsHandler
func SettingsHandler(ctx *middleware.Context, settings model.Settings) {
if ctx.R.Method == "POST" {
err := settings.Update()
PanicIf(err)
dbSettings := model.GetSettings()
ctx.AddMessage(Translate(ctx.S.Get("Lang").(string), "message.change.success"))
ctx.S.Set("Settings", dbSettings)
}
user := &model.User{}
users, err := user.SelectAll()
PanicIf(err)
ctx.Set("Users", users)
ctx.HTML(200, "admin/settings", ctx)
}
示例5: ProfileHandler
func ProfileHandler(ctx *middleware.Context, formErr binding.Errors, user model.User) {
switch ctx.R.Method {
case "POST":
ctx.JoinFormErrors(formErr)
if !ctx.HasError() {
err := user.Update()
PanicIf(err)
dbUser, err := user.GetUserById(user.Id)
PanicIf(err)
ctx.AddMessage(Translate(ctx.S.Get("Lang").(string), "message.change.success"))
ctx.S.Set("SignedUser", dbUser)
}
ctx.HTML(200, "profile/profile", ctx)
default:
ctx.HTML(200, "profile/profile", ctx)
}
}