Deprecate previous backend

This commit is contained in:
Arthur Belleville 2026-05-07 23:02:29 +02:00
parent 0a647fc7c4
commit 98952ace6e
No known key found for this signature in database
18 changed files with 792 additions and 259 deletions

View file

@ -1,11 +0,0 @@
{
"src/main.ts": {
"file": "assets/main-B7j1Bbjq.js",
"name": "main",
"src": "src/main.ts",
"isEntry": true,
"css": [
"assets/main-D3T09nt8.css"
]
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,8 +0,0 @@
package frontend
import (
"embed"
)
//go:embed all:dist
var DistFS embed.FS

View file

@ -1,129 +0,0 @@
package spahandler
import (
"fmt"
"io/fs"
"net/http"
"os"
"path/filepath"
"text/template"
"github.com/olivere/vite"
"github.com/rs/zerolog/log"
"xtablo-backend/internal/frontend"
)
type handler struct {
distFS fs.FS
}
func NewHandler() *handler {
distFS, err := fs.Sub(frontend.DistFS, "dist")
if err != nil {
panic(fmt.Errorf("creating sub-filesystem for 'dist' directory: %w", err))
}
return &handler{
distFS: distFS,
}
}
func (h *handler) GetAssets() http.HandlerFunc {
return http.FileServerFS(h.distFS).ServeHTTP
}
func (h *handler) GetSpa() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var err error
defer func() {
if err != nil {
log.Err(err).Msg(err.Error())
}
}()
if r.URL.Path == "/" || r.URL.Path == "/index.html" {
viteFragment, err := vite.HTMLFragment(vite.Config{
FS: h.distFS,
IsDev: false,
})
if err != nil {
log.Err(err).Msg(err.Error())
http.Error(w, "Error instantiating vite fragment", http.StatusInternalServerError)
return
}
tmpl, err := template.New("index").Parse(indexTmpl)
if err != nil {
http.Error(w, "Error parsing template", http.StatusInternalServerError)
return
}
if err = tmpl.Execute(w, map[string]interface{}{
"Vite": viteFragment,
}); err != nil {
http.Error(w, "Error executing template", http.StatusInternalServerError)
return
}
return
}
// Serve the public files generated by Vite. By default, these files are
// referenced in the DOM with a root-relative URL format (e.g. '/file.ext').
http.ServeFileFS(w, r, h.distFS, filepath.Base(r.URL.Path))
}
}
func (h *handler) GetDevSpa() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var err error
defer func() {
if err != nil {
log.Err(err).Msg(err.Error())
}
}()
if r.URL.Path == "/" || r.URL.Path == "/index.html" {
viteFragment, err := vite.HTMLFragment(vite.Config{
FS: os.DirFS("ui"),
IsDev: true,
ViteURL: "http://localhost:5173",
ViteTemplate: vite.SvelteTs,
ViteEntry: "/src/main.ts",
})
if err != nil {
http.Error(w, "Error instantiating vite fragment", http.StatusInternalServerError)
return
}
tmpl, err := template.New("index").Parse(indexTmpl)
if err != nil {
http.Error(w, "Error parsing template", http.StatusInternalServerError)
return
}
if err = tmpl.Execute(w, map[string]interface{}{
"Vite": viteFragment,
}); err != nil {
http.Error(w, "Error executing template", http.StatusInternalServerError)
return
}
return
}
// Serve files in the public directory. By default, these files are
// referenced in the DOM with a root-relative URL format (e.g. '/file.ext').
http.ServeFileFS(w, r, os.DirFS("./public"), filepath.Base(r.URL.Path))
}
}
var indexTmpl = `<!doctype html>
<html lang="en" class="h-full scroll-smooth">
<head>
<meta charset="UTF-8" />
{{ .Vite.Tags }}
</head>
<body class="w-100">
<div id="app"></div>
</body>
</html>
`

View file

