package controllers import ( "github.com/kataras/iris/v12/mvc" "xps/service" ) type LoginController struct { Base Service service.LoginService } func (c *LoginController) BeforeActivation(b mvc.BeforeActivation) { b.Handle("POST", "/login", "Login" ) b.Handle("GET", "/logout", "Logout" ) b.Handle("GET", "/test", "GetTest" ) b.Handle("GET", "/hello", "GetHello" ) } func (c *LoginController) Login() *JsonResult { username := c.Ctx.FormValue("username") password := c.Ctx.FormValue("password") userNameErr := validate.Var(username, "required,min=4,max=32") if userNameErr != nil { return ResultErr("用户名格式错误", nil) } pwdErr := validate.Var(password, "required,min=4,max=20") if pwdErr != nil { return ResultErr("密码格式错误", nil) } bRet, msg, data := c.Service.CheckLogin(username, password) if !bRet { return ResultErr(msg, data) } else { return ResultOk(msg, data) } } func (c *LoginController) Logout() *JsonResult { userId := c.GetCurOcId() if userId > 0 { _ = c.Service.Logout(userId) } return ResultOk("登出成功", nil) } func (c *LoginController) GetTest() mvc.Response { return mvc.Response{ ContentType: "text/html", Text: "