user.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package handler
  2. import (
  3. "kpt-pasture/http/middleware"
  4. "net/http"
  5. "strconv"
  6. operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
  7. "gitee.com/xuyiping_admin/pkg/apierr"
  8. "gitee.com/xuyiping_admin/pkg/ginutil"
  9. "gitee.com/xuyiping_admin/pkg/valid"
  10. "github.com/gin-gonic/gin"
  11. )
  12. // GetUserInfo 获取用户信息
  13. func GetUserInfo(c *gin.Context) {
  14. token := middleware.GetToken(c)
  15. if err := valid.Validate(token, valid.Required); err != nil {
  16. apierr.ClassifiedAbort(c, err)
  17. return
  18. }
  19. res, err := middleware.BackendOperation(c).OpsService.GetUserInfo(c, token)
  20. if err != nil {
  21. apierr.ClassifiedAbort(c, err)
  22. return
  23. }
  24. ginutil.JSONResp(c, res)
  25. }
  26. // Details 系统用户详情
  27. func Details(c *gin.Context) {
  28. userIdStr := c.Param("user_id")
  29. userId, _ := strconv.Atoi(userIdStr)
  30. if err := valid.Validate(userId, valid.Required, valid.Min(1)); err != nil {
  31. apierr.ClassifiedAbort(c, err)
  32. return
  33. }
  34. res, err := middleware.BackendOperation(c).OpsService.DetailsSystemUser(c, int64(userId))
  35. if err != nil {
  36. apierr.ClassifiedAbort(c, err)
  37. return
  38. }
  39. ginutil.JSONResp(c, res)
  40. }
  41. // GetUserMenu 获取系统用户菜单权限
  42. func GetUserMenu(c *gin.Context) {
  43. token := middleware.GetToken(c)
  44. if err := valid.Validate(token, valid.Required); err != nil {
  45. apierr.ClassifiedAbort(c, err)
  46. return
  47. }
  48. res, err := middleware.BackendOperation(c).OpsService.GetSystemUserPermissions(c, token)
  49. if err != nil {
  50. apierr.ClassifiedAbort(c, err)
  51. return
  52. }
  53. ginutil.JSONResp(c, res)
  54. }
  55. // Logout 用户登出,
  56. func Logout(c *gin.Context) {
  57. ginutil.JSONResp(c, &operationPb.CommonOK{
  58. Code: http.StatusOK,
  59. Msg: "ok",
  60. Data: &operationPb.Success{Success: true},
  61. })
  62. }