// SetLanguage switches language, between swahili and english. This means when this // handler is accessed, if the current language is en it will be set to sw and vice versa. // // Method GET // // Route /language/:lang // // Restrictions None // // Template None ( Redirection is made to home route ("/")) func SetLanguage(ctx *echo.Context) error { lang := ctx.Param("lang") var language string switch lang { case "en", "sw": language = lang default: language = "en" } store := session.New() sess, _ := store.Get(ctx.Request(), settings.LangSessionName) sess.Values[settings.LangSessionKey] = language store.Save(ctx.Request(), ctx.Response(), sess) ctx.Redirect(http.StatusFound, "/") return nil }
import ( "encoding/gob" "github.com/gernest/zedlist/modules/log" "github.com/gernest/zedlist/modules/session" "github.com/gernest/zedlist/modules/settings" "github.com/labstack/echo" ) func init() { gob.Register(&Flash{}) gob.Register(Flashes{}) } var store = session.New() // Flash implements flash messages, like ones in gorilla/sessions type Flash struct { Kind string Message string } // Flashes is a collection of flash messages type Flashes []*Flash // GetFlashes retieves all flash messages found in a cookie session associated with ctx.. // // BUG multipleflash messages are not propery set. the flashes contains only the first // message to be set. func GetFlashes(ctx *echo.Context) Flashes {
"github.com/gernest/zedlist/modules/session" "github.com/gernest/zedlist/modules/settings" "github.com/gernest/zedlist/modules/tmpl" "github.com/labstack/echo" ) const ( msgAccountCreate = "flash_account_create" msgAccountCreateFailed = "flash_account_create_fail" msgLoginSuccess = "flash_login_success" msgLoginErr = "flash_login_failed" authForm = "AuthForm" ) var sessStore = session.New() // Login renders login form. // // Method GET // // Route /auth/login // // Restrictions None // // Template auth/login.html // func Login(ctx *echo.Context) error { f := forms.New(utils.GetLang(ctx)) utils.SetData(ctx, authForm, f.LoginForm()())