@ -1,57 +0,0 @@
package main
import (
"flag"
"net/http"
"time"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
chi "github.com/go-chi/chi/v5"
)
// Here we are implementing the NotImplemented handler. Whenever an API endpoint is hit
// we will simply return the message "Not Implemented"
var NotImplemented = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Not Implemented"))
})
func main() {
// Prepare logger
zerolog.TimeFieldFormat = time.DateTime
var (
isDev = flag.Bool("dev", false, "run in development mode")
)
flag.Parse()
mux := chi.NewRouter()
if *isDev {
registerDevRoutes(mux)
} else {
registerProdRoutes(mux)
}
// Our API is going to consist of three routes
// /status - which we will call to make sure that our API is up and running
// /products - which will retrieve a list of products that the user can leave feedback on
// /products/{slug}/feedback - which will capture user feedback on products
mux.Get("/status", NotImplemented)
mux.Get("/products", NotImplemented)
mux.Post("/products/{slug}/feedback", NotImplemented)
server := &http.Server{
Addr: "0.0.0.0:8443",
Handler: mux,
ReadTimeout: 10 * time.Second,
WriteTimeout: time.Minute,
}
log.Info().Msg("Listening on port 8443...")
if err := server.ListenAndServe(); err != nil {
log.Error().Msg(err.Error())
panic(err)
}
}

View file

@ -1,36 +0,0 @@
package main
import (
chi "github.com/go-chi/chi/v5"
"xtablo-backend/internal/spahandler"
)
func registerProdRoutes(mux *chi.Mux) {
spaHandler := spahandler.NewHandler()
// Handle requests for Vite-managed assets.
mux.Get("/assets/*", spaHandler.GetAssets())
// Handle index.html request
mux.Get("/*", spaHandler.GetSpa())
}
func registerDevRoutes(mux *chi.Mux) {
spaHandler := spahandler.NewHandler()
// Handle index.html request
mux.Get("/*", spaHandler.GetDevSpa())
}
var indexTmpl = `<!doctype html>
<html lang="en" class="h-full scroll-smooth">
<head>
<meta charset="UTF-8" />
{{ .Vite.Tags }}
</head>
<body class="w-100">
<div id="app"></div>
</body>
</html>
`

View file

@ -2,14 +2,13 @@ module xtablo-backend
go 1.23.4
require (
github.com/go-chi/chi/v5 v5.2.0
github.com/olivere/vite v0.0.0-20241125063354-5c2fc1f1ddc2
)
require github.com/go-chi/chi/v5 v5.2.0
require github.com/a-h/templ v0.3.1001
require (
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/rs/zerolog v1.33.0
golang.org/x/sys v0.29.0 // indirect
golang.org/x/sys v0.34.0 // indirect
)

View file

@ -1,8 +1,11 @@
github.com/a-h/templ v0.3.1001 h1:yHDTgexACdJttyiyamcTHXr2QkIeVF1MukLy44EAhMY=
github.com/a-h/templ v0.3.1001/go.mod h1:oCZcnKRf5jjsGpf2yELzQfodLphd2mwecwG4Crk5HBo=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/go-chi/chi/v5 v5.2.0 h1:Aj1EtB0qR2Rdo2dG4O94RIU35w2lvQSj6BRA4+qwFL0=
github.com/go-chi/chi/v5 v5.2.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
@ -10,8 +13,6 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/olivere/vite v0.0.0-20241125063354-5c2fc1f1ddc2 h1:yrFRHF77HTyASeJG/11+Zflj7Z5OVT+oIkeUc/EIwpI=
github.com/olivere/vite v0.0.0-20241125063354-5c2fc1f1ddc2/go.mod h1:GcOsJRAsACfTzrwnVKPHHQb2IpqJo2o7OEGht882nuA=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
@ -19,7 +20,5 @@ github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWR
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=

View file

@ -0,0 +1,48 @@
package handlers
import (
"net/http"
"strings"
"xtablo-backend/internal/web/views"
)
type LoginHandler struct{}
func NewLoginHandler() *LoginHandler {
return &LoginHandler{}
}
func (h *LoginHandler) GetPage() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
if err := views.LoginPage().Render(r.Context(), w); err != nil {
http.Error(w, "failed to render login page", http.StatusInternalServerError)
}
}
}
func (h *LoginHandler) PostLogin() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
http.Error(w, "invalid form payload", http.StatusBadRequest)
return
}
email := strings.TrimSpace(r.FormValue("email"))
password := strings.TrimSpace(r.FormValue("password"))
w.Header().Set("Content-Type", "text/html; charset=utf-8")
switch {
case email == "" || password == "":
w.WriteHeader(http.StatusUnprocessableEntity)
_ = views.LoginStatus("error", "Veuillez renseigner votre email et votre mot de passe.").Render(r.Context(), w)
case email == "demo@xtablo.com" && password == "xtablo-demo":
_ = views.LoginStatus("success", "Connexion reussie. Bienvenue sur XTablo.").Render(r.Context(), w)
default:
w.WriteHeader(http.StatusUnauthorized)
_ = views.LoginStatus("error", "Identifiants invalides. Essayez demo@xtablo.com / xtablo-demo.").Render(r.Context(), w)
}
}
}

View file

@ -0,0 +1,95 @@
package views
templ LoginPage() {
<!doctype html>
<html lang="fr" class="light">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="theme-color" content="#1e1b2e"/>
<title>XTablo</title>
<link rel="stylesheet" href="/static/styles.css"/>
<script src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-beta2/dist/htmx.min.js"></script>
</head>
<body>
<div class="page-shell">
<div class="page-background">
<div class="orb orb-a"><span>X</span></div>
<div class="orb orb-b"><span>X</span></div>
<div class="orb orb-c"><span>X</span></div>
<div class="orb orb-d"><span>X</span></div>
<div class="orb orb-e"><span>X</span></div>
<div class="orb orb-f"><span>X</span></div>
<div class="orb orb-g"><span>X</span></div>
<div class="orb orb-h"><span>X</span></div>
</div>
<main class="auth-stage">
<section class="auth-card">
<div class="auth-glow"></div>
<div class="card-body">
<div class="card-topbar">
<a class="back-link" href="https://www.xtablo.com">Retour a l'accueil</a>
<button type="button" class="theme-button" aria-label="theme placeholder">
<span class="theme-button-monitor"></span>
</button>
</div>
<div class="brand-lockup">
<div class="brand-mark">XT</div>
</div>
<div class="headline-block">
<h1>Se connecter a Xtablo</h1>
</div>
<div class="spotlight-link-wrap">
<a class="spotlight-link" href="/login-v2">Decouvrez la nouvelle experience de connexion</a>
</div>
<form
class="login-form"
hx-post="/login"
hx-target="#login-status"
hx-swap="innerHTML"
>
<div id="login-status" class="status-slot"></div>
<div class="field-group">
<label for="email">Email *</label>
<input id="email" name="email" type="email" placeholder="Votre email" required/>
</div>
<div class="field-group">
<label for="password">Mot de passe *</label>
<input id="password" name="password" type="password" placeholder="Votre mot de passe" required/>
</div>
<div class="aux-row">
<a href="/reset-password">Mot de passe oublie ?</a>
</div>
<button class="primary-button" type="submit">Se connecter</button>
</form>
<div class="divider">
<span>Ou continuer avec</span>
</div>
<button type="button" class="google-button">
<span class="google-mark" aria-hidden="true">
<span class="google-mark-blue"></span>
<span class="google-mark-red"></span>
<span class="google-mark-yellow"></span>
<span class="google-mark-green"></span>
</span>
<span>Continuer avec Google</span>
</button>
<p class="signup-copy">
Pas encore de compte ?
<a href="/signup">S'inscrire</a>
</p>
</div>
</section>
</main>
</div>
</body>
</html>
}
templ LoginStatus(kind string, message string) {
if kind == "success" {
<div class="status-banner status-success" role="status">{ message }</div>
} else if kind == "error" {
<div class="status-banner status-error" role="alert">{ message }</div>
}
}

View file

@ -0,0 +1,102 @@
// Code generated by templ - DO NOT EDIT.
// templ: version: v0.3.1001
package views
//lint:file-ignore SA4006 This context is only used if a nested component is present.
import "github.com/a-h/templ"
import templruntime "github.com/a-h/templ/runtime"
func LoginPage() templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer {
defer func() {
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
}
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 = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<!doctype html><html lang=\"fr\" class=\"light\"><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><meta name=\"theme-color\" content=\"#1e1b2e\"><title>XTablo</title><link rel=\"stylesheet\" href=\"/static/styles.css\"><script src=\"https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-beta2/dist/htmx.min.js\"></script></head><body><div class=\"page-shell\"><div class=\"page-background\"><div class=\"orb orb-a\"><span>X</span></div><div class=\"orb orb-b\"><span>X</span></div><div class=\"orb orb-c\"><span>X</span></div><div class=\"orb orb-d\"><span>X</span></div><div class=\"orb orb-e\"><span>X</span></div><div class=\"orb orb-f\"><span>X</span></div><div class=\"orb orb-g\"><span>X</span></div><div class=\"orb orb-h\"><span>X</span></div></div><main class=\"auth-stage\"><section class=\"auth-card\"><div class=\"auth-glow\"></div><div class=\"card-body\"><div class=\"card-topbar\"><a class=\"back-link\" href=\"https://www.xtablo.com\">Retour a l'accueil</a> <button type=\"button\" class=\"theme-button\" aria-label=\"theme placeholder\"><span class=\"theme-button-monitor\"></span></button></div><div class=\"brand-lockup\"><div class=\"brand-mark\">XT</div></div><div class=\"headline-block\"><h1>Se connecter a Xtablo</h1></div><div class=\"spotlight-link-wrap\"><a class=\"spotlight-link\" href=\"/login-v2\">Decouvrez la nouvelle experience de connexion</a></div><form class=\"login-form\" hx-post=\"/login\" hx-target=\"#login-status\" hx-swap=\"innerHTML\"><div id=\"login-status\" class=\"status-slot\"></div><div class=\"field-group\"><label for=\"email\">Email *</label> <input id=\"email\" name=\"email\" type=\"email\" placeholder=\"Votre email\" required></div><div class=\"field-group\"><label for=\"password\">Mot de passe *</label> <input id=\"password\" name=\"password\" type=\"password\" placeholder=\"Votre mot de passe\" required></div><div class=\"aux-row\"><a href=\"/reset-password\">Mot de passe oublie ?</a></div><button class=\"primary-button\" type=\"submit\">Se connecter</button></form><div class=\"divider\"><span>Ou continuer avec</span></div><button type=\"button\" class=\"google-button\"><span class=\"google-mark\" aria-hidden=\"true\"><span class=\"google-mark-blue\"></span> <span class=\"google-mark-red\"></span> <span class=\"google-mark-yellow\"></span> <span class=\"google-mark-green\"></span></span> <span>Continuer avec Google</span></button><p class=\"signup-copy\">Pas encore de compte ? <a href=\"/signup\">S'inscrire</a></p></div></section></main></div></body></html>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
}
func LoginStatus(kind string, message string) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer {
defer func() {
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var2 := templ.GetChildren(ctx)
if templ_7745c5c3_Var2 == nil {
templ_7745c5c3_Var2 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
if kind == "success" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "<div class=\"status-banner status-success\" role=\"status\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(message)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/views/login.templ`, Line: 91, Col: 67}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "</div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else if kind == "error" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "<div class=\"status-banner status-error\" role=\"alert\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(message)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/views/login.templ`, Line: 93, Col: 64}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
return nil
})
}
var _ = templruntime.GeneratedTemplate

View file

