101 lines
2.2 KiB
Go
101 lines
2.2 KiB
Go
package webui
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"html"
|
|
"io"
|
|
|
|
"github.com/a-h/templ"
|
|
)
|
|
|
|
type AuthPageData struct {
|
|
Username string
|
|
Error string
|
|
}
|
|
|
|
func Signup(data AuthPageData) templ.Component {
|
|
return authPage(
|
|
"Sign up",
|
|
"Create your account",
|
|
"First account created becomes the initial admin.",
|
|
"/signup",
|
|
"Create account",
|
|
"/signin",
|
|
"Already have an account? Sign in",
|
|
data,
|
|
)
|
|
}
|
|
|
|
func Signin(data AuthPageData) templ.Component {
|
|
return authPage(
|
|
"Sign in",
|
|
"Welcome back",
|
|
"Sign in to manage backup infrastructure.",
|
|
"/signin",
|
|
"Sign in",
|
|
"/signup",
|
|
"Need an account? Sign up",
|
|
data,
|
|
)
|
|
}
|
|
|
|
func authPage(
|
|
title string,
|
|
heading string,
|
|
description string,
|
|
action string,
|
|
submitLabel string,
|
|
switchHref string,
|
|
switchLabel string,
|
|
data AuthPageData,
|
|
) templ.Component {
|
|
return templ.ComponentFunc(func(_ context.Context, w io.Writer) error {
|
|
errBlock := ""
|
|
if data.Error != "" {
|
|
errBlock = fmt.Sprintf(`<p class="error">%s</p>`, html.EscapeString(data.Error))
|
|
}
|
|
|
|
_, err := io.WriteString(w, fmt.Sprintf(`<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title>%s · Satoru</title>
|
|
<link rel="stylesheet" href="/static/app.css" />
|
|
</head>
|
|
<body>
|
|
<main class="card auth-card">
|
|
<p class="eyebrow">Satoru</p>
|
|
<h1>%s</h1>
|
|
<p class="muted">%s</p>
|
|
%s
|
|
<form class="stack" method="post" action="%s">
|
|
<label class="stack">
|
|
<span>Username</span>
|
|
<input type="text" name="username" value="%s" autocomplete="username" required />
|
|
</label>
|
|
<label class="stack">
|
|
<span>Password</span>
|
|
<input type="password" name="password" autocomplete="current-password" required />
|
|
</label>
|
|
<button class="button" type="submit">%s</button>
|
|
</form>
|
|
<p class="muted"><a href="%s">%s</a></p>
|
|
</main>
|
|
</body>
|
|
</html>`,
|
|
html.EscapeString(title),
|
|
html.EscapeString(heading),
|
|
html.EscapeString(description),
|
|
errBlock,
|
|
html.EscapeString(action),
|
|
html.EscapeString(data.Username),
|
|
html.EscapeString(submitLabel),
|
|
html.EscapeString(switchHref),
|
|
html.EscapeString(switchLabel),
|
|
))
|
|
return err
|
|
})
|
|
}
|