v2
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"management/internal/db/model/dto"
|
||||
db "management/internal/db/sqlc"
|
||||
"management/internal/pkg/convertor"
|
||||
"management/internal/router/manage/util"
|
||||
categoryservice "management/internal/service/category"
|
||||
"management/internal/tpl"
|
||||
@@ -28,12 +29,12 @@ func (h *CategoryHandler) List(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (h *CategoryHandler) PostList(w http.ResponseWriter, r *http.Request) {
|
||||
var q dto.SearchDto
|
||||
q.SearchStatus = util.ConvertInt(r.PostFormValue("SearchStatus"), 9999)
|
||||
q.SearchParentID = util.ConvertInt(r.PostFormValue("SearchParentID"), 0)
|
||||
q.SearchName = r.PostFormValue("SearchName")
|
||||
q.SearchKey = r.PostFormValue("SearchKey")
|
||||
q.Page = util.ConvertInt(r.PostFormValue("page"), 1)
|
||||
q.Rows = util.ConvertInt(r.PostFormValue("rows"), 10)
|
||||
q.SearchStatus = convertor.ConvertInt(r.PostFormValue("status"), 9999)
|
||||
q.SearchParentID = convertor.ConvertInt(r.PostFormValue("parentId"), 0)
|
||||
q.SearchName = r.PostFormValue("name")
|
||||
q.SearchID = convertor.ConvertInt[int64](r.PostFormValue("id"), 0)
|
||||
q.Page = convertor.ConvertInt(r.PostFormValue("page"), 1)
|
||||
q.Rows = convertor.ConvertInt(r.PostFormValue("rows"), 10)
|
||||
res, count, err := categoryservice.ListCategoriesCondition(r.Context(), q)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@@ -194,19 +195,32 @@ func (h *CategoryHandler) DTree(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (h *CategoryHandler) XmSelect(w http.ResponseWriter, r *http.Request) {
|
||||
all, err := categoryservice.ListByLetter(r.Context(), r.URL.Query().Get("letter"))
|
||||
letter := r.URL.Query().Get("letter")
|
||||
ctx := r.Context()
|
||||
if len(letter) > 0 {
|
||||
all, err := categoryservice.ListByLetter(ctx, letter)
|
||||
if err != nil {
|
||||
tpl.JSONERR(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var res []*dto.XmSelectStrDto
|
||||
for _, v := range all {
|
||||
res = append(res, &dto.XmSelectStrDto{
|
||||
Name: v.Name,
|
||||
Value: strconv.FormatInt(int64(v.ID), 10),
|
||||
})
|
||||
}
|
||||
tpl.JSON(w, res)
|
||||
return
|
||||
}
|
||||
|
||||
res, err := categoryservice.XmSelectCategory(ctx, 0)
|
||||
if err != nil {
|
||||
tpl.JSONERR(w, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var res []*dto.XmSelectStrDto
|
||||
for _, v := range all {
|
||||
res = append(res, &dto.XmSelectStrDto{
|
||||
Name: v.Name,
|
||||
Value: strconv.FormatInt(int64(v.ID), 10),
|
||||
})
|
||||
}
|
||||
tpl.JSON(w, res)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,7 @@ import (
|
||||
|
||||
"management/internal/db/model/dto"
|
||||
db "management/internal/db/sqlc"
|
||||
authglobal "management/internal/global/auth"
|
||||
"management/internal/pkg/crypto"
|
||||
"management/internal/pkg/session"
|
||||
captchaservice "management/internal/service/captcha"
|
||||
systemservice "management/internal/service/system"
|
||||
"management/internal/tpl"
|
||||
@@ -19,19 +17,19 @@ import (
|
||||
)
|
||||
|
||||
func Login(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
var user dto.AuthorizeUser
|
||||
u := session.GetBytes(ctx, authglobal.StoreName)
|
||||
if err := json.Unmarshal(u, &user); err == nil {
|
||||
// 判断租户是否一致, 一致则刷新令牌,跳转到首页
|
||||
if err := session.RenewToken(ctx); err == nil {
|
||||
session.Put(ctx, authglobal.StoreName, u)
|
||||
http.Redirect(w, r, "/home.html", http.StatusFound)
|
||||
return
|
||||
}
|
||||
}
|
||||
// ctx := r.Context()
|
||||
// var user dto.AuthorizeUser
|
||||
// u := session.GetBytes(ctx, authglobal.StoreName)
|
||||
// if err := json.Unmarshal(u, &user); err == nil {
|
||||
// // 判断租户是否一致, 一致则刷新令牌,跳转到首页
|
||||
// if err := session.RenewToken(ctx); err == nil {
|
||||
// session.Put(ctx, authglobal.StoreName, u)
|
||||
// http.Redirect(w, r, "/home.html", http.StatusFound)
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
|
||||
session.Destroy(ctx)
|
||||
// session.Destroy(ctx)
|
||||
tpl.HTML(w, r, "oauth/login.tmpl", nil)
|
||||
}
|
||||
|
||||
@@ -122,7 +120,7 @@ func PostLogin(w http.ResponseWriter, r *http.Request) {
|
||||
Browser: log.Browser,
|
||||
}
|
||||
|
||||
b, err := json.Marshal(auth)
|
||||
_, err = json.Marshal(auth)
|
||||
if err != nil {
|
||||
log.Message = err.Error()
|
||||
_ = systemservice.CreateSysUserLoginLog(ctx, log)
|
||||
@@ -130,15 +128,15 @@ func PostLogin(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
session.Put(ctx, authglobal.StoreName, b)
|
||||
// session.Put(ctx, authglobal.StoreName, b)
|
||||
|
||||
log.IsSuccess = true
|
||||
log.Message = "登陆成功"
|
||||
_ = systemservice.CreateSysUserLoginLog(ctx, log)
|
||||
tpl.JSON(w, tpl.Response{Success: true, Message: "login successful"})
|
||||
tpl.JSONOK(w, "login successful")
|
||||
}
|
||||
|
||||
func Logout(w http.ResponseWriter, r *http.Request) {
|
||||
session.Destroy(r.Context())
|
||||
// session.Destroy(r.Context())
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"management/internal/middleware/manage/audit"
|
||||
"management/internal/middleware/manage/auth"
|
||||
"management/internal/middleware/manage/nosurf"
|
||||
"management/internal/middleware/manage/session"
|
||||
|
||||
budgethandler "management/internal/router/manage/budget"
|
||||
cachehandler "management/internal/router/manage/cache"
|
||||
@@ -38,8 +37,8 @@ func NewRouter() *chi.Mux {
|
||||
r.Handle("/upload/*", http.StripPrefix("/upload", uploadServer))
|
||||
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(nosurf.NoSurf) // CSRF
|
||||
r.Use(session.LoadSession) // Session
|
||||
r.Use(nosurf.NoSurf) // CSRF
|
||||
// r.Use(session.LoadSession) // Session
|
||||
|
||||
r.Get("/captcha", commonhandler.Captcha)
|
||||
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"management/internal/db/model/dto"
|
||||
db "management/internal/db/sqlc"
|
||||
"management/internal/global/auth"
|
||||
"management/internal/pkg/session"
|
||||
"management/internal/router/manage/util"
|
||||
systemservice "management/internal/service/system"
|
||||
"management/internal/tpl"
|
||||
@@ -189,20 +185,20 @@ func (h *SysMenuHandler) Save(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (h *SysMenuHandler) UserMenus(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
b := session.GetBytes(ctx, auth.StoreName)
|
||||
var u dto.AuthorizeUser
|
||||
if err := json.Unmarshal(b, &u); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
menus, err := systemservice.RecursiveSysMenus(ctx, u.RoleID)
|
||||
if err != nil {
|
||||
tpl.JSON(w, tpl.Response{Success: false, Message: err.Error()})
|
||||
return
|
||||
}
|
||||
// ctx := r.Context()
|
||||
// b := session.GetBytes(ctx, auth.StoreName)
|
||||
// var u dto.AuthorizeUser
|
||||
// if err := json.Unmarshal(b, &u); err != nil {
|
||||
// http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
// return
|
||||
// }
|
||||
// menus, err := systemservice.RecursiveSysMenus(ctx, u.RoleID)
|
||||
// if err != nil {
|
||||
// tpl.JSON(w, tpl.Response{Success: false, Message: err.Error()})
|
||||
// return
|
||||
// }
|
||||
|
||||
tpl.JSON(w, menus)
|
||||
tpl.JSON(w, nil)
|
||||
}
|
||||
|
||||
func (h *SysMenuHandler) XmSelectTree(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"management/internal/db/model/dto"
|
||||
db "management/internal/db/sqlc"
|
||||
"management/internal/pkg/convertor"
|
||||
"management/internal/router/manage/util"
|
||||
systemservice "management/internal/service/system"
|
||||
"management/internal/tpl"
|
||||
@@ -25,14 +26,13 @@ func (h *SysRoleHandler) List(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (h *SysRoleHandler) PostList(w http.ResponseWriter, r *http.Request) {
|
||||
var q dto.SearchDto
|
||||
q.SearchStatus = util.ConvertInt(r.PostFormValue("SearchStatus"), 9999)
|
||||
q.SearchParentID = util.ConvertInt(r.PostFormValue("SearchParentID"), 0)
|
||||
q.SearchName = r.PostFormValue("SearchName")
|
||||
q.SearchKey = r.PostFormValue("SearchKey")
|
||||
q.Page = util.ConvertInt(r.PostFormValue("page"), 1)
|
||||
q.Rows = util.ConvertInt(r.PostFormValue("rows"), 10)
|
||||
ctx := r.Context()
|
||||
res, count, err := systemservice.ListSysRoleCondition(ctx, q)
|
||||
q.SearchStatus = convertor.ConvertInt(r.PostFormValue("status"), 9999)
|
||||
q.SearchParentID = convertor.ConvertInt(r.PostFormValue("parentId"), 0)
|
||||
q.SearchName = r.PostFormValue("name")
|
||||
q.SearchID = convertor.ConvertInt[int64](r.PostFormValue("id"), 0)
|
||||
q.Page = convertor.ConvertInt(r.PostFormValue("page"), 1)
|
||||
q.Rows = convertor.ConvertInt(r.PostFormValue("rows"), 10)
|
||||
res, count, err := systemservice.ListSysRoleCondition(r.Context(), q)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@@ -141,7 +141,7 @@ func (h *SysRoleHandler) Save(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (h *SysRoleHandler) XmSelect(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
res, err := systemservice.XmSelectSysRole(ctx)
|
||||
res, err := systemservice.XmSelectSysRole(ctx, 0)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user