@ -0,0 +1,26 @@
package main
import (
"net/http"
"time"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
func main() {
zerolog.TimeFieldFormat = time.DateTime
server := &http.Server{
Addr: "localhost:3000",
Handler: newRouter(),
ReadTimeout: 10 * time.Second,
WriteTimeout: time.Minute,
}
log.Info().Msg("Listening on http://localhost:3000...")
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Error().Msg(err.Error())
panic(err)
}
}

View file

@ -0,0 +1,20 @@
package main
import (
"net/http"
"os"
chi "github.com/go-chi/chi/v5"
"xtablo-backend/internal/web/handlers"
)
func newRouter() http.Handler {
mux := chi.NewRouter()
loginHandler := handlers.NewLoginHandler()
mux.Get("/", loginHandler.GetPage())
mux.Post("/login", loginHandler.PostLogin())
mux.Handle("/static/*", http.StripPrefix("/static/", http.FileServerFS(os.DirFS("static"))))
return mux
}

View file

@ -0,0 +1,74 @@
package main
import (
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
)
func TestRootRendersLoginPage(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/", nil)
rec := httptest.NewRecorder()
router := newRouter()
router.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("expected status 200, got %d", rec.Code)
}
body := rec.Body.String()
for _, want := range []string{
"Se connecter a Xtablo",
`hx-post="/login"`,
"https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-beta2/dist/htmx.min.js",
} {
if !strings.Contains(body, want) {
t.Fatalf("expected body to contain %q", want)
}
}
}
func TestLoginReturnsValidationError(t *testing.T) {
form := url.Values{}
form.Set("email", "")
form.Set("password", "")
req := httptest.NewRequest(http.MethodPost, "/login", strings.NewReader(form.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
rec := httptest.NewRecorder()
router := newRouter()
router.ServeHTTP(rec, req)
if rec.Code != http.StatusUnprocessableEntity {
t.Fatalf("expected status 422, got %d", rec.Code)
}
if !strings.Contains(rec.Body.String(), "Veuillez renseigner votre email et votre mot de passe") {
t.Fatalf("expected validation error fragment, got %q", rec.Body.String())
}
}
func TestLoginReturnsSuccessMessage(t *testing.T) {
form := url.Values{}
form.Set("email", "demo@xtablo.com")
form.Set("password", "xtablo-demo")
req := httptest.NewRequest(http.MethodPost, "/login", strings.NewReader(form.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
rec := httptest.NewRecorder()
router := newRouter()
router.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("expected status 200, got %d", rec.Code)
}
if !strings.Contains(rec.Body.String(), "Connexion reussie") {
t.Fatalf("expected success fragment, got %q", rec.Body.String())
}
}

View file

@ -0,0 +1,417 @@
:root {
--background: #f5f1ea;
--surface: rgba(255, 251, 246, 0.78);
--surface-border: rgba(84, 61, 31, 0.12);
--text: #1f1a17;
--muted: #73675d;
--primary: #1f6f64;
--primary-strong: #18584f;
--accent: #cf6b2d;
--accent-soft: rgba(207, 107, 45, 0.16);
--success-bg: rgba(31, 111, 100, 0.1);
--success-border: rgba(31, 111, 100, 0.25);
--error-bg: rgba(181, 69, 69, 0.1);
--error-border: rgba(181, 69, 69, 0.24);
--shadow: 0 24px 80px rgba(43, 24, 4, 0.12);
--font-body: "Avenir Next", "Segoe UI", sans-serif;
--font-display: "Iowan Old Style", "Georgia", serif;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
}
body {
background:
radial-gradient(circle at top left, rgba(31, 111, 100, 0.16), transparent 30%),
radial-gradient(circle at top right, rgba(207, 107, 45, 0.16), transparent 26%),
linear-gradient(135deg, #f3efe7 0%, #f8f4ed 48%, #efe9dd 100%);
color: var(--text);
font-family: var(--font-body);
}
a {
color: inherit;
text-decoration: none;
}
button,
input {
font: inherit;
}
.page-shell {
min-height: 100vh;
position: relative;
overflow: hidden;
}
.page-background {
inset: 0;
pointer-events: none;
position: absolute;
}
.orb {
align-items: center;
animation: drift 18s linear infinite;
background: linear-gradient(135deg, rgba(31, 111, 100, 0.22), rgba(207, 107, 45, 0.1));
border: 1px solid rgba(255, 255, 255, 0.45);
border-radius: 999px;
color: rgba(31, 111, 100, 0.6);
display: flex;
font-family: var(--font-display);
font-size: 1.15rem;
font-weight: 700;
height: 3.4rem;
justify-content: center;
position: absolute;
width: 3.4rem;
}
.orb span {
transform: rotate(-12deg);
}
.orb-a { left: 6%; top: 18%; animation-duration: 14s; }
.orb-b { left: 12%; top: 70%; animation-duration: 19s; height: 4rem; width: 4rem; }
.orb-c { left: 24%; top: 8%; animation-duration: 16s; }
.orb-d { right: 14%; top: 20%; animation-duration: 21s; height: 4.4rem; width: 4.4rem; }
.orb-e { right: 8%; top: 66%; animation-duration: 17s; }
.orb-f { right: 26%; top: 10%; animation-duration: 23s; }
.orb-g { left: 36%; bottom: 10%; animation-duration: 20s; }
.orb-h { right: 35%; bottom: 8%; animation-duration: 15s; }
.auth-stage {
align-items: center;
display: flex;
justify-content: center;
min-height: 100vh;
padding: 2rem 1rem;
position: relative;
}
.auth-card {
max-width: 34rem;
position: relative;
width: 100%;
}
.auth-glow {
background: linear-gradient(135deg, rgba(31, 111, 100, 0.18), rgba(207, 107, 45, 0.1));
border-radius: 2rem;
filter: blur(24px);
inset: 1rem;
position: absolute;
z-index: 0;
}
.card-body {
backdrop-filter: blur(16px);
background: var(--surface);
border: 1px solid var(--surface-border);
border-radius: 1.75rem;
box-shadow: var(--shadow);
padding: 1.5rem;
position: relative;
z-index: 1;
}
.card-topbar {
align-items: center;
display: flex;
justify-content: space-between;
margin-bottom: 1.5rem;
}
.back-link {
color: var(--muted);
font-size: 0.95rem;
transition: color 160ms ease;
}
.back-link:hover,
.aux-row a:hover,
.signup-copy a:hover {
color: var(--text);
}
.back-link::before {
content: "<";
margin-right: 0.55rem;
}
.theme-button {
align-items: center;
background: transparent;
border: 0;
border-radius: 999px;
color: var(--muted);
cursor: pointer;
display: inline-flex;
height: 2.5rem;
justify-content: center;
padding: 0;
transition: background-color 160ms ease, color 160ms ease;
width: 2.5rem;
}
.theme-button:hover {
background: rgba(31, 26, 23, 0.05);
color: var(--text);
}
.theme-button-monitor {
border: 2px solid currentColor;
border-radius: 0.35rem;
display: inline-block;
height: 1rem;
position: relative;
width: 1.3rem;
}
.theme-button-monitor::after {
border-top: 2px solid currentColor;
content: "";
left: 50%;
position: absolute;
top: calc(100% + 0.2rem);
transform: translateX(-50%);
width: 0.9rem;
}
.brand-lockup {
display: flex;
justify-content: center;
margin-bottom: 1.25rem;
}
.brand-mark {
align-items: center;
background: linear-gradient(135deg, rgba(31, 111, 100, 0.18), rgba(207, 107, 45, 0.2));
border: 1px solid rgba(31, 111, 100, 0.16);
border-radius: 1.25rem;
color: var(--primary-strong);
display: flex;
font-family: var(--font-display);
font-size: 1.3rem;
font-weight: 700;
height: 4.5rem;
justify-content: center;
letter-spacing: 0.12rem;
width: 4.5rem;
}
.headline-block {
margin-bottom: 1rem;
text-align: center;
}
.headline-block h1 {
font-family: var(--font-display);
font-size: clamp(2rem, 4vw, 2.7rem);
line-height: 1.05;
margin: 0;
}
.spotlight-link-wrap {
margin-bottom: 1.5rem;
text-align: center;
}
.spotlight-link {
color: var(--accent);
font-size: 0.95rem;
font-weight: 600;
}
.login-form {
display: grid;
gap: 1rem;
}
.status-slot {
min-height: 0.25rem;
}
.status-banner {
border: 1px solid;
border-radius: 1rem;
font-size: 0.94rem;
line-height: 1.45;
padding: 0.9rem 1rem;
}
.status-success {
background: var(--success-bg);
border-color: var(--success-border);
color: var(--primary-strong);
}
.status-error {
background: var(--error-bg);
border-color: var(--error-border);
color: #8f3737;
}
.field-group {
display: grid;
gap: 0.45rem;
}
.field-group label {
font-size: 0.95rem;
font-weight: 600;
}
.field-group input {
background: rgba(255, 255, 255, 0.7);
border: 1px solid rgba(31, 26, 23, 0.12);
border-radius: 0.9rem;
color: var(--text);
min-height: 3rem;
padding: 0.8rem 0.95rem;
transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}
.field-group input:focus {
background: rgba(255, 255, 255, 0.92);
border-color: rgba(31, 111, 100, 0.45);
box-shadow: 0 0 0 4px rgba(31, 111, 100, 0.1);
outline: none;
}
.field-group input::placeholder {
color: #988d82;
}
.aux-row {
display: flex;
justify-content: flex-end;
}
.aux-row a {
color: var(--primary);
font-size: 0.92rem;
}
.primary-button,
.google-button {
align-items: center;
border: 0;
border-radius: 999px;
cursor: pointer;
display: inline-flex;
font-weight: 700;
justify-content: center;
min-height: 3rem;
transition: transform 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}
.primary-button {
background: linear-gradient(135deg, var(--primary), var(--primary-strong));
box-shadow: 0 14px 30px rgba(31, 111, 100, 0.28);
color: #fffdf9;
width: 100%;
}
.primary-button:hover,
.google-button:hover {
transform: translateY(-1px);
}
.divider {
align-items: center;
color: var(--muted);
display: flex;
gap: 0.85rem;
margin: 1.35rem 0;
}
.divider::before,
.divider::after {
background: rgba(31, 26, 23, 0.12);
content: "";
flex: 1;
height: 1px;
}
.divider span {
background: rgba(255, 251, 246, 0.72);
border-radius: 999px;
padding: 0.4rem 0.95rem;
}
.google-button {
background: rgba(255, 255, 255, 0.8);
border: 1px solid rgba(31, 26, 23, 0.12);
color: var(--text);
gap: 0.8rem;
width: 100%;
}
.google-mark {
display: grid;
gap: 0.08rem;
grid-template-columns: repeat(2, 0.55rem);
}
.google-mark span {
border-radius: 0.12rem;
display: inline-block;
height: 0.55rem;
width: 0.55rem;
}
.google-mark-blue { background: #4285f4; }
.google-mark-red { background: #ea4335; }
.google-mark-yellow { background: #fbbc05; }
.google-mark-green { background: #34a853; }
.signup-copy {
color: var(--muted);
margin: 1.3rem 0 0;
text-align: center;
}
.signup-copy a {
color: var(--text);
font-weight: 700;
}
@keyframes drift {
0%,
100% {
transform: translate3d(0, 0, 0) rotate(0deg);
}
25% {
transform: translate3d(10px, -14px, 0) rotate(8deg);
}
50% {
transform: translate3d(-8px, 10px, 0) rotate(-6deg);
}
75% {
transform: translate3d(12px, 8px, 0) rotate(5deg);
}
}
@media (max-width: 640px) {
.card-body {
border-radius: 1.45rem;
padding: 1.2rem;
}
.headline-block h1 {
font-size: 2rem;
}
.divider span {
padding-inline: 0.7rem;
}
}