satoru/internal/webui/password.go

65 lines
1.7 KiB
Go

package webui
import (
"context"
"fmt"
"html"
"io"
"github.com/a-h/templ"
"satoru/internal/store"
)
type PasswordPageData struct {
User store.User
Error string
}
func ChangePassword(data PasswordPageData) 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>Change Password · Satoru</title>
<link rel="stylesheet" href="/static/app.css" />
</head>
<body>
<main class="card auth-card">
<p class="eyebrow">Satoru</p>
<h1>Change Password</h1>
<p class="muted">User: <strong>%s</strong></p>
%s
<form class="stack" method="post" action="/account/password">
<label class="stack">
<span>Current password</span>
<input type="password" name="current_password" autocomplete="current-password" required />
</label>
<label class="stack">
<span>New password</span>
<input type="password" name="new_password" autocomplete="new-password" required />
</label>
<label class="stack">
<span>Confirm new password</span>
<input type="password" name="confirm_password" autocomplete="new-password" required />
</label>
<button class="button" type="submit">Update password</button>
</form>
<p class="muted"><a href="/">Back to dashboard</a></p>
</main>
</body>
</html>`,
html.EscapeString(data.User.Username),
errBlock,
))
return err
})
}