diff --git a/controllers/authentication.go b/controllers/authentication.go index 25c7b31..a58b71d 100644 --- a/controllers/authentication.go +++ b/controllers/authentication.go @@ -22,6 +22,8 @@ import ( "git.smarteching.com/goffee/cup/utils" "github.com/google/uuid" "gorm.io/gorm" + + "git.smarteching.com/goffee/core/template/components" ) func Signup(c *core.Context) *core.Response { @@ -221,12 +223,6 @@ func Signin(c *core.Context) *core.Response { userAgent := c.GetUserAgent() hashedCacheKey := utils.CreateAuthTokenHashedCacheKey(user.ID, userAgent) err = c.GetCache().Set(hashedCacheKey, token) - - // delete data from old sessions - sessionKey := fmt.Sprintf("sess_%v", userAgent) - hashedSessionKey := utils.CreateAuthTokenHashedCacheKey(user.ID, sessionKey) - _ = c.GetCache().Delete(hashedSessionKey) - if err != nil { c.GetLogger().Error(err.Error()) if TemplateEnable { @@ -452,3 +448,43 @@ func Signout(c *core.Context) *core.Response { "message": "signed out successfully", })) } + +// Show basic app login +func AppLogin(c *core.Context) *core.Response { + + // first, include all compoments + // first, include all compoments + type templateData struct { + PageCard components.PageCard + } + + // now fill data of the components + tmplData := templateData{ + PageCard: components.PageCard{ + CardTitle: "Card title", + CardBody: "Loerm ipsum at deim", + }, + } + return c.Response.Template("login.html", tmplData) +} + +// Show basic app sample +func AppSample(c *core.Context) *core.Response { + + // first, include all compoments + type templateData struct { + PageCard components.PageCard + } + + // now fill data of the components + tmplData := templateData{ + PageCard: components.PageCard{ + CardTitle: "Protected page", + CardBody: "If you can see this page, your are loggedin", + }, + } + //fmt.Printf("Outside cookie user is: %s", user.Email) + + return c.Response.Template("app.html", tmplData) + +} diff --git a/controllers/sample.go b/controllers/sample.go index bc06390..1243d5d 100644 --- a/controllers/sample.go +++ b/controllers/sample.go @@ -5,11 +5,8 @@ package controllers import ( - "fmt" - "git.smarteching.com/goffee/core" "git.smarteching.com/goffee/core/template/components" - "git.smarteching.com/goffee/cup/utils" ) // Show basic template @@ -31,103 +28,3 @@ func Sample(c *core.Context) *core.Response { return c.Response.Template("basic.html", tmplData) } - -// Show basic app login -func AppLogin(c *core.Context) *core.Response { - - // first, include all compoments - // first, include all compoments - type templateData struct { - PageCard components.PageCard - } - - // now fill data of the components - tmplData := templateData{ - PageCard: components.PageCard{ - CardTitle: "Card title", - CardBody: "Loerm ipsum at deim", - }, - } - return c.Response.Template("login.html", tmplData) -} - -// Show basic app login -func AppSession(c *core.Context) *core.Response { - - var session = new(utils.SessionUser) - - // true if session is active - hassession := session.Init(c) - - //session.Set("numberdos", 66) - - type templateData struct { - PageCard components.PageCard - } - - // now fill data of the components - tmplData := templateData{} - - if hassession { - - sesiondata := "" - cardtitle := fmt.Sprintf("Session user id: %v", session.GetUserID()) - numberdos, ok := session.Get("numberdos") - - if numberdos != nil { - numberdos = numberdos.(float64) + 10 - } else { - numberdos = 10 - } - - session.Set("numberdos", numberdos) - - if ok { - sesiondata = fmt.Sprintf("OK, Session numberdos has %v", numberdos) - } else { - sesiondata = fmt.Sprintf("No ok, session numberdos has %v", numberdos) - } - - // delete single - //session.Delete("numberdos") - - // delete all data - //session.Flush() - - tmplData = templateData{ - PageCard: components.PageCard{ - CardTitle: cardtitle, - CardBody: sesiondata, - }, - } - - return c.Response.Template("appsession.html", tmplData) - - } else { - - return c.Response.Template("login.html", tmplData) - - } - -} - -// Show basic app sample -func AppSample(c *core.Context) *core.Response { - - // first, include all compoments - type templateData struct { - PageCard components.PageCard - } - - // now fill data of the components - tmplData := templateData{ - PageCard: components.PageCard{ - CardTitle: "Protected page", - CardBody: "If you can see this page, your are loggedin", - }, - } - //fmt.Printf("Outside cookie user is: %s", user.Email) - - return c.Response.Template("app.html", tmplData) - -} diff --git a/controllers/themedemo.go b/controllers/themedemo.go index 22ba5a5..1373052 100644 --- a/controllers/themedemo.go +++ b/controllers/themedemo.go @@ -114,10 +114,10 @@ func Themeform(c *core.Context) *core.Response { optionc.Value = "buenosaires" optionc.Label = "Buenos Aires" allOptionsc = append(allOptionsc, optionc) - optionc.ID = "london" - optionc.Name = "london" - optionc.Value = "london" - optionc.Label = "London" + optionc.ID = "sogas" + optionc.Name = "sogas" + optionc.Value = "Sogamoso" + optionc.Label = "Sogamoso" //optionc.IsChecked = true allOptionsc = append(allOptionsc, optionc) diff --git a/routes.go b/routes.go index 610fbcb..18c72be 100644 --- a/routes.go +++ b/routes.go @@ -41,7 +41,4 @@ func registerRoutes() { controller.Get("/applogin", controllers.AppLogin, hooks.CheckSessionCookie) controller.Post("/applogin", controllers.AppLogin, hooks.CheckSessionCookie) - - controller.Get("/appsession", controllers.AppSession) - controller.Post("/appsession", controllers.AppSession) } diff --git a/storage/templates/appsession.html b/storage/templates/appsession.html deleted file mode 100644 index 32364f0..0000000 --- a/storage/templates/appsession.html +++ /dev/null @@ -1,12 +0,0 @@ - - - {{template "page_head" "Sample page test session vars"}} -
-