diff --git a/cmd/main.go b/cmd/main.go index bf3e16d..0258924 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -38,6 +38,14 @@ func main() { handlers.SetupRoutes(app, h) + LStore, err := db.NewLoginStore(dbName) + if err != nil { + app.Logger.Fatalf("failed to create store: %s", err) + } + l := services.NewServicesLogin(services.Login{}, LStore) + lh := handlers.NewLoginHandler(l) + handlers.SetupRoutesLogin(app, lh) + xStore, err := db.NewXsampleStore(dbName) if err != nil { app.Logger.Fatalf("failed to create store: %s", err) diff --git a/db/login.store.go b/db/login.store.go new file mode 100644 index 0000000..47ea165 --- /dev/null +++ b/db/login.store.go @@ -0,0 +1,26 @@ +package db + +import ( + "database/sql" + + _ "github.com/glebarez/go-sqlite" +) + +type LoginStore struct { + Db *sql.DB +} + +func NewLoginStore(dbName string) (LoginStore, error) { + Db, err := getConnection(dbName) + if err != nil { + return LoginStore{}, err + } + + if err := createMigrations(dbName, Db); err != nil { + return LoginStore{}, err + } + + return LoginStore{ + Db, + }, nil +} diff --git a/handlers/login.handlers.go b/handlers/login.handlers.go index 1a390ef..1559a8c 100644 --- a/handlers/login.handlers.go +++ b/handlers/login.handlers.go @@ -2,19 +2,34 @@ package handlers import ( "github.com/a-h/templ" + "github.com/emarifer/go-templ-project-structure/services" "github.com/emarifer/go-templ-project-structure/views/login" "github.com/labstack/echo/v4" ) -func HandlerShowLoginCompany(c echo.Context) error { - - // si := user.ShowIndex("| Home", user.Show(udata)) - si := login.ShowLogin("Login ", login.DivLogin(), login.CssLogin(), login.JsLogin()) - - return ViewLoginCompany(c, si) +type LoginService interface { + GetLogin(Email string, Password string) (services.Login, error) } -func ViewLoginCompany(c echo.Context, cmp templ.Component) error { + +func NewLoginHandler(us LoginService) *LoginHandler { + return &LoginHandler{ + LoginService: us, + } +} + +type LoginHandler struct { + LoginService LoginService +} + +func (lh *LoginHandler) HandlerShowLogin(c echo.Context) error { + + si := login.ShowLogin("Login ", login.MainLogin(), login.CssLogin(), login.JsLogin()) + + return lh.ViewLogin(c, si) +} + +func (uh *LoginHandler) ViewLogin(c echo.Context, cmp templ.Component) error { c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML) return cmp.Render(c.Request().Context(), c.Response().Writer) diff --git a/handlers/routes.go b/handlers/routes.go index 5196bcf..180cbe5 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -11,6 +11,10 @@ func SetupRoutes(app *echo.Echo, h *UserHandler) { } //PLAYGROUND TESTING +func SetupRoutesLogin(app *echo.Echo, h *LoginHandler) { + l := app.Group("/login") + l.GET("/", h.HandlerShowLogin) +} func SetupRoutesXsample(app *echo.Echo, h *XsampleHandler) { xSample := app.Group("/xsample") xSample.GET("/xsample01", h.Hello) diff --git a/services/login.services.go b/services/login.services.go new file mode 100644 index 0000000..0ffa532 --- /dev/null +++ b/services/login.services.go @@ -0,0 +1,59 @@ +package services + +import ( + "time" + + "github.com/emarifer/go-templ-project-structure/db" +) + +func NewServicesLogin(u Login, uStore db.LoginStore) *ServicesLogin { + + return &ServicesLogin{ + Login: u, + LoginStore: uStore, + } +} + +type Login struct { + ID int `json:"id"` + Loginname string `json:"Loginname"` + Email string `json:"Email"` + Password string `json:"Password"` + CreatedAt time.Time `json:"created_at,omitempty"` +} + +type ServicesLogin struct { + Login Login + LoginStore db.LoginStore +} + +func (su *ServicesLogin) GetLogin(Email string, Password string) (Login, error) { + + query := `SELECT id, Loginname, Email, Password, created_at FROM Login + WHERE Email = ? AND Password = ?` + + stmt, err := su.LoginStore.Db.Prepare(query) + if err != nil { + return Login{}, err + } + + defer stmt.Close() + + su.Login.Email = Email + su.Login.Password = Password + err = stmt.QueryRow( + su.Login.Email, + su.Login.Password, + ).Scan( + &su.Login.ID, + &su.Login.Loginname, + &su.Login.Email, + &su.Login.Password, + &su.Login.CreatedAt, + ) + if err != nil { + return Login{}, err + } + + return su.Login, nil +} diff --git a/views/login/login.templ b/views/login/login.templ index 0b177e6..2bc24e4 100644 --- a/views/login/login.templ +++ b/views/login/login.templ @@ -4,44 +4,14 @@ import ( "github.com/emarifer/go-templ-project-structure/views/layout" ) -templ DivLogin() { +templ MainLogin() {
- + @AsideLeft()
@@ -315,73 +52,52 @@ templ DivLogin() { templ CssLogin() { } -.aside-title { - color: #fff; - text-align: center; - font-family: Poppins; - font-size: 28px; - font-style: normal; - font-weight: 600; - line-height: normal; - letter-spacing: -0.84px; -} - -.aside-subtitle { - color: #fff; - text-align: center; - font-family: Poppins; - font-size: 16px; - font-style: normal; - font-weight: 500; - line-height: 30px; - /* 187.5% */ - letter-spacing: -0.48px; -} - -.btn-submit { - background-color: #3b4f9f !important -} - -.btn-cancel { - color: #3b4f9f !important; - background-color: #e1f0ff !important; -} - - -} - -// templ CssLoginCompany() { -// -// } templ JsLogin() { - + } templ ShowLogin(title string, cmp templ.Component, css templ.Component, js templ.Component) { - @layout.CanvasLayout(title, css, js) { + @layout.PlaygroundLayout(title, css, js) { @cmp } } diff --git a/views/login/login_templ.go b/views/login/login_templ.go index cb50060..14c4405 100644 --- a/views/login/login_templ.go +++ b/views/login/login_templ.go @@ -14,7 +14,7 @@ import ( "github.com/emarifer/go-templ-project-structure/views/layout" ) -func DivLogin() templ.Component { +func MainLogin() templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) if !templ_7745c5c3_IsBuffer { @@ -27,7 +27,39 @@ func DivLogin() templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Empowering Your Workforce's Health\r
Discover peace of mind and prioritize your health with our\r comprehensive medical check-up packages\r
\"\"

Welcome to Corporate Portal\r

Sign in to access your account\r

Sign Up\r

Enter your details to create your account\r

\"\"

Forgotten Password ?\r

Enter your email to reset your password\r

") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = AsideLeft().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = FormSignin().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = FormSignup().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = ForgotPassword().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -51,7 +83,7 @@ func CssLogin() templ.Component { templ_7745c5c3_Var2 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -62,13 +94,6 @@ func CssLogin() templ.Component { }) } -// templ CssLoginCompany() { -// -// } func JsLogin() templ.Component { return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) @@ -82,7 +107,7 @@ func JsLogin() templ.Component { templ_7745c5c3_Var3 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -121,7 +146,7 @@ func ShowLogin(title string, cmp templ.Component, css templ.Component, js templ. } return templ_7745c5c3_Err }) - templ_7745c5c3_Err = layout.CanvasLayout(title, css, js).Render(templ.WithChildren(ctx, templ_7745c5c3_Var5), templ_7745c5c3_Buffer) + templ_7745c5c3_Err = layout.PlaygroundLayout(title, css, js).Render(templ.WithChildren(ctx, templ_7745c5c3_Var5), templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/views/login/logincomponent.templ b/views/login/logincomponent.templ new file mode 100644 index 0000000..f7cab2c --- /dev/null +++ b/views/login/logincomponent.templ @@ -0,0 +1,274 @@ +package login + +templ AsideLeft() { + +} + +templ FormSignin() { +
+ +
+ +
+
+

+ Welcome to Corporate Portal +

+
+
+

+ Sign in to access your account +

+
+ + +
+ + +
+ + +
+
+ +
+
+ + +
+ + + + + + +
+
+
+ + + +
+ +
+ +
+} + +templ FormSignup() { +
+ +
+

+ Sign Up +

+

+ Enter your details to create your account +

+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+ +
+} + +templ ForgotPassword() { +
+ +
+ +
+
+

+ Forgotten Password ? +

+

+ Enter your email to reset your password +

+
+ + +
+ +
+ + +
+ + +
+ +
+} diff --git a/views/login/logincomponent_templ.go b/views/login/logincomponent_templ.go new file mode 100644 index 0000000..d919e87 --- /dev/null +++ b/views/login/logincomponent_templ.go @@ -0,0 +1,107 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.663 +package login + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import "context" +import "io" +import "bytes" + +func AsideLeft() templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Empowering Your Workforce's Health\r
Discover peace of mind and prioritize your health with our\r comprehensive medical check-up packages\r
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func FormSignin() templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var2 := templ.GetChildren(ctx) + if templ_7745c5c3_Var2 == nil { + templ_7745c5c3_Var2 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
\"\"

Welcome to Corporate Portal\r

Sign in to access your account\r

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func FormSignup() templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var3 := templ.GetChildren(ctx) + if templ_7745c5c3_Var3 == nil { + templ_7745c5c3_Var3 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Sign Up\r

Enter your details to create your account\r

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func ForgotPassword() templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var4 := templ.GetChildren(ctx) + if templ_7745c5c3_Var4 == nil { + templ_7745c5c3_Var4 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
\"\"

Forgotten Password ?\r

Enter your email to reset your password\r

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +}