golang – Redirect in POST method in Iris Framework

// login_controllers.go
package controllers

import (
    "github.com/kataras/iris/mvc"
    "github.com/kataras/iris"
    "fmt"
)

type LoginFormData struct {
    Email string
    Password string
}


type LoginController struct {
    mvc.C
}

func (c *LoginController) Get() mvc.Result {
    return mvc.View{
        Name: "login.html",
    }
}

func (c *LoginController) Post() {
    userLoginData := LoginFormData{}
    err := c.Ctx.ReadForm(&userLoginData)
    if err != nil {
        c.Ctx.StatusCode(iris.StatusInternalServerError)
        c.Ctx.WriteString(err.Error())
    }

    if userLoginData.Email == "teste@teste.com" && userLoginData.Password == "123" {
        c.Ctx.Redirect("/", iris.StatusSeeOther)

        fmt.Printf("UserInner: %#v", userLoginData)
        c.Ctx.Writef("UserInner: %#v", userLoginData)
    }
}
https://stackoverflow.com/questions/48037167/redirect-in-post-method-in-iris-framework

Share and Enjoy !

0Shares
0 0 0