diff --git a/delegates/coverage.out b/delegates/coverage.out index c034d3a..802be13 100644 --- a/delegates/coverage.out +++ b/delegates/coverage.out @@ -162,16 +162,16 @@ github.com/Ulbora/go-micro-blog-ui/delegates/userDelegate.go:118.2,118.13 1 1 github.com/Ulbora/go-micro-blog-ui/delegates/userDelegate.go:122.52,125.16 3 1 github.com/Ulbora/go-micro-blog-ui/delegates/userDelegate.go:125.16,127.17 2 1 github.com/Ulbora/go-micro-blog-ui/delegates/userDelegate.go:127.17,132.4 4 1 -github.com/Ulbora/go-micro-blog-ui/delegates/userDelegate.go:134.2,135.13 2 1 +github.com/Ulbora/go-micro-blog-ui/delegates/userDelegate.go:134.2,135.15 2 1 github.com/Ulbora/go-micro-blog-ui/delegates/userDelegate.go:139.53,142.16 3 1 github.com/Ulbora/go-micro-blog-ui/delegates/userDelegate.go:142.16,144.17 2 1 github.com/Ulbora/go-micro-blog-ui/delegates/userDelegate.go:144.17,149.4 4 1 -github.com/Ulbora/go-micro-blog-ui/delegates/userDelegate.go:151.2,152.13 2 1 +github.com/Ulbora/go-micro-blog-ui/delegates/userDelegate.go:151.2,152.15 2 1 github.com/Ulbora/go-micro-blog-ui/delegates/userDelegate.go:156.61,159.16 3 1 github.com/Ulbora/go-micro-blog-ui/delegates/userDelegate.go:159.16,161.17 2 1 github.com/Ulbora/go-micro-blog-ui/delegates/userDelegate.go:161.17,166.4 4 1 -github.com/Ulbora/go-micro-blog-ui/delegates/userDelegate.go:168.2,169.13 2 1 +github.com/Ulbora/go-micro-blog-ui/delegates/userDelegate.go:168.2,169.16 2 1 github.com/Ulbora/go-micro-blog-ui/delegates/userDelegate.go:173.56,176.16 3 1 github.com/Ulbora/go-micro-blog-ui/delegates/userDelegate.go:176.16,178.17 2 1 github.com/Ulbora/go-micro-blog-ui/delegates/userDelegate.go:178.17,183.4 4 1 -github.com/Ulbora/go-micro-blog-ui/delegates/userDelegate.go:185.2,186.13 2 1 +github.com/Ulbora/go-micro-blog-ui/delegates/userDelegate.go:185.2,186.15 2 1 diff --git a/delegates/userDelegate.go b/delegates/userDelegate.go index 75f8e54..1d6db6f 100644 --- a/delegates/userDelegate.go +++ b/delegates/userDelegate.go @@ -120,68 +120,68 @@ func (d *MCDelegate) GetBannedUserList() *[]User { // EnableUser EnableUser func (d *MCDelegate) EnableUser(u *User) *Response { - var rtn Response + var eurtn Response aJSON, err := json.Marshal(u) if err == nil { erq, err := d.buildRequest(http.MethodPut, "/rs/user/enable", aJSON, adminKey) if err == nil { - usuc, stat := d.proxy.Do(erq, &rtn) - rtn.Code = int64(stat) + usuc, stat := d.proxy.Do(erq, &eurtn) + eurtn.Code = int64(stat) d.Log.Debug("suc: ", usuc) d.Log.Debug("stat: ", stat) } } - d.Log.Debug("rtn: ", rtn) - return &rtn + d.Log.Debug("rtn: ", eurtn) + return &eurtn } // DisableUser DisableUser func (d *MCDelegate) DisableUser(u *User) *Response { - var rtn Response + var durtn Response aJSON, err := json.Marshal(u) if err == nil { drq, err := d.buildRequest(http.MethodPut, "/rs/user/disable", aJSON, adminKey) if err == nil { - dsuc, stat := d.proxy.Do(drq, &rtn) - rtn.Code = int64(stat) + dsuc, stat := d.proxy.Do(drq, &durtn) + durtn.Code = int64(stat) d.Log.Debug("suc: ", dsuc) d.Log.Debug("stat: ", stat) } } - d.Log.Debug("rtn: ", rtn) - return &rtn + d.Log.Debug("rtn: ", durtn) + return &durtn } // DisableUserForCause DisableUserForCause func (d *MCDelegate) DisableUserForCause(u *User) *Response { - var rtn Response + var ddurtn Response aJSON, err := json.Marshal(u) if err == nil { drq, err := d.buildRequest(http.MethodPut, "/rs/user/disableForCause", aJSON, adminKey) if err == nil { - dsuc, stat := d.proxy.Do(drq, &rtn) - rtn.Code = int64(stat) + dsuc, stat := d.proxy.Do(drq, &ddurtn) + ddurtn.Code = int64(stat) d.Log.Debug("suc: ", dsuc) d.Log.Debug("stat: ", stat) } } - d.Log.Debug("rtn: ", rtn) - return &rtn + d.Log.Debug("rtn: ", ddurtn) + return &ddurtn } // ReactivateUser ReactivateUser func (d *MCDelegate) ReactivateUser(u *User) *Response { - var rtn Response + var rertn Response aJSON, err := json.Marshal(u) if err == nil { erq, err := d.buildRequest(http.MethodPut, "/rs/user/reinstate", aJSON, adminKey) if err == nil { - usuc, stat := d.proxy.Do(erq, &rtn) - rtn.Code = int64(stat) + usuc, stat := d.proxy.Do(erq, &rertn) + rertn.Code = int64(stat) d.Log.Debug("suc: ", usuc) d.Log.Debug("stat: ", stat) } } - d.Log.Debug("rtn: ", rtn) - return &rtn + d.Log.Debug("rtn: ", rertn) + return &rertn } diff --git a/handlers/adminBlogHandler.go b/handlers/adminBlogHandler.go index 7d1b589..b3f5857 100644 --- a/handlers/adminBlogHandler.go +++ b/handlers/adminBlogHandler.go @@ -33,20 +33,20 @@ import ( // GetAdminBlogList GetAdminBlogList func (h *MCHandler) GetAdminBlogList(w http.ResponseWriter, r *http.Request) { fmt.Println("in GetAdminBlogList") - s, suc := h.getSession(r) + abs, suc := h.getSession(r) h.Log.Debug("session suc in GetBlog", suc) if suc { - loggedInAuth := s.Get("loggedIn") - var isAdmin = s.Get("isAdmin") + loggedInAuth := abs.Get("loggedIn") + var isAdmin = abs.Get("isAdmin") h.Log.Debug("loggedIn in GetBlog: ", loggedInAuth) if loggedInAuth == true && isAdmin == true { - blogList := h.Delegate.GetAdminBlogList(0, maxPosts) - h.Log.Debug("blogCnt: ", len(*blogList)) + ablogList := h.Delegate.GetAdminBlogList(0, maxPosts) + h.Log.Debug("blogCnt: ", len(*ablogList)) var bp BlogPage bp.Title = h.Title bp.Desc = h.Desc bp.KeyWords = h.KeyWords - uemail := s.Get("userEmail") + uemail := abs.Get("userEmail") if uemail != nil { bp.MyEmail = uemail.(string) } @@ -56,19 +56,19 @@ func (h *MCHandler) GetAdminBlogList(w http.ResponseWriter, r *http.Request) { bp.IsAdmin = true } var blst []Blog - for i := range *blogList { + for i := range *ablogList { var wg sync.WaitGroup - var bb Blog - bb.Blog = &(*blogList)[i] - txt, err := b64.StdEncoding.DecodeString(bb.Blog.Content) + var abb Blog + abb.Blog = &(*ablogList)[i] + txt, err := b64.StdEncoding.DecodeString(abb.Blog.Content) if err == nil { - bb.Blog.Content = string(txt) - bb.Blog.Content = strings.Replace(bb.Blog.Content, stripOut, "", -1) - bb.Blog.Content = strings.Replace(bb.Blog.Content, stripOut2, "", -1) - bb.Blog.Content = strings.Replace(bb.Blog.Content, stripOut3, "", -1) - bb.Blog.Content = strings.Replace(bb.Blog.Content, stripOut4, "", -1) + abb.Blog.Content = string(txt) + abb.Blog.Content = strings.Replace(abb.Blog.Content, stripOut, "", -1) + abb.Blog.Content = strings.Replace(abb.Blog.Content, stripOut2, "", -1) + abb.Blog.Content = strings.Replace(abb.Blog.Content, stripOut3, "", -1) + abb.Blog.Content = strings.Replace(abb.Blog.Content, stripOut4, "", -1) - bb.TextHTML = template.HTML(bb.Blog.Content) + abb.TextHTML = template.HTML(abb.Blog.Content) } wg.Add(1) go func(bbb *Blog) { @@ -77,7 +77,7 @@ func (h *MCHandler) GetAdminBlogList(w http.ResponseWriter, r *http.Request) { h.Log.Debug("commentCnt: ", len(*cl)) bbb.CommentCnt = len(*cl) h.Log.Debug("Comments Done: ") - }(&bb) + }(&abb) wg.Add(1) go func(bbb *Blog) { defer wg.Done() @@ -90,7 +90,7 @@ func (h *MCHandler) GetAdminBlogList(w http.ResponseWriter, r *http.Request) { h.Log.Debug("likeCnt: ", len(*ll)) bbb.LikeCnt = len(*ll) h.Log.Debug("Views Done: ") - }(&bb) + }(&abb) wg.Add(1) go func(bbb *Blog) { @@ -100,11 +100,11 @@ func (h *MCHandler) GetAdminBlogList(w http.ResponseWriter, r *http.Request) { bbb.User = u1 bbb.UserImage = b64.StdEncoding.EncodeToString(bbb.User.Image) h.Log.Debug("User Done: ") - }(&bb) + }(&abb) wg.Wait() - blst = append(blst, bb) + blst = append(blst, abb) } bp.BlogList = &blst h.Log.Debug("after all waits") @@ -120,21 +120,21 @@ func (h *MCHandler) GetAdminBlogList(w http.ResponseWriter, r *http.Request) { // ActivateBlog ActivateBlog func (h *MCHandler) ActivateBlog(w http.ResponseWriter, r *http.Request) { fmt.Println("in Activate Blog") - s, suc := h.getSession(r) + aas, suc := h.getSession(r) h.Log.Debug("session suc in Activate Blog", suc) if suc { - loggedInAuth := s.Get("loggedIn") - var isAdmin = s.Get("isAdmin") + loggedInAuth := aas.Get("loggedIn") + var isAdmin = aas.Get("isAdmin") h.Log.Debug("loggedIn in Activate Blog: ", loggedInAuth) if loggedInAuth == true && isAdmin == true { - vars := mux.Vars(r) - bidStr := vars["bid"] + aavars := mux.Vars(r) + bidStr := aavars["bid"] h.Log.Debug("bid in Activate Blog: ", bidStr) bid, _ := strconv.ParseInt(bidStr, 10, 64) - var abb mcd.Blog - abb.ID = bid - res := h.Delegate.ActivateBlog(&abb) + var aabb mcd.Blog + aabb.ID = bid + res := h.Delegate.ActivateBlog(&aabb) if !res.Success { h.Log.Debug("add Activate Blog suc: ", res.Success) h.Log.Debug("add Activate Blog code: ", res.Code) @@ -149,22 +149,22 @@ func (h *MCHandler) ActivateBlog(w http.ResponseWriter, r *http.Request) { // DeactivateBlog DeactivateBlog func (h *MCHandler) DeactivateBlog(w http.ResponseWriter, r *http.Request) { fmt.Println("in Dectivate Blog") - s, suc := h.getSession(r) + ads, suc := h.getSession(r) h.Log.Debug("session suc in Dectivate Blog", suc) if suc { - loggedInAuth := s.Get("loggedIn") - var isAdmin = s.Get("isAdmin") + loggedInAuth := ads.Get("loggedIn") + var isAdmin = ads.Get("isAdmin") h.Log.Debug("loggedIn in Dectivate Blog: ", loggedInAuth) if loggedInAuth == true && isAdmin == true { - vars := mux.Vars(r) - bidStr := vars["bid"] + advars := mux.Vars(r) + bidStr := advars["bid"] h.Log.Debug("bid: ", bidStr) bid, _ := strconv.ParseInt(bidStr, 10, 64) - var dbb mcd.Blog - dbb.ID = bid + var adbb mcd.Blog + adbb.ID = bid - res := h.Delegate.DeActivateBlog(&dbb) + res := h.Delegate.DeActivateBlog(&adbb) if !res.Success { h.Log.Debug("add Dectivate Blog suc: ", res.Success) h.Log.Debug("add Dectivate Blog code: ", res.Code) @@ -179,22 +179,22 @@ func (h *MCHandler) DeactivateBlog(w http.ResponseWriter, r *http.Request) { // DeleteBlog DeleteBlog func (h *MCHandler) DeleteBlog(w http.ResponseWriter, r *http.Request) { fmt.Println("in Delete Blog") - s, suc := h.getSession(r) + adds, suc := h.getSession(r) h.Log.Debug("session suc in Delete Blog", suc) if suc { - loggedInAuth := s.Get("loggedIn") - var isAdmin = s.Get("isAdmin") + loggedInAuth := adds.Get("loggedIn") + var isAdmin = adds.Get("isAdmin") h.Log.Debug("loggedIn in Delete Blog: ", loggedInAuth) if loggedInAuth == true && isAdmin == true { - vars := mux.Vars(r) - bidStr := vars["bid"] + addvars := mux.Vars(r) + bidStr := addvars["bid"] h.Log.Debug("bid: ", bidStr) bid, _ := strconv.ParseInt(bidStr, 10, 64) - res := h.Delegate.DeleteBlog(bid) - if !res.Success { - h.Log.Debug("add Delete Blog suc: ", res.Success) - h.Log.Debug("add Delete Blog code: ", res.Code) + addres := h.Delegate.DeleteBlog(bid) + if !addres.Success { + h.Log.Debug("add Delete Blog suc: ", addres.Success) + h.Log.Debug("add Delete Blog code: ", addres.Code) } http.Redirect(w, r, adminBlogListRt, http.StatusFound) diff --git a/handlers/adminCommentHandler.go b/handlers/adminCommentHandler.go index cf0e707..0ad5b0b 100644 --- a/handlers/adminCommentHandler.go +++ b/handlers/adminCommentHandler.go @@ -33,27 +33,27 @@ import ( // GetAdminCommentList GetAdminCommentList func (h *MCHandler) GetAdminCommentList(w http.ResponseWriter, r *http.Request) { fmt.Println("in GetAdminCommentList") - s, suc := h.getSession(r) + cs, suc := h.getSession(r) h.Log.Debug("session suc in GetAdminCommentList", suc) if suc { - loggedInAuth := s.Get("loggedIn") - var isAdmin = s.Get("isAdmin") + loggedInAuth := cs.Get("loggedIn") + var isAdmin = cs.Get("isAdmin") h.Log.Debug("loggedIn in GetAdminCommentList: ", loggedInAuth) if loggedInAuth == true && isAdmin == true { - bvars := mux.Vars(r) - bidstr := bvars["bid"] + cvars := mux.Vars(r) + bidstr := cvars["bid"] bid, _ := strconv.ParseInt(bidstr, 10, 64) h.Log.Debug("blog id in edit", bid) var wg sync.WaitGroup bg := h.Delegate.GetBlog(bid) - var bp BlogPage - bp.Title = h.Title - bp.Desc = h.Desc - bp.KeyWords = h.KeyWords - uemail := s.Get("userEmail") + var cbp BlogPage + cbp.Title = h.Title + cbp.Desc = h.Desc + cbp.KeyWords = h.KeyWords + uemail := cs.Get("userEmail") if uemail != nil { - bp.MyEmail = uemail.(string) + cbp.MyEmail = uemail.(string) } var bb Blog bb.Blog = bg @@ -69,7 +69,7 @@ func (h *MCHandler) GetAdminCommentList(w http.ResponseWriter, r *http.Request) h.Log.Debug("TextHTML: ", bb.TextHTML) } - bp.Blog = &bb + cbp.Blog = &bb wg.Add(1) go func(bbb *Blog) { defer wg.Done() @@ -102,7 +102,7 @@ func (h *MCHandler) GetAdminCommentList(w http.ResponseWriter, r *http.Request) wg.Wait() - h.AdminTemplates.ExecuteTemplate(w, adminBlogPage, &bp) + h.AdminTemplates.ExecuteTemplate(w, adminBlogPage, &cbp) } else { http.Redirect(w, r, loginRt, http.StatusFound) @@ -113,16 +113,16 @@ func (h *MCHandler) GetAdminCommentList(w http.ResponseWriter, r *http.Request) // ActivateComment ActivateComment func (h *MCHandler) ActivateComment(w http.ResponseWriter, r *http.Request) { fmt.Println("in Activate Comment") - s, suc := h.getSession(r) + acs, suc := h.getSession(r) h.Log.Debug("session suc in Activate Comment", suc) if suc { - loggedInAuth := s.Get("loggedIn") - var isAdmin = s.Get("isAdmin") + loggedInAuth := acs.Get("loggedIn") + var isAdmin = acs.Get("isAdmin") h.Log.Debug("loggedIn in Activate Comment: ", loggedInAuth) if loggedInAuth == true && isAdmin == true { - vars := mux.Vars(r) - cidStr := vars["cid"] - bidStr := vars["bid"] + avars := mux.Vars(r) + cidStr := avars["cid"] + bidStr := avars["bid"] h.Log.Debug("cid in Activate Comment: ", cidStr) cid, _ := strconv.ParseInt(cidStr, 10, 64) @@ -143,22 +143,22 @@ func (h *MCHandler) ActivateComment(w http.ResponseWriter, r *http.Request) { // DeactivateComment DeactivateComment func (h *MCHandler) DeactivateComment(w http.ResponseWriter, r *http.Request) { fmt.Println("in Deactivate Comment") - s, suc := h.getSession(r) + dcs, suc := h.getSession(r) h.Log.Debug("session suc in Deactivate Comment", suc) if suc { - loggedInAuth := s.Get("loggedIn") - var isAdmin = s.Get("isAdmin") + loggedInAuth := dcs.Get("loggedIn") + var isAdmin = dcs.Get("isAdmin") h.Log.Debug("loggedIn in Deactivate Comment: ", loggedInAuth) if loggedInAuth == true && isAdmin == true { - vars := mux.Vars(r) - cidStr := vars["cid"] - bidStr := vars["bid"] + dvars := mux.Vars(r) + cidStr := dvars["cid"] + bidStr := dvars["bid"] h.Log.Debug("cid in Deactivate Comment: ", cidStr) cid, _ := strconv.ParseInt(cidStr, 10, 64) - var acc mcd.Comment - acc.ID = cid - res := h.Delegate.DeActivateComment(&acc) + var dcc mcd.Comment + dcc.ID = cid + res := h.Delegate.DeActivateComment(&dcc) if !res.Success { h.Log.Debug("add Activate Comment suc: ", res.Success) h.Log.Debug("add Activate Comment code: ", res.Code) diff --git a/handlers/adminUserHandler.go b/handlers/adminUserHandler.go index a9d1ec2..2e6c781 100644 --- a/handlers/adminUserHandler.go +++ b/handlers/adminUserHandler.go @@ -47,28 +47,28 @@ type User struct { // GetUserByIDPage GetUserByIDPage func (h *MCHandler) GetUserByIDPage(w http.ResponseWriter, r *http.Request) { fmt.Println("in GetUserByIDPage") - s, suc := h.getSession(r) + gs, suc := h.getSession(r) h.Log.Debug("session suc in GetUserByIDPage", suc) if suc { - loggedInAuth := s.Get("loggedIn") - var isAdmin = s.Get("isAdmin") + loggedInAuth := gs.Get("loggedIn") + var isAdmin = gs.Get("isAdmin") h.Log.Debug("loggedIn in GetBlog: ", loggedInAuth) if loggedInAuth == true && isAdmin == true { - bvars := mux.Vars(r) - uidstr := bvars["uid"] + guvars := mux.Vars(r) + uidstr := guvars["uid"] uid, _ := strconv.ParseInt(uidstr, 10, 64) h.Log.Debug("user id", uid) user := h.Delegate.GetUserByID(uid) - var up UserPage - up.Title = h.Title - up.Desc = h.Desc - up.KeyWords = h.KeyWords - up.User = user - up.UserImage = b64.StdEncoding.EncodeToString(up.User.Image) + var gup UserPage + gup.Title = h.Title + gup.Desc = h.Desc + gup.KeyWords = h.KeyWords + gup.User = user + gup.UserImage = b64.StdEncoding.EncodeToString(gup.User.Image) - h.AdminTemplates.ExecuteTemplate(w, adminUserPage, &up) + h.AdminTemplates.ExecuteTemplate(w, adminUserPage, &gup) } else { http.Redirect(w, r, loginRt, http.StatusFound) @@ -79,30 +79,30 @@ func (h *MCHandler) GetUserByIDPage(w http.ResponseWriter, r *http.Request) { // GetUnactivatedUserList GetUnactivatedUserList func (h *MCHandler) GetUnactivatedUserList(w http.ResponseWriter, r *http.Request) { fmt.Println("in GetUnactivatedUserList") - s, suc := h.getSession(r) + uas, suc := h.getSession(r) h.Log.Debug("session suc in GetUnactivatedUserList", suc) if suc { - loggedInAuth := s.Get("loggedIn") - var isAdmin = s.Get("isAdmin") + loggedInAuth := uas.Get("loggedIn") + var isAdmin = uas.Get("isAdmin") h.Log.Debug("loggedIn in GetUnactivatedUserList: ", loggedInAuth) if loggedInAuth == true && isAdmin == true { users := h.Delegate.GetUnActivatedUserList() - var ul []User + var ual []User for i := range *users { var u User u.User = &(*users)[i] u.UserImage = b64.StdEncoding.EncodeToString(u.User.Image) - ul = append(ul, u) + ual = append(ual, u) } - var up UserPage - up.Title = h.Title - up.Desc = h.Desc - up.KeyWords = h.KeyWords - up.Users = &ul + var uap UserPage + uap.Title = h.Title + uap.Desc = h.Desc + uap.KeyWords = h.KeyWords + uap.Users = &ual - h.AdminTemplates.ExecuteTemplate(w, adminUnactivatedUserPage, &up) + h.AdminTemplates.ExecuteTemplate(w, adminUnactivatedUserPage, &uap) } else { http.Redirect(w, r, loginRt, http.StatusFound) @@ -113,30 +113,30 @@ func (h *MCHandler) GetUnactivatedUserList(w http.ResponseWriter, r *http.Reques // GetBannedUserList GetBannedUserList func (h *MCHandler) GetBannedUserList(w http.ResponseWriter, r *http.Request) { fmt.Println("in GetBannedUserList") - s, suc := h.getSession(r) + gbs, suc := h.getSession(r) h.Log.Debug("session suc in GetBannedUserList", suc) if suc { - loggedInAuth := s.Get("loggedIn") - var isAdmin = s.Get("isAdmin") + loggedInAuth := gbs.Get("loggedIn") + var isAdmin = gbs.Get("isAdmin") h.Log.Debug("loggedIn in GetBannedUserList: ", loggedInAuth) if loggedInAuth == true && isAdmin == true { - users := h.Delegate.GetBannedUserList() + busers := h.Delegate.GetBannedUserList() var ul []User - for i := range *users { + for i := range *busers { var u User - u.User = &(*users)[i] + u.User = &(*busers)[i] u.UserImage = b64.StdEncoding.EncodeToString(u.User.Image) ul = append(ul, u) } - var up UserPage - up.Title = h.Title - up.Desc = h.Desc - up.KeyWords = h.KeyWords - up.Users = &ul + var bup UserPage + bup.Title = h.Title + bup.Desc = h.Desc + bup.KeyWords = h.KeyWords + bup.Users = &ul - h.AdminTemplates.ExecuteTemplate(w, adminBannedUserPage, &up) + h.AdminTemplates.ExecuteTemplate(w, adminBannedUserPage, &bup) } else { http.Redirect(w, r, loginRt, http.StatusFound) @@ -147,24 +147,24 @@ func (h *MCHandler) GetBannedUserList(w http.ResponseWriter, r *http.Request) { // EnableUser EnableUser func (h *MCHandler) EnableUser(w http.ResponseWriter, r *http.Request) { fmt.Println("in EnableUser") - s, suc := h.getSession(r) + es, suc := h.getSession(r) h.Log.Debug("session suc in EnableUser", suc) if suc { - loggedInAuth := s.Get("loggedIn") - var isAdmin = s.Get("isAdmin") + loggedInAuth := es.Get("loggedIn") + var isAdmin = es.Get("isAdmin") h.Log.Debug("loggedIn in EnableUser: ", loggedInAuth) if loggedInAuth == true && isAdmin == true { - vars := mux.Vars(r) - uidStr := vars["uid"] + evars := mux.Vars(r) + uidStr := evars["uid"] h.Log.Debug("uid in EnableUser: ", uidStr) uid, _ := strconv.ParseInt(uidStr, 10, 64) - var ubb mcd.User - ubb.ID = uid - res := h.Delegate.EnableUser(&ubb) - if !res.Success { - h.Log.Debug("add EnableUser suc: ", res.Success) - h.Log.Debug("add EnableUser code: ", res.Code) + var eubb mcd.User + eubb.ID = uid + eres := h.Delegate.EnableUser(&eubb) + if !eres.Success { + h.Log.Debug("add EnableUser suc: ", eres.Success) + h.Log.Debug("add EnableUser code: ", eres.Code) } http.Redirect(w, r, adminUserRt+"/"+uidStr, http.StatusFound) } else { @@ -176,24 +176,24 @@ func (h *MCHandler) EnableUser(w http.ResponseWriter, r *http.Request) { // DisableUser DisableUser func (h *MCHandler) DisableUser(w http.ResponseWriter, r *http.Request) { fmt.Println("in DisableUser") - s, suc := h.getSession(r) + das, suc := h.getSession(r) h.Log.Debug("session suc in DisableUser", suc) if suc { - loggedInAuth := s.Get("loggedIn") - var isAdmin = s.Get("isAdmin") + loggedInAuth := das.Get("loggedIn") + var isAdmin = das.Get("isAdmin") h.Log.Debug("loggedIn in DisableUser: ", loggedInAuth) if loggedInAuth == true && isAdmin == true { - vars := mux.Vars(r) - uidStr := vars["uid"] + davars := mux.Vars(r) + uidStr := davars["uid"] h.Log.Debug("uid in DisableUser: ", uidStr) uid, _ := strconv.ParseInt(uidStr, 10, 64) - var ubb mcd.User - ubb.ID = uid - res := h.Delegate.DisableUser(&ubb) - if !res.Success { - h.Log.Debug("add DisableUser suc: ", res.Success) - h.Log.Debug("add DisableUser code: ", res.Code) + var dubb mcd.User + dubb.ID = uid + dares := h.Delegate.DisableUser(&dubb) + if !dares.Success { + h.Log.Debug("add DisableUser suc: ", dares.Success) + h.Log.Debug("add DisableUser code: ", dares.Code) } http.Redirect(w, r, adminUserRt+"/"+uidStr, http.StatusFound) } else { @@ -205,24 +205,24 @@ func (h *MCHandler) DisableUser(w http.ResponseWriter, r *http.Request) { // DisableUserForCause DisableUserForCause func (h *MCHandler) DisableUserForCause(w http.ResponseWriter, r *http.Request) { fmt.Println("in DisableUserForCause") - s, suc := h.getSession(r) + dds, suc := h.getSession(r) h.Log.Debug("session suc in DisableUserForCause", suc) if suc { - loggedInAuth := s.Get("loggedIn") - var isAdmin = s.Get("isAdmin") + loggedInAuth := dds.Get("loggedIn") + var isAdmin = dds.Get("isAdmin") h.Log.Debug("loggedIn in DisableUserForCause: ", loggedInAuth) if loggedInAuth == true && isAdmin == true { - vars := mux.Vars(r) - uidStr := vars["uid"] + dddvars := mux.Vars(r) + uidStr := dddvars["uid"] h.Log.Debug("uid in DisableUserForCause: ", uidStr) uid, _ := strconv.ParseInt(uidStr, 10, 64) - var ubb mcd.User - ubb.ID = uid - res := h.Delegate.DisableUserForCause(&ubb) - if !res.Success { - h.Log.Debug("add DisableUserForCause suc: ", res.Success) - h.Log.Debug("add DisableUserForCause code: ", res.Code) + var dddubb mcd.User + dddubb.ID = uid + dddres := h.Delegate.DisableUserForCause(&dddubb) + if !dddres.Success { + h.Log.Debug("add DisableUserForCause suc: ", dddres.Success) + h.Log.Debug("add DisableUserForCause code: ", dddres.Code) } http.Redirect(w, r, adminUserRt+"/"+uidStr, http.StatusFound) } else { @@ -234,24 +234,24 @@ func (h *MCHandler) DisableUserForCause(w http.ResponseWriter, r *http.Request) // ReinstateBannedUser ReinstateBannedUser func (h *MCHandler) ReinstateBannedUser(w http.ResponseWriter, r *http.Request) { fmt.Println("in ReinstateBannedUser") - s, suc := h.getSession(r) + ris, suc := h.getSession(r) h.Log.Debug("session suc in ReinstateBannedUser", suc) if suc { - loggedInAuth := s.Get("loggedIn") - var isAdmin = s.Get("isAdmin") + loggedInAuth := ris.Get("loggedIn") + var isAdmin = ris.Get("isAdmin") h.Log.Debug("loggedIn in ReinstateBannedUser: ", loggedInAuth) if loggedInAuth == true && isAdmin == true { - vars := mux.Vars(r) - uidStr := vars["uid"] + rivars := mux.Vars(r) + uidStr := rivars["uid"] h.Log.Debug("uid in ReinstateBannedUser: ", uidStr) uid, _ := strconv.ParseInt(uidStr, 10, 64) - var ubb mcd.User - ubb.ID = uid - res := h.Delegate.ReactivateUser(&ubb) - if !res.Success { - h.Log.Debug("add ReinstateBannedUser suc: ", res.Success) - h.Log.Debug("add ReinstateBannedUser code: ", res.Code) + var riubb mcd.User + riubb.ID = uid + rires := h.Delegate.ReactivateUser(&riubb) + if !rires.Success { + h.Log.Debug("add ReinstateBannedUser suc: ", rires.Success) + h.Log.Debug("add ReinstateBannedUser code: ", rires.Code) } http.Redirect(w, r, adminUserRt+"/"+uidStr, http.StatusFound) } else { diff --git a/handlers/callbackHandler.go b/handlers/callbackHandler.go index ba2ab22..f9702ab 100644 --- a/handlers/callbackHandler.go +++ b/handlers/callbackHandler.go @@ -121,62 +121,62 @@ func (h *MCHandler) GoogleSigninCallback(w http.ResponseWriter, r *http.Request) if s.GoogleState == state { tk := si.AccessToken(code) h.Log.Debug("token: ", tk.AccessToken) - uiRes := si.GetUserInfo(tk.AccessToken) - if uiRes.(*s.GoogleUserInfoResponse).EmailVerified && uiRes.(*s.GoogleUserInfoResponse).Email != "" { - uemail := uiRes.(*s.GoogleUserInfoResponse).Email - fname := uiRes.(*s.GoogleUserInfoResponse).FirstName - lname := uiRes.(*s.GoogleUserInfoResponse).LastName - picture := uiRes.(*s.GoogleUserInfoResponse).PictureURL - - h.Log.Debug("uemail: ", uemail) - h.Log.Debug("fname: ", fname) - h.Log.Debug("lname: ", lname) - h.Log.Debug("picture: ", picture) - h.Log.Debug("token: ", tk.AccessToken) - - var usuc bool + guiRes := si.GetUserInfo(tk.AccessToken) + if guiRes.(*s.GoogleUserInfoResponse).EmailVerified && guiRes.(*s.GoogleUserInfoResponse).Email != "" { + uemail := guiRes.(*s.GoogleUserInfoResponse).Email + fname := guiRes.(*s.GoogleUserInfoResponse).FirstName + lname := guiRes.(*s.GoogleUserInfoResponse).LastName + picture := guiRes.(*s.GoogleUserInfoResponse).PictureURL + + h.Log.Debug("guemail: ", uemail) + h.Log.Debug("gfname: ", fname) + h.Log.Debug("glname: ", lname) + h.Log.Debug("gpicture: ", picture) + h.Log.Debug("gtoken: ", tk.AccessToken) + + var gusuc bool var urole int64 - user := h.Delegate.GetUser(uemail) - if !user.Active && user.Email == "" { + guser := h.Delegate.GetUser(uemail) + if !guser.Active && guser.Email == "" { h.Log.Debug("create new user: ", uemail) role := h.Delegate.GetRole(del.UserRole) - var nusr del.User - nusr.Active = true - nusr.Email = uemail - nusr.FirstName = fname - nusr.LastName = lname - nusr.RoleID = role.ID + var gnusr del.User + gnusr.Active = true + gnusr.Email = uemail + gnusr.FirstName = fname + gnusr.LastName = lname + gnusr.RoleID = role.ID image := si.GetUserPicture(picture) - nusr.Image = image - adusr := h.Delegate.AddUser(&nusr) + gnusr.Image = image + adusr := h.Delegate.AddUser(&gnusr) if adusr.Success { - usuc = true + gusuc = true var usauth del.UserAuth usauth.AuthType = "GoogleOAuth2" usauth.Entered = time.Now() usauth.UserID = adusr.ID h.Delegate.AddUserAuth(&usauth) } - } else if user.Active { - urole = user.RoleID - usuc = true + } else if guser.Active { + urole = guser.RoleID + gusuc = true var usauth del.UserAuth usauth.AuthType = "GoogleOAuth2" usauth.Entered = time.Now() - usauth.UserID = user.ID + usauth.UserID = guser.ID h.Delegate.AddUserAuth(&usauth) } - if usuc { - sec, suc := h.getSession(r) + if gusuc { + gsec, suc := h.getSession(r) if suc { arole := h.Delegate.GetRole(del.AdminRole) if urole == arole.ID { - sec.Set("isAdmin", true) + gsec.Set("isAdmin", true) } - sec.Set("loggedIn", true) - sec.Set("userEmail", uemail) - serr := sec.Save(w) + gsec.Set("loggedIn", true) + gsec.Set("userEmail", uemail) + serr := gsec.Save(w) h.Log.Debug("serr", serr) } diff --git a/handlers/coverage.out b/handlers/coverage.out index 4d4d0e5..ece86e7 100644 --- a/handlers/coverage.out +++ b/handlers/coverage.out @@ -5,8 +5,8 @@ github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:42.46,50.21 8 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:50.21,52.5 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:54.4,55.23 2 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:55.23,57.5 1 1 -github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:58.4,59.29 2 1 -github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:59.29,64.19 5 1 +github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:58.4,59.30 2 1 +github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:59.30,64.19 5 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:64.19,72.6 6 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:73.5,74.24 2 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:74.24,80.6 5 1 @@ -17,7 +17,7 @@ github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:86.38,88.8 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:90.6,92.33 3 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:95.5,96.24 2 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:96.24,103.6 6 1 -github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:105.5,107.28 2 1 +github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:105.5,107.29 2 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:109.4,113.63 4 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:114.9,116.4 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:121.74,125.9 4 1 @@ -34,8 +34,8 @@ github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:172.4,172.58 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:173.9,175.4 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:180.72,184.9 4 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:184.9,188.46 4 1 -github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:188.46,195.20 6 1 -github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:195.20,198.5 2 1 +github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:188.46,195.23 6 1 +github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:195.23,198.5 2 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:199.4,199.58 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminBlogHandler.go:201.9,203.4 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminCommentHandler.go:34.81,38.9 4 1 @@ -50,7 +50,7 @@ github.com/Ulbora/go-micro-blog-ui/handlers/adminCommentHandler.go:79.24,87.6 7 github.com/Ulbora/go-micro-blog-ui/handlers/adminCommentHandler.go:88.5,90.35 3 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminCommentHandler.go:93.4,94.23 2 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminCommentHandler.go:94.23,101.5 6 1 -github.com/Ulbora/go-micro-blog-ui/handlers/adminCommentHandler.go:103.4,105.59 2 1 +github.com/Ulbora/go-micro-blog-ui/handlers/adminCommentHandler.go:103.4,105.60 2 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminCommentHandler.go:107.9,109.4 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminCommentHandler.go:114.77,118.9 4 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminCommentHandler.go:118.9,122.46 4 1 @@ -87,36 +87,36 @@ github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:80.84,84.9 4 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:84.9,88.46 4 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:88.46,92.26 3 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:92.26,97.5 4 1 -github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:99.4,105.70 6 1 +github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:99.4,105.71 6 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:107.9,109.4 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:114.79,118.9 4 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:118.9,122.46 4 1 -github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:122.46,126.26 3 1 -github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:126.26,131.5 4 1 -github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:133.4,139.65 6 1 +github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:122.46,126.27 3 1 +github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:126.27,131.5 4 1 +github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:133.4,139.66 6 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:141.9,143.4 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:148.72,152.9 4 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:152.9,156.46 4 1 -github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:156.46,165.20 8 1 -github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:165.20,168.5 2 1 +github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:156.46,165.21 8 1 +github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:165.21,168.5 2 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:169.4,169.65 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:170.9,172.4 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:177.73,181.9 4 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:181.9,185.46 4 1 -github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:185.46,194.20 8 1 -github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:194.20,197.5 2 1 +github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:185.46,194.22 8 1 +github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:194.22,197.5 2 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:198.4,198.65 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:199.9,201.4 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:206.81,210.9 4 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:210.9,214.46 4 1 -github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:214.46,223.20 8 1 -github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:223.20,226.5 2 1 +github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:214.46,223.23 8 1 +github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:223.23,226.5 2 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:227.4,227.65 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:228.9,230.4 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:235.81,239.9 4 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:239.9,243.46 4 1 -github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:243.46,252.20 8 1 -github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:252.20,255.5 2 1 +github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:243.46,252.22 8 1 +github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:252.22,255.5 2 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:256.4,256.65 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/adminUserHandler.go:257.9,259.4 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/blogHandler.go:81.73,85.9 4 1 @@ -199,14 +199,14 @@ github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:100.5,100.57 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:104.3,104.49 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:105.8,107.3 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:112.82,121.28 8 1 -github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:121.28,125.103 4 1 -github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:125.103,140.40 13 1 -github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:140.40,152.22 12 1 +github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:121.28,125.105 4 1 +github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:125.105,140.42 13 1 +github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:140.42,152.22 12 1 github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:152.22,159.6 6 1 -github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:160.10,160.26 1 1 -github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:160.26,168.5 7 1 -github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:170.4,170.12 1 1 -github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:170.12,172.12 2 1 +github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:160.10,160.27 1 1 +github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:160.27,168.5 7 1 +github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:170.4,170.13 1 1 +github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:170.13,172.12 2 1 github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:172.12,174.27 2 1 github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:174.27,176.7 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/callbackHandler.go:177.6,180.31 4 1 @@ -225,6 +225,21 @@ github.com/Ulbora/go-micro-blog-ui/handlers/likeHandler.go:43.21,51.21 7 1 github.com/Ulbora/go-micro-blog-ui/handlers/likeHandler.go:51.21,55.6 3 1 github.com/Ulbora/go-micro-blog-ui/handlers/likeHandler.go:56.5,56.51 1 1 github.com/Ulbora/go-micro-blog-ui/handlers/likeHandler.go:58.9,60.4 1 1 +github.com/Ulbora/go-micro-blog-ui/handlers/loggingHandler.go:35.73,42.16 4 1 +github.com/Ulbora/go-micro-blog-ui/handlers/loggingHandler.go:42.16,44.3 1 1 +github.com/Ulbora/go-micro-blog-ui/handlers/loggingHandler.go:44.8,46.37 2 1 +github.com/Ulbora/go-micro-blog-ui/handlers/loggingHandler.go:46.37,48.4 1 1 +github.com/Ulbora/go-micro-blog-ui/handlers/loggingHandler.go:48.9,50.4 1 1 +github.com/Ulbora/go-micro-blog-ui/handlers/loggingHandler.go:51.3,52.34 2 1 +github.com/Ulbora/go-micro-blog-ui/handlers/loggingHandler.go:52.34,58.30 3 1 +github.com/Ulbora/go-micro-blog-ui/handlers/loggingHandler.go:58.30,60.5 1 1 +github.com/Ulbora/go-micro-blog-ui/handlers/loggingHandler.go:60.10,61.38 1 1 +github.com/Ulbora/go-micro-blog-ui/handlers/loggingHandler.go:62.21,66.34 3 1 +github.com/Ulbora/go-micro-blog-ui/handlers/loggingHandler.go:67.20,72.33 3 1 +github.com/Ulbora/go-micro-blog-ui/handlers/loggingHandler.go:73.19,78.32 3 1 +github.com/Ulbora/go-micro-blog-ui/handlers/loggingHandler.go:79.19,84.32 3 1 +github.com/Ulbora/go-micro-blog-ui/handlers/loggingHandler.go:87.9,89.4 1 1 +github.com/Ulbora/go-micro-blog-ui/handlers/loggingHandler.go:90.3,91.33 2 1 github.com/Ulbora/go-micro-blog-ui/handlers/loginHandler.go:35.75,39.9 4 1 github.com/Ulbora/go-micro-blog-ui/handlers/loginHandler.go:39.9,42.51 3 1 github.com/Ulbora/go-micro-blog-ui/handlers/loginHandler.go:42.51,50.4 6 1 diff --git a/handlers/handler.go b/handlers/handler.go index 0f80a7b..b6f5104 100644 --- a/handlers/handler.go +++ b/handlers/handler.go @@ -123,4 +123,5 @@ type Handler interface { // GetComment(w http.ResponseWriter, r *http.Request) // UpdateComment(w http.ResponseWriter, r *http.Request) // GetCommentList(w http.ResponseWriter, r *http.Request) + SetLogLevel(w http.ResponseWriter, r *http.Request) } diff --git a/handlers/loggingHandler.go b/handlers/loggingHandler.go new file mode 100644 index 0000000..403d8d4 --- /dev/null +++ b/handlers/loggingHandler.go @@ -0,0 +1,93 @@ +// Package handlers ... +package handlers + +import ( + "encoding/json" + "fmt" + "net/http" + "os" + "strings" + + lg "github.com/GolangToolKits/go-level-logger" +) + +// LogLevel LogLevel +type LogLevel struct { + Level string `json:"logLevel"` +} + +// LogResponse LogResponse +type LogResponse struct { + Success bool `json:"success"` + LogLevel string `json:"logLevel"` +} + +const ( + defaultLoggingKey = "45sdbb2345" + + debugLevel = "DEBUG" + infoLevel = "INFO" + allLevel = "ALL" + offLevel = "OFF" +) + +// SetLogLevel SetLogLevel +func (h *MCHandler) SetLogLevel(w http.ResponseWriter, r *http.Request) { + var logRes LogResponse + h.setContentType(w) + logContOk := h.checkContent(r) + + //fmt.Println("conOk: ", logContOk) + + if !logContOk { + http.Error(w, "json required", http.StatusUnsupportedMediaType) + } else { + var loggingKey string + if os.Getenv("LOGGING_KEY") != "" { + loggingKey = os.Getenv("LOGGING_KEY") + } else { + loggingKey = defaultLoggingKey + } + loggingKeyHdr := r.Header.Get("Logging_KEY") + if loggingKey == loggingKeyHdr { + var lv LogLevel + lgsuc, lgerr := h.processBody(r, &lv) + //fmt.Println("lgsuc: ", lgsuc) + //fmt.Println("LogLevel: ", lv) + //fmt.Println("lgerr: ", lgerr) + if !lgsuc && lgerr != nil { + http.Error(w, lgerr.Error(), http.StatusBadRequest) + } else { + switch strings.ToUpper(lv.Level) { + case debugLevel: + h.Log.SetLogLevel(lg.DebugLevel) + //h.BTCPlugin.SetLogLevel(lg.DebugLevel) + logRes.Success = true + logRes.LogLevel = debugLevel + case infoLevel: + h.Log.SetLogLevel(lg.InfoLevel) + //h.Log.LogLevel = lg.InfoLevel + //h.BTCPlugin.SetLogLevel(lg.InfoLevel) + logRes.Success = true + logRes.LogLevel = infoLevel + case allLevel: + //h.Log.LogLevel = lg.AllLevel + h.Log.SetLogLevel(lg.AllLevel) + //h.BTCPlugin.SetLogLevel(lg.AllLevel) + logRes.Success = true + logRes.LogLevel = allLevel + case offLevel: + //h.Log.LogLevel = lg.OffLevel + h.Log.SetLogLevel(lg.OffLevel) + //h.BTCPlugin.SetLogLevel(lg.OffLevel) + logRes.Success = true + logRes.LogLevel = offLevel + } + } + } else { + w.WriteHeader(http.StatusUnauthorized) + } + resJSON, _ := json.Marshal(logRes) + fmt.Fprint(w, string(resJSON)) + } +} diff --git a/handlers/loggingHandler_test.go b/handlers/loggingHandler_test.go new file mode 100644 index 0000000..744f7ed --- /dev/null +++ b/handlers/loggingHandler_test.go @@ -0,0 +1,246 @@ +// Package handlers ... +package handlers + +import ( + "bytes" + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + "net/http/httptest" + "os" + "testing" + + lg "github.com/GolangToolKits/go-level-logger" + //pi "github.com/Ulbora/Six910BTCPayServerPlugin" +) + +func TestCmsHandler_SetLogLevel(t *testing.T) { + var oh MCHandler + var logger lg.Logger + oh.Log = &logger + //var pii pi.PayPlugin + //oh.BTCPlugin = pii.New() + + h := oh.New() + aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"debug"}`)) + //aJSON, _ := json.Marshal(robj) + //fmt.Println("aJSON: ", aJSON) + r, _ := http.NewRequest("POST", "/ffllist", aJSON) + //r, _ := http.NewRequest("POST", "/ffllist", nil) + r.Header.Set("Content-Type", "application/json") + r.Header.Set("Logging_KEY", "45sdbb2345") + w := httptest.NewRecorder() + + h.SetLogLevel(w, r) + resp := w.Result() + body, _ := ioutil.ReadAll(resp.Body) + var lres LogResponse + json.Unmarshal(body, &lres) + fmt.Println("body: ", string(body)) + fmt.Println("Code: ", w.Code) + if w.Code != 200 || w.Header().Get("Content-Type") != "application/json" || !lres.Success || lres.LogLevel != "DEBUG" { + t.Fail() + } +} + +func TestCmsHandler_SetLogLevelBadReq(t *testing.T) { + var oh MCHandler + var logger lg.Logger + oh.Log = &logger + + h := oh.New() + //aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"debug"}`)) + //aJSON, _ := json.Marshal(robj) + //fmt.Println("aJSON: ", aJSON) + r, _ := http.NewRequest("POST", "/ffllist", nil) + //r, _ := http.NewRequest("POST", "/ffllist", nil) + r.Header.Set("Content-Type", "application/json") + r.Header.Set("Logging_KEY", "45sdbb2345") + w := httptest.NewRecorder() + h.SetLogLevel(w, r) + resp := w.Result() + body, _ := ioutil.ReadAll(resp.Body) + var lres LogResponse + json.Unmarshal(body, &lres) + fmt.Println("body: ", string(body)) + fmt.Println("Code: ", w.Code) + if w.Code != 400 { + t.Fail() + } +} + +func TestCmsHandler_SetInfoLogLevel(t *testing.T) { + var oh MCHandler + var logger lg.Logger + oh.Log = &logger + + //var pii pi.PayPlugin + //oh.BTCPlugin = pii.New() + + h := oh.New() + aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"info"}`)) + //aJSON, _ := json.Marshal(robj) + //fmt.Println("aJSON: ", aJSON) + r, _ := http.NewRequest("POST", "/ffllist", aJSON) + //r, _ := http.NewRequest("POST", "/ffllist", nil) + r.Header.Set("Content-Type", "application/json") + r.Header.Set("Logging_KEY", "45sdbb2345") + w := httptest.NewRecorder() + h.SetLogLevel(w, r) + resp := w.Result() + body, _ := ioutil.ReadAll(resp.Body) + var lres LogResponse + json.Unmarshal(body, &lres) + fmt.Println("body: ", string(body)) + fmt.Println("Code: ", w.Code) + if w.Code != 200 || w.Header().Get("Content-Type") != "application/json" || !lres.Success || lres.LogLevel != "INFO" { + t.Fail() + } +} + +func TestCmsHandler_SetAllLogLevel(t *testing.T) { + var oh MCHandler + var logger lg.Logger + oh.Log = &logger + + //var pii pi.PayPlugin + //oh.BTCPlugin = pii.New() + + h := oh.New() + aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"all"}`)) + //aJSON, _ := json.Marshal(robj) + //fmt.Println("aJSON: ", aJSON) + r, _ := http.NewRequest("POST", "/ffllist", aJSON) + //r, _ := http.NewRequest("POST", "/ffllist", nil) + r.Header.Set("Content-Type", "application/json") + r.Header.Set("Logging_KEY", "45sdbb2345") + w := httptest.NewRecorder() + h.SetLogLevel(w, r) + resp := w.Result() + body, _ := ioutil.ReadAll(resp.Body) + var lres LogResponse + json.Unmarshal(body, &lres) + fmt.Println("body: ", string(body)) + fmt.Println("Code: ", w.Code) + if w.Code != 200 || w.Header().Get("Content-Type") != "application/json" || !lres.Success || lres.LogLevel != "ALL" { + t.Fail() + } +} + +func TestCmsHandler_SetOffLogLevel(t *testing.T) { + var oh MCHandler + var logger lg.Logger + oh.Log = &logger + + //var pii pi.PayPlugin + //oh.BTCPlugin = pii.New() + + h := oh.New() + aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"off"}`)) + //aJSON, _ := json.Marshal(robj) + //fmt.Println("aJSON: ", aJSON) + r, _ := http.NewRequest("POST", "/ffllist", aJSON) + //r, _ := http.NewRequest("POST", "/ffllist", nil) + r.Header.Set("Content-Type", "application/json") + r.Header.Set("Logging_KEY", "45sdbb2345") + w := httptest.NewRecorder() + h.SetLogLevel(w, r) + resp := w.Result() + body, _ := ioutil.ReadAll(resp.Body) + var lres LogResponse + json.Unmarshal(body, &lres) + fmt.Println("body: ", string(body)) + fmt.Println("Code: ", w.Code) + if w.Code != 200 || w.Header().Get("Content-Type") != "application/json" || !lres.Success || lres.LogLevel != "OFF" { + t.Fail() + } +} + +func TestCmsHandler_SetOffLogLevelLogKey(t *testing.T) { + os.Setenv("LOGGING_KEY", "45sdbb2345") + var oh MCHandler + var logger lg.Logger + oh.Log = &logger + + //var pii pi.PayPlugin + //oh.BTCPlugin = pii.New() + + h := oh.New() + aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"off"}`)) + //aJSON, _ := json.Marshal(robj) + //fmt.Println("aJSON: ", aJSON) + r, _ := http.NewRequest("POST", "/ffllist", aJSON) + //r, _ := http.NewRequest("POST", "/ffllist", nil) + r.Header.Set("Content-Type", "application/json") + r.Header.Set("Logging_KEY", "45sdbb2345") + w := httptest.NewRecorder() + h.SetLogLevel(w, r) + resp := w.Result() + body, _ := ioutil.ReadAll(resp.Body) + var lres LogResponse + json.Unmarshal(body, &lres) + fmt.Println("body: ", string(body)) + fmt.Println("Code: ", w.Code) + if w.Code != 200 || w.Header().Get("Content-Type") != "application/json" || !lres.Success || lres.LogLevel != "OFF" { + t.Fail() + } + os.Unsetenv("LOGGING_KEY") +} + +func TestCmsHandler_SetOffLogLevelLogWrongKey(t *testing.T) { + os.Setenv("LOGGING_KEY", "45sdbb23455") + var oh MCHandler + var logger lg.Logger + oh.Log = &logger + + // var pii pi.PayPlugin + // oh.BTCPlugin = pii.New() + + h := oh.New() + aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"off"}`)) + //aJSON, _ := json.Marshal(robj) + //fmt.Println("aJSON: ", aJSON) + r, _ := http.NewRequest("POST", "/ffllist", aJSON) + //r, _ := http.NewRequest("POST", "/ffllist", nil) + r.Header.Set("Content-Type", "application/json") + r.Header.Set("Logging_KEY", "45sdbb2345") + w := httptest.NewRecorder() + h.SetLogLevel(w, r) + resp := w.Result() + body, _ := ioutil.ReadAll(resp.Body) + var lres LogResponse + json.Unmarshal(body, &lres) + fmt.Println("body: ", string(body)) + fmt.Println("Code: ", w.Code) + if w.Code != 401 { + t.Fail() + } + os.Unsetenv("LOGGING_KEY") +} + +func TestCmsHandler_SetOffLogLevelBadMedia(t *testing.T) { + var oh MCHandler + var logger lg.Logger + oh.Log = &logger + + h := oh.New() + aJSON := ioutil.NopCloser(bytes.NewBufferString(`{"logLevel":"off"}`)) + //aJSON, _ := json.Marshal(robj) + //fmt.Println("aJSON: ", aJSON) + r, _ := http.NewRequest("POST", "/ffllist", aJSON) + //r, _ := http.NewRequest("POST", "/ffllist", nil) + //r.Header.Set("Content-Type", "application/json") + r.Header.Set("Logging_KEY", "45sdbb2345") + w := httptest.NewRecorder() + h.SetLogLevel(w, r) + resp := w.Result() + body, _ := ioutil.ReadAll(resp.Body) + var lres LogResponse + json.Unmarshal(body, &lres) + fmt.Println("body: ", string(body)) + fmt.Println("Code: ", w.Code) + if w.Code != 415 { + t.Fail() + } +} diff --git a/main b/main index 8cc4e3d..8214e27 100755 Binary files a/main and b/main differ diff --git a/main.go b/main.go index aa13b8a..76c8a13 100644 --- a/main.go +++ b/main.go @@ -206,6 +206,7 @@ func main() { router.HandleFunc("/reactivateUser/{uid}", h.ReinstateBannedUser).Methods("GET") router.HandleFunc("/adminConfig", h.GetConfig).Methods("GET") router.HandleFunc("/updateConfig", h.UpdateConfig).Methods("POST") + router.HandleFunc("/rs/loglevel", h.SetLogLevel).Methods("POST") router.PathPrefix("/").Handler(http.FileServer(http.Dir("./static/")))