123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- /*
- * @description:
- * @Author: CP
- * @Date: 2020-08-28 10:26:02
- * @FilePath: \construction_management\web\controllers\login.go
- */
- package controllers
- import (
- "fmt"
- "strings"
- "github.com/kataras/iris/v12"
- "github.com/kataras/iris/v12/mvc"
- "go.mod/comm"
- "go.mod/services"
- )
- type LoginController struct {
- //框架-web应用上下文环境
- Ctx iris.Context
- // 需要用的service
- ServiceProjectAccount services.ProjectAccountService
- ServiceLogin services.LoginService
- }
- // 默认首页
- func (c *LoginController) Get() mvc.Result {
- return mvc.Response{
- Path: "/login",
- }
- }
- //登录页面
- func (c *LoginController) GetLogin() mvc.Result {
- //msg := c.Ctx.URLParam("err")
- //fmt.Println(msg)
- return mvc.View{
- Name: "login/login.html",
- Data: iris.Map{
- "Title": "用户登录",
- "Channel": "login",
- "Action": "login",
- },
- Layout: "login/layout.html",
- }
- }
- //登陆
- func (c *LoginController) PostLogin() {
- refer := "/project"
- //TODO -1验证规则
- err := c.ServiceLogin.ValidLogin(c.Ctx)
- if err != nil {
- s := strings.Split(fmt.Sprintf("%s", err), ";")
- fmt.Println(s[0])
- refer = fmt.Sprintf("/login?err=%s", err)
- }
- //TODO -2验证登陆
- comm.Redirect(c.Ctx.ResponseWriter(), refer)
- //c.Ctx.Writef("You're welcome mate!")
- //refer := fmt.Sprintf("/login?err=%s", err)
- //comm.Redirect(c.Ctx.ResponseWriter(), refer)
- // return mvc.View{
- // Name: "login/login.html",
- // Data: iris.Map{
- // "Title": "用户登录",
- // "Channel": "login",
- // "Action": "login",
- // },
- // Layout: "login/layout.html",
- // }
- }
- //自定义请求
- func (c *LoginController) BeforeActivation(b mvc.BeforeActivation) {
- anyMiddlewareHere := func(ctx iris.Context) {
- ctx.Application().Logger().Warnf("Inside /custom_path")
- ctx.Next()
- }
- b.Handle("GET", "/something", "MyCustomHandlerc", anyMiddlewareHere)
- }
- func (c *LoginController) MyCustomHandlerc() string {
- // rs := make(map[string]interface{})
- // rs["code"] = 0
- // rs["msg"] = ""
- // datalist := c.ServiceGift.GetAll(true)
- // list := make([]models.LtGift, 0)
- // for _, data := range datalist {
- // // 正常状态的才需要放进来
- // if data.SysStatus == 0 {
- // list = append(list, data)
- // }
- // }
- // rs["gifts"] = list
- // return rs
- fmt.Println("out")
- return "MyCustomHandler says Hey"
- // c.Ctx.Header("Content-Type", "text/html")
- // return "out"
- }
|