| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package controller
- 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: "<h1>Test</h1>",
- }
- }
- func (c *LoginController) GetHello() interface{} {
- return map[string]string{"message": "hello iris"}
- }
|