本文整理匯總了Golang中github.com/easykoo/go-blog/middleware.Context.Set方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Set方法的具體用法?Golang Context.Set怎麽用?Golang Context.Set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/easykoo/go-blog/middleware.Context
的用法示例。
在下文中一共展示了Context.Set方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
}
示例2: LoginHandler
func LoginHandler(ctx *middleware.Context, formErr binding.Errors, loginUser model.UserLoginForm) {
switch ctx.R.Method {
case "POST":
ctx.JoinFormErrors(formErr)
password := Md5(loginUser.Password)
user := &model.User{Username: loginUser.Username, Password: password}
if !ctx.HasError() {
if has, err := user.Exist(); has {
PanicIf(err)
if user.Locked {
ctx.Set("User", user)
ctx.AddError(Translate(ctx.S.Get("Lang").(string), "message.error.invalid.username.or.password"))
ctx.HTML(200, "user/login", ctx)
return
}
ctx.S.Set("SignedUser", user)
Log.Info(user.Username, " login")
ctx.Redirect("/admin/dashboard")
} else {
ctx.Set("User", user)
ctx.AddError(Translate(ctx.S.Get("Lang").(string), "message.error.invalid.username.or.password"))
ctx.HTML(200, "user/login", ctx)
}
} else {
ctx.HTML(200, "user/login", ctx)
}
default:
ctx.HTML(200, "user/login", ctx)
}
}
示例3: PublishBlog
func PublishBlog(ctx *middleware.Context, blog model.Blog) {
switch ctx.R.Method {
case "POST":
if blog.Title == "" || blog.Content == "" {
ctx.AddError(Translate(ctx.S.Get("Lang").(string), "message.error.publish.failed"))
} else {
tags := ctx.R.PostForm["tags"]
blog.SetTags(tags)
signedUser := ctx.S.Get("SignedUser").(model.User)
blog.State = "PUBLISHED"
blog.PublishDate = time.Now()
if blog.Version == 0 {
blog.Priority = 5
blog.Author = signedUser
blog.CreateUser = signedUser.Username
err := blog.Insert()
PanicIf(err)
} else {
err := blog.Update()
PanicIf(err)
}
}
ctx.Redirect("/blog/view/" + IntString(blog.Id))
default:
tags, err := blog.GetAllTags()
PanicIf(err)
ctx.Set("Tags", tags)
ctx.HTML(200, "blog/edit", ctx)
}
}
示例4: 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)
}
示例5: ViewFeedback
func ViewFeedback(ctx *middleware.Context, params martini.Params) {
id := params["id"]
feedback := new(model.Feedback)
feedback.Id = ParseInt(id)
err := feedback.SetViewed(true)
PanicIf(err)
ctx.Set("success", true)
ctx.JSON(200, ctx.Response)
}
示例6: LiftUser
func LiftUser(ctx *middleware.Context, params martini.Params) {
id := params["id"]
user := new(model.User)
user.Id = ParseInt(id)
err := user.SetLock(false)
PanicIf(err)
ctx.Set("success", true)
ctx.JSON(200, ctx.Response)
}
示例7: FeedbackInfo
func FeedbackInfo(ctx *middleware.Context) {
feedback := new(model.Feedback)
feedback.Viewed = false
feedbackArray, count, err := feedback.Info()
PanicIf(err)
ctx.Set("Array", feedbackArray)
ctx.Set("Count", count)
ctx.JSON(200, ctx.Response)
}
示例8: DeleteLink
func DeleteLink(ctx *middleware.Context, params martini.Params) {
id := params["id"]
link := new(model.Link)
link.Id = ParseInt(id)
err := link.Delete()
PanicIf(err)
ctx.Set("success", true)
ctx.JSON(200, ctx.Response)
}
示例9: PermitBlog
func PermitBlog(ctx *middleware.Context, params martini.Params) {
id := params["id"]
blog := new(model.Blog)
blog.Id = ParseInt(id)
err := blog.Forbid(false)
PanicIf(err)
ctx.Set("success", true)
ctx.JSON(200, ctx.Response)
}
示例10: DeleteFeedbackArray
func DeleteFeedbackArray(ctx *middleware.Context) {
feedbackArray := ctx.R.FormValue("feedbackArray")
feedback := new(model.Feedback)
var res []int
json.Unmarshal([]byte(feedbackArray), &res)
err := feedback.DeleteFeedbackArray(res)
PanicIf(err)
ctx.Set("success", true)
ctx.JSON(200, ctx.Response)
}
示例11: DeleteBlogArray
func DeleteBlogArray(ctx *middleware.Context) {
blogArray := ctx.R.FormValue("blogArray")
blog := new(model.Blog)
var res []int
json.Unmarshal([]byte(blogArray), &res)
err := blog.DeleteBlogArray(res)
PanicIf(err)
ctx.Set("success", true)
ctx.JSON(200, ctx.Response)
}
示例12: DeleteLinkArray
func DeleteLinkArray(ctx *middleware.Context) {
linkArray := ctx.R.FormValue("linkArray")
link := new(model.Link)
var res []int
json.Unmarshal([]byte(linkArray), &res)
err := link.DeleteLinkArray(res)
PanicIf(err)
ctx.Set("success", true)
ctx.JSON(200, ctx.Response)
}
示例13: EditLink
func EditLink(ctx *middleware.Context, params martini.Params) {
id := params["id"]
link := new(model.Link)
link.Id = ParseInt(id)
err := link.GetLink()
PanicIf(err)
ctx.Set("Link", link)
ctx.HTML(200, "link/edit", ctx)
}
示例14: DeleteUsers
func DeleteUsers(ctx *middleware.Context) {
users := ctx.R.FormValue("Users")
var res []int
json.Unmarshal([]byte(users), &res)
user := new(model.User)
err := user.DeleteUsers(res)
PanicIf(err)
ctx.Set("success", true)
ctx.JSON(200, ctx.Response)
}
示例15: InsertLink
func InsertLink(ctx *middleware.Context, link model.Link) {
switch ctx.R.Method {
case "POST":
err := link.Insert()
PanicIf(err)
ctx.Set("success", true)
ctx.Set("message", Translate(ctx.S.Get("Lang").(string), "message.send.success"))
ctx.Redirect("/link/all")
default:
ctx.HTML(200, "link/edit", ctx)
}
}