本文整理汇总了Golang中filter.CurrentUser函数的典型用法代码示例。如果您正苦于以下问题:Golang CurrentUser函数的具体用法?Golang CurrentUser怎么用?Golang CurrentUser使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CurrentUser函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: CommentHandler
// 评论(或回复)
// uri: /comment/{objid:[0-9]+}.json
func CommentHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
user, _ := filter.CurrentUser(req)
if !util.CheckInt(req.PostForm, "objtype") {
fmt.Fprint(rw, `{"errno": 1, "error":"参数错误"}`)
return
}
// 入库
comment, err := service.PostComment(user["uid"].(int), util.MustInt(vars["objid"]), req.PostForm)
if err != nil {
fmt.Fprint(rw, `{"errno": 1, "error":"服务器内部错误"}`)
return
}
buf, err := json.Marshal(comment)
if err != nil {
logger.Errorln("[RecentCommentHandler] json.marshal error:", err)
fmt.Fprint(rw, `{"errno": 1, "error":"解析json出错"}`)
return
}
fmt.Fprint(rw, `{"errno": 0, "error":"", "data":`+string(buf)+`}`)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:27,代码来源:comment.go
示例2: AccountEditHandler
// 用户编辑个人信息
func AccountEditHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
curUser, _ := filter.CurrentUser(req)
if req.Method != "POST" || vars["json"] == "" {
// 获取用户信息
user := service.FindUserByUsername(curUser["username"].(string))
// 设置模板数据
filter.SetData(req, map[string]interface{}{"user": user, "default_avatars": service.DefaultAvatars})
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/user/edit.html")
return
}
req.PostForm.Set("username", curUser["username"].(string))
if req.PostFormValue("open") != "1" {
req.PostForm.Set("open", "0")
}
// 更新个人信息
errMsg, err := service.UpdateUser(req.PostForm)
if err != nil {
fmt.Fprint(rw, `{"ok": 0, "error":"`, errMsg, `"}`)
return
}
fmt.Fprint(rw, `{"ok": 1, "msg":"个人资料更新成功!"}`)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:27,代码来源:account.go
示例3: ModifyAuthorityHandler
func ModifyAuthorityHandler(rw http.ResponseWriter, req *http.Request) {
var data = make(map[string]interface{})
if req.PostFormValue("submit") == "1" {
user, _ := filter.CurrentUser(req)
username := user["username"].(string)
errMsg, err := service.SaveAuthority(req.PostForm, username)
if err != nil {
data["ok"] = 0
data["error"] = errMsg
} else {
data["ok"] = 1
data["msg"] = "修改成功"
}
} else {
menu1, menu2 := service.GetMenus()
allmenu2, _ := json.Marshal(menu2)
authority := service.FindAuthority(req.FormValue("aid"))
if authority == nil || authority.Aid == 0 {
rw.WriteHeader(http.StatusInternalServerError)
return
}
// 设置内容模板
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/admin/authority/modify.html")
data["allmenu1"] = menu1
data["allmenu2"] = string(allmenu2)
data["authority"] = authority
}
filter.SetData(req, data)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:35,代码来源:authority.go
示例4: UpdateProjectStatusHandler
// 更新状态
// uri: /admin/community/project/update_status
func UpdateProjectStatusHandler(rw http.ResponseWriter, req *http.Request) {
id, err := strconv.Atoi(req.PostFormValue("id"))
if err != nil {
rw.WriteHeader(http.StatusBadRequest)
return
}
status, err := strconv.Atoi(req.FormValue("status"))
if err != nil {
rw.WriteHeader(http.StatusBadRequest)
return
}
var data = make(map[string]interface{})
user, _ := filter.CurrentUser(req)
err = service.UpdateProjectStatus(id, status, user["username"].(string))
if err != nil {
logger.Errorln("UpdateProjectStatusHandler error:", err)
data["ok"] = 0
data["error"] = "更新状态失败"
} else {
data["ok"] = 1
data["msg"] = "更新状态成功"
}
filter.SetData(req, data)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:31,代码来源:project.go
示例5: ModifyTopicHandler
// 修改主题
// uri: /topics/modify{json:(|.json)}
func ModifyTopicHandler(rw http.ResponseWriter, req *http.Request) {
tid := req.FormValue("tid")
if tid == "" {
util.Redirect(rw, req, "/topics")
return
}
nodes := service.GenNodes()
vars := mux.Vars(req)
// 请求编辑主题页面
if req.Method != "POST" || vars["json"] == "" {
topic := service.FindTopic(tid)
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/topics/new.html")
filter.SetData(req, map[string]interface{}{"nodes": nodes, "topic": topic, "activeTopics": "active"})
return
}
user, _ := filter.CurrentUser(req)
err := service.PublishTopic(user, req.PostForm)
if err != nil {
if err == service.NotModifyAuthorityErr {
rw.WriteHeader(http.StatusForbidden)
return
}
fmt.Fprint(rw, `{"ok": 0, "error":"内部服务错误!"}`)
return
}
fmt.Fprint(rw, `{"ok": 1, "data":""}`)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:32,代码来源:topic.go
示例6: ProjectDetailHandler
// 项目详情
// uri: /p/{uniq}
func ProjectDetailHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
project := service.FindProject(vars["uniq"])
if project == nil {
util.Redirect(rw, req, "/projects")
return
}
likeFlag := 0
hadCollect := 0
user, ok := filter.CurrentUser(req)
if ok {
uid := user["uid"].(int)
likeFlag = service.HadLike(uid, project.Id, model.TYPE_PROJECT)
hadCollect = service.HadFavorite(uid, project.Id, model.TYPE_PROJECT)
}
service.Views.Incr(req, model.TYPE_PROJECT, project.Id)
// 为了阅读数即时看到
project.Viewnum++
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/projects/detail.html,/template/common/comment.html")
filter.SetData(req, map[string]interface{}{"activeProjects": "active", "project": project, "likeflag": likeFlag, "hadcollect": hadCollect})
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:27,代码来源:project.go
示例7: UserModifyHandler
// uri: /admin/user/user/modify
func UserModifyHandler(rw http.ResponseWriter, req *http.Request) {
uidStr := req.PostFormValue("uid")
var (
uid int
err error
)
if uid, err = strconv.Atoi(uidStr); err != nil {
logger.Errorln("[UserModifyHandler] invalid uid")
rw.WriteHeader(http.StatusNotFound)
return
}
var data = make(map[string]interface{})
user, _ := filter.CurrentUser(req)
if user["uid"].(int) == uid {
data["ok"] = 0
data["error"] = "不能改自己的角色!"
filter.SetData(req, data)
return
}
service.AllocUserRoles(uid, req.PostForm["roleids"])
data["ok"] = 1
data["msg"] = "success"
filter.SetData(req, data)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:31,代码来源:user.go
示例8: NewResourceHandler
// 发布新资源
// uri: /resources/new{json:(|.json)}
func NewResourceHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
title := req.PostFormValue("title")
// 请求新建资源页面
if title == "" || req.Method != "POST" || vars["json"] == "" {
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/resources/new.html")
filter.SetData(req, map[string]interface{}{"activeResources": "active", "categories": service.AllCategory})
return
}
errMsg := ""
resForm := req.PostFormValue("form")
if resForm == model.LinkForm {
if req.PostFormValue("url") == "" {
errMsg = "url不能为空"
}
} else {
if req.PostFormValue("content") == "" {
errMsg = "内容不能为空"
}
}
if errMsg != "" {
fmt.Fprint(rw, `{"ok": 0, "error":"`+errMsg+`"}`)
return
}
user, _ := filter.CurrentUser(req)
err := service.PublishResource(user, req.PostForm)
if err != nil {
fmt.Fprint(rw, `{"ok": 0, "error":"内部服务错误,请稍候再试!"}`)
return
}
fmt.Fprint(rw, `{"ok": 1, "data":""}`)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:37,代码来源:resource.go
示例9: ModifyResourceHandler
// 修改資源
// uri: /resources/modify{json:(|.json)}
func ModifyResourceHandler(rw http.ResponseWriter, req *http.Request) {
id := req.FormValue("id")
if id == "" {
util.Redirect(rw, req, "/resources")
return
}
vars := mux.Vars(req)
// 请求编辑資源页面
if req.Method != "POST" || vars["json"] == "" {
resource := service.FindResourceById(id)
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/resources/new.html")
filter.SetData(req, map[string]interface{}{"resource": resource, "activeResources": "active", "categories": service.AllCategory})
return
}
user, _ := filter.CurrentUser(req)
err := service.PublishResource(user, req.PostForm)
if err != nil {
if err == service.NotModifyAuthorityErr {
rw.WriteHeader(http.StatusForbidden)
return
}
fmt.Fprint(rw, `{"ok": 0, "error":"内部服务错误!"}`)
return
}
fmt.Fprint(rw, `{"ok": 1, "data":""}`)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:30,代码来源:resource.go
示例10: ArticleDetailHandler
// 文章详细页
// uri: /articles/{id:[0-9]+}
func ArticleDetailHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
article, prevNext, err := service.FindArticlesById(vars["id"])
if err != nil {
util.Redirect(rw, req, "/articles")
return
}
if article == nil || article.Id == 0 || article.Status == model.StatusOffline {
util.Redirect(rw, req, "/articles")
return
}
likeFlag := 0
hadCollect := 0
user, ok := filter.CurrentUser(req)
if ok {
uid := user["uid"].(int)
likeFlag = service.HadLike(uid, article.Id, model.TYPE_ARTICLE)
hadCollect = service.HadFavorite(uid, article.Id, model.TYPE_ARTICLE)
}
service.Views.Incr(req, model.TYPE_ARTICLE, article.Id)
// 为了阅读数即时看到
article.Viewnum++
// 设置内容模板
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/articles/detail.html,/template/common/comment.html")
// 设置模板数据
filter.SetData(req, map[string]interface{}{"activeArticles": "active", "article": article, "prev": prevNext[0], "next": prevNext[1], "likeflag": likeFlag, "hadcollect": hadCollect})
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:35,代码来源:article.go
示例11: ModifyArticleHandler
func ModifyArticleHandler(rw http.ResponseWriter, req *http.Request) {
var data = make(map[string]interface{})
if req.PostFormValue("submit") == "1" {
user, _ := filter.CurrentUser(req)
errMsg, err := service.ModifyArticle(user, req.PostForm)
if err != nil {
data["ok"] = 0
data["error"] = errMsg
} else {
data["ok"] = 1
data["msg"] = "修改成功"
}
} else {
article, err := service.FindArticleById(req.FormValue("id"))
if err != nil {
rw.WriteHeader(http.StatusInternalServerError)
return
}
// 设置内容模板
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/admin/article/modify.html")
data["article"] = article
data["statusSlice"] = model.StatusSlice
data["langSlice"] = model.LangSlice
}
filter.SetData(req, data)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:31,代码来源:article.go
示例12: ReminderHandler
func ReminderHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
username := req.FormValue("username")
curUser, _ := filter.CurrentUser(req)
if username == "" || req.Method != "POST" || vars["json"] == "" {
// 获取用户信息
user := service.FindUserByUsername(curUser["username"].(string))
// 设置模板数据
filter.SetData(req, map[string]interface{}{"activeUsers": "active", "user": user})
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/user/reminder.html")
return
}
// 只能编辑自己的信息
if username != curUser["username"].(string) {
fmt.Fprint(rw, `{"errno": 1, "error": "非法请求"}`)
return
}
// open传递过来的是“on”或没传递
if req.FormValue("Emailnotice") == "on" {
req.Form.Set("Emailnotice", "1")
} else {
req.Form.Set("Emailnotice", "0")
}
// 更新个人信息
errMsg, err := service.UpdateUserReminder(req.Form)
if err != nil {
fmt.Fprint(rw, `{"errno": 1, "error":"`, errMsg, `"}`)
return
}
fmt.Fprint(rw, `{"errno": 0, "msg":"个人reminder资料更新成功!"}`)
}
开发者ID:jackyxie,项目名称:btcrobot,代码行数:33,代码来源:account.go
示例13: NewTopicHandler
// 新建帖子
// uri: /topics/new{json:(|.json)}
func NewTopicHandler(rw http.ResponseWriter, req *http.Request) {
nodes := genNodes()
vars := mux.Vars(req)
title := req.FormValue("title")
// 请求新建帖子页面
if title == "" || req.Method != "POST" || vars["json"] == "" {
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/topics/new.html")
filter.SetData(req, map[string]interface{}{"nodes": nodes})
return
}
user, _ := filter.CurrentUser(req)
// 入库
topic := model.NewTopic()
topic.Uid = user["uid"].(int)
topic.Nid = util.MustInt(req.FormValue("nid"))
topic.Title = req.FormValue("title")
topic.Content = req.FormValue("content")
errMsg, err := service.PublishTopic(topic)
if err != nil {
fmt.Fprint(rw, `{"errno": 1, "error":"`, errMsg, `"}`)
return
}
fmt.Fprint(rw, `{"errno": 0, "error":""}`)
}
开发者ID:sndnvaps,项目名称:studygolang,代码行数:27,代码来源:topic.go
示例14: PublishReadingHandler
// /admin/reading/publish
func PublishReadingHandler(rw http.ResponseWriter, req *http.Request) {
var data = make(map[string]interface{})
if req.PostFormValue("submit") == "1" {
user, _ := filter.CurrentUser(req)
errMsg, err := service.SaveReading(req.PostForm, user["username"].(string))
if err != nil {
data["ok"] = 0
data["error"] = errMsg
} else {
data["ok"] = 1
data["msg"] = "操作成功"
}
} else {
id, err := strconv.Atoi(req.FormValue("id"))
if err == nil && id != 0 {
data["reading"], err = service.FindReadingById(id)
if err != nil {
rw.WriteHeader(http.StatusInternalServerError)
return
}
}
// 设置内容模板
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/admin/reading/modify.html")
}
filter.SetData(req, data)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:32,代码来源:reading.go
示例15: NewRoleHandler
func NewRoleHandler(rw http.ResponseWriter, req *http.Request) {
var data = make(map[string]interface{})
if req.PostFormValue("submit") == "1" {
user, _ := filter.CurrentUser(req)
username := user["username"].(string)
errMsg, err := service.SaveRole(req.PostForm, username)
if err != nil {
data["ok"] = 0
data["error"] = errMsg
} else {
data["ok"] = 1
data["msg"] = "添加成功"
}
} else {
menu1, menu2 := service.GetMenus()
menu3 := service.GeneralAuthorities()
// 设置内容模板
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/admin/role/new.html")
data["allmenu1"] = menu1
data["allmenu2"] = menu2
data["allmenu3"] = menu3
}
filter.SetData(req, data)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:30,代码来源:role.go
示例16: ModifyRuleHandler
func ModifyRuleHandler(rw http.ResponseWriter, req *http.Request) {
var data = make(map[string]interface{})
if req.PostFormValue("submit") == "1" {
user, _ := filter.CurrentUser(req)
errMsg, err := service.ModifyTopic(user, req.PostForm)
if err != nil {
data["ok"] = 0
data["error"] = errMsg
} else {
data["ok"] = 1
data["msg"] = "修改成功"
}
} else {
topic, replies, err := service.FindTopicByTid(req.FormValue("tid"))
if err != nil {
rw.WriteHeader(http.StatusInternalServerError)
return
}
// 设置内容模板
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/admin/topic/modify.html")
data["topic"] = topic
data["replies"] = replies
data["nodes"] = service.GenNodes()
}
filter.SetData(req, data)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:31,代码来源:rule.go
示例17: ModifyProjectHandler
// 修改项目
// uri: /project/modify{json:(|.json)}
func ModifyProjectHandler(rw http.ResponseWriter, req *http.Request) {
id := req.FormValue("id")
if id == "" {
util.Redirect(rw, req, "/projects")
return
}
vars := mux.Vars(req)
// 请求编辑项目页面
if req.Method != "POST" || vars["json"] == "" {
project := service.FindProject(id)
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/projects/new.html")
filter.SetData(req, map[string]interface{}{"project": project, "activeProjects": "active"})
return
}
user, _ := filter.CurrentUser(req)
err := service.PublishProject(user, req.PostForm)
if err != nil {
if err == service.NotModifyAuthorityErr {
rw.WriteHeader(http.StatusForbidden)
return
}
fmt.Fprint(rw, `{"ok": 0, "error":"内部服务错误!"}`)
return
}
fmt.Fprint(rw, `{"ok": 1, "data":""}`)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:30,代码来源:project.go
示例18: TopicDetailHandler
// 社区帖子详细页
// uri: /topics/{tid:[0-9]+}
func TopicDetailHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
topic, replies, err := service.FindTopicByTid(vars["tid"])
if err != nil {
util.Redirect(rw, req, "/topics")
return
}
likeFlag := 0
hadCollect := 0
user, ok := filter.CurrentUser(req)
if ok {
uid := user["uid"].(int)
tid := topic["tid"].(int)
likeFlag = service.HadLike(uid, tid, model.TYPE_TOPIC)
hadCollect = service.HadFavorite(uid, tid, model.TYPE_TOPIC)
}
service.Views.Incr(req, model.TYPE_TOPIC, util.MustInt(vars["tid"]))
// 设置内容模板
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/topics/detail.html,/template/common/comment.html")
// 设置模板数据
filter.SetData(req, map[string]interface{}{"activeTopics": "active", "topic": topic, "replies": replies, "likeflag": likeFlag, "hadcollect": hadCollect})
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:28,代码来源:topic.go
示例19: FavoriteHandler
// 收藏(取消收藏)
// uri: /favorite/{objid:[0-9]+}.json
func FavoriteHandler(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
user, _ := filter.CurrentUser(req)
if !util.CheckInt(req.PostForm, "objtype") {
fmt.Fprint(rw, `{"ok": 0, "error":"参数错误"}`)
return
}
var err error
objtype := util.MustInt(req.PostFormValue("objtype"))
collect := util.MustInt(req.PostFormValue("collect"))
if collect == 1 {
err = service.SaveFavorite(user["uid"].(int), util.MustInt(vars["objid"]), objtype)
} else {
err = service.CancelFavorite(user["uid"].(int), util.MustInt(vars["objid"]), objtype)
}
if err != nil {
fmt.Fprint(rw, `{"ok": 0, "error":"`+err.Error()+`""}`)
return
}
fmt.Fprint(rw, `{"ok": 1, "message":"success"}`)
}
开发者ID:bluefchen,项目名称:studygolang,代码行数:28,代码来源:favorite.go
示例20: NewUserHandler
// 添加新用户表单页面
func NewUserHandler(rw http.ResponseWriter, req *http.Request) {
user, _ := filter.CurrentUser(req)
tpl, err := template.ParseFiles(ROOT+"/template/admin/common.html", ROOT+"/template/admin/newuser.html")
if err != nil {
fmt.Fprintln(rw, err)
return
}
tpl.Execute(rw, user)
}
开发者ID:jackyxie,项目名称:btcrobot,代码行数:10,代码来源:user.go
注:本文中的filter.CurrentUser函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论