login.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * @description:
  3. * @Author: CP
  4. * @Date: 2020-08-28 10:26:02
  5. * @FilePath: \construction_management\web\controllers\login.go
  6. */
  7. package controllers
  8. import (
  9. "fmt"
  10. "strings"
  11. "github.com/kataras/iris/v12"
  12. "github.com/kataras/iris/v12/mvc"
  13. "go.mod/comm"
  14. "go.mod/services"
  15. )
  16. type LoginController struct {
  17. //框架-web应用上下文环境
  18. Ctx iris.Context
  19. // 需要用的service
  20. ServiceProjectAccount services.ProjectAccountService
  21. ServiceLogin services.LoginService
  22. }
  23. // 默认首页
  24. func (c *LoginController) Get() mvc.Result {
  25. return mvc.Response{
  26. Path: "/login",
  27. }
  28. }
  29. //登录页面
  30. func (c *LoginController) GetLogin() mvc.Result {
  31. //msg := c.Ctx.URLParam("err")
  32. //fmt.Println(msg)
  33. return mvc.View{
  34. Name: "login/login.html",
  35. Data: iris.Map{
  36. "Title": "用户登录",
  37. "Channel": "login",
  38. "Action": "login",
  39. },
  40. Layout: "login/layout.html",
  41. }
  42. }
  43. //登陆
  44. func (c *LoginController) PostLogin() {
  45. refer := "/project"
  46. //TODO -1验证规则
  47. err := c.ServiceLogin.ValidLogin(c.Ctx)
  48. if err != nil {
  49. s := strings.Split(fmt.Sprintf("%s", err), ";")
  50. fmt.Println(s[0])
  51. refer = fmt.Sprintf("/login?err=%s", err)
  52. }
  53. //TODO -2验证登陆
  54. comm.Redirect(c.Ctx.ResponseWriter(), refer)
  55. //c.Ctx.Writef("You're welcome mate!")
  56. //refer := fmt.Sprintf("/login?err=%s", err)
  57. //comm.Redirect(c.Ctx.ResponseWriter(), refer)
  58. // return mvc.View{
  59. // Name: "login/login.html",
  60. // Data: iris.Map{
  61. // "Title": "用户登录",
  62. // "Channel": "login",
  63. // "Action": "login",
  64. // },
  65. // Layout: "login/layout.html",
  66. // }
  67. }
  68. //自定义请求
  69. func (c *LoginController) BeforeActivation(b mvc.BeforeActivation) {
  70. anyMiddlewareHere := func(ctx iris.Context) {
  71. ctx.Application().Logger().Warnf("Inside /custom_path")
  72. ctx.Next()
  73. }
  74. b.Handle("GET", "/something", "MyCustomHandlerc", anyMiddlewareHere)
  75. }
  76. func (c *LoginController) MyCustomHandlerc() string {
  77. // rs := make(map[string]interface{})
  78. // rs["code"] = 0
  79. // rs["msg"] = ""
  80. // datalist := c.ServiceGift.GetAll(true)
  81. // list := make([]models.LtGift, 0)
  82. // for _, data := range datalist {
  83. // // 正常状态的才需要放进来
  84. // if data.SysStatus == 0 {
  85. // list = append(list, data)
  86. // }
  87. // }
  88. // rs["gifts"] = list
  89. // return rs
  90. fmt.Println("out")
  91. return "MyCustomHandler says Hey"
  92. // c.Ctx.Header("Content-Type", "text/html")
  93. // return "out"
  94. }