CommonsController.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package controllers
  2. import (
  3. "ColdP_server/controllers/lib"
  4. "ColdP_server/models/Account"
  5. "fmt"
  6. beego "github.com/beego/beego/v2/server/web"
  7. "net/http"
  8. "strings"
  9. "time"
  10. )
  11. type AdminController struct {
  12. beego.Controller
  13. }
  14. func (c *AdminController) Login() {
  15. c.TplName = "login.html"
  16. }
  17. //func (c *AdminController) Login_verification() {
  18. // Admin_user := c.GetString("bzd_username")
  19. // Admin_pass := c.GetString("bzd_password")
  20. // companyId := c.GetString("company_id")
  21. //
  22. // println("Login_verification", Admin_user, Admin_pass)
  23. // err, admin_r := Account.Read_AdminLogin_verification(Admin_user, Admin_pass)
  24. //
  25. // if err != nil {
  26. // c.Data["json"] = lib.JSONS{Code: 202, Msg: "账号密码错误!"}
  27. // c.ServeJSON()
  28. // return
  29. // }
  30. //
  31. // if admin_r.T_pids == "*" {
  32. // User_tokey := Account.Add_Tokey_Set(admin_r.T_uuid, companyId)
  33. // c.Ctx.SetCookie("User_tokey", User_tokey, time.Second*60*60)
  34. // c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK!", Data: User_tokey}
  35. // c.ServeJSON()
  36. // return
  37. // }
  38. // //如果自定义了公司ID,则标识是管理员,判断是否pids是否存在要操作的pid,并且要求登录用户的PID一定为0
  39. // if companyId != "" && admin_r.T_pid == 0 {
  40. // pids := strings.Split(admin_r.T_pids, "|")
  41. // for _, v := range pids {
  42. // newV := strings.Replace(v, "P", "", -1)
  43. // if newV == companyId {
  44. // User_tokey := Account.Add_Tokey_Set(admin_r.T_uuid, companyId)
  45. // c.Ctx.SetCookie("User_tokey", User_tokey, time.Second*60*60)
  46. // c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK!", Data: User_tokey}
  47. // c.ServeJSON()
  48. // return
  49. // }
  50. // }
  51. // //不存在该公司的Pid
  52. // c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有操作该公司的权限!"}
  53. // c.ServeJSON()
  54. // return
  55. // } else {
  56. // User_tokey := Account.Add_Tokey_Set(admin_r.T_uuid, fmt.Sprintf("%d", admin_r.T_pid))
  57. // c.Ctx.SetCookie("User_tokey", User_tokey, time.Second*60*60)
  58. // c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK!", Data: User_tokey}
  59. // c.ServeJSON()
  60. // return
  61. // }
  62. //
  63. //}
  64. func (c *AdminController) Login_verification() {
  65. Admin_user := c.GetString("bzd_username")
  66. Admin_pass := c.GetString("bzd_password")
  67. companyId := c.GetString("company_id")
  68. println("Login_verification", Admin_user, Admin_pass)
  69. err, admin_r := Account.ReadAdminLoginVerification(Admin_user, Admin_pass)
  70. if err != nil {
  71. c.Data["json"] = lib.JSONS{Code: 202, Msg: "账号密码错误!"}
  72. c.ServeJSON()
  73. return
  74. }
  75. if admin_r.T_pids == "*" {
  76. User_tokey := Account.Add_Tokey_Set(admin_r.T_uuid, companyId)
  77. c.Ctx.SetCookie("User_tokey", User_tokey, time.Second*60*60)
  78. c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK!", Data: User_tokey}
  79. c.ServeJSON()
  80. return
  81. }
  82. //如果自定义了公司ID,则标识是管理员,判断是否pids是否存在要操作的pid,并且要求登录用户的PID一定为0
  83. if companyId != "" && admin_r.T_pid == 0 {
  84. pids := strings.Split(admin_r.T_pids, "|")
  85. for _, v := range pids {
  86. newV := strings.Replace(v, "P", "", -1)
  87. if newV == companyId {
  88. User_tokey := Account.Add_Tokey_Set(admin_r.T_uuid, companyId)
  89. c.Ctx.SetCookie("User_tokey", User_tokey, time.Second*60*60)
  90. c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK!", Data: User_tokey}
  91. c.ServeJSON()
  92. return
  93. }
  94. }
  95. //不存在该公司的Pid
  96. c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有操作该公司的权限!"}
  97. c.ServeJSON()
  98. return
  99. } else {
  100. User_tokey := Account.Add_Tokey_Set(admin_r.T_uuid, fmt.Sprintf("%d", admin_r.T_pid))
  101. c.Ctx.SetCookie("User_tokey", User_tokey, time.Second*60*60)
  102. c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK!", Data: User_tokey}
  103. c.ServeJSON()
  104. return
  105. }
  106. }
  107. // func (c *AdminController) Info() {
  108. //
  109. // // 验证登录
  110. // b_, user_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  111. // if !b_ {
  112. // c.Data["json"] = lib.JSONS{Code: 202, Msg: "no"}
  113. // c.ServeJSON()
  114. // return
  115. // }
  116. //
  117. // c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok", Data: Account.AdminToAdmin_R(user_r)}
  118. // c.ServeJSON()
  119. // return
  120. // }
  121. func (c *AdminController) Info() {
  122. // 验证登录
  123. b_, user_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  124. if !b_ {
  125. c.Data["json"] = lib.JSONS{Code: 202, Msg: "no"}
  126. c.ServeJSON()
  127. return
  128. }
  129. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok", Data: Account.ColdpUserToColdpUser_R(user_r)}
  130. c.ServeJSON()
  131. return
  132. }
  133. func (c *AdminController) Index() {
  134. // 验证登录
  135. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  136. if !b_ {
  137. c.Ctx.Redirect(302, "Login")
  138. return
  139. }
  140. // 基本信息
  141. c.Data["Admin_name"] = admin_r.T_name
  142. c.Data["Admin_root"] = admin_r.Id
  143. c.TplName = "index.html"
  144. }
  145. func (c *AdminController) Home() {
  146. b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  147. if !b_ {
  148. fmt.Println("当前未登录,请先登录!")
  149. c.Ctx.Redirect(http.StatusFound, "Login")
  150. }
  151. c.Data["T_pid"] = admin_r.T_pid
  152. c.Data["names"] = admin_r.T_name
  153. fmt.Println("======================>", admin_r.T_pid, admin_r.T_name)
  154. c.TplName = "home.html"
  155. }