lishwist/http/props/register.go
2025-12-16 00:23:13 +09:00

88 lines
1.9 KiB
Go

package props
import (
"html/template"
"lishwist/http/props/htmlx"
"lishwist/http/templates"
)
type RegisterForm struct {
Username htmlx.Input
Password htmlx.Input
ConfirmPassword htmlx.Input
Submit htmlx.Submit
}
type Register struct {
Nav templates.NavCollapse
Error string `json:",omitempty" xml:",omitempty"`
Warning template.HTML `json:",omitempty" xml:",omitempty"`
Form htmlx.Form[RegisterForm]
}
func (p *RegisterForm) Validate() (valid bool) {
valid = true
if p.Password.Value != p.ConfirmPassword.Value {
p.ConfirmPassword.Error = "Passwords didn't match"
valid = false
}
if !p.Username.Validate() {
valid = false
}
if !p.Password.Validate() {
valid = false
}
if !p.ConfirmPassword.Validate() {
valid = false
}
return
}
func NewRegister(usernameVal, passwordVal, confirmPassVal string) *Register {
return &Register{
Nav: templates.NavCollapse{
Links: []htmlx.Link{{
Name: "Login",
Href: "/",
}},
},
Error: "",
Warning: template.HTML(`<p>Your password will be stored in a safe, responsible manner; but don't trust my programming skills!</p><p class="mb-0">Maybe use a password here that you don't use for important things...</p>`),
Form: htmlx.Form[RegisterForm]{
Method: "POST",
Elements: RegisterForm{
Username: htmlx.Input{
Label: "Username",
Name: "username",
Required: true,
MinLength: 4,
Value: usernameVal,
},
Password: htmlx.Input{
Label: "Password",
Type: "password",
Name: "newPassword",
Required: true,
MinLength: 5,
Value: passwordVal,
},
ConfirmPassword: htmlx.Input{
Label: "Confirm password",
Type: "password",
Name: "confirmPassword",
Required: true,
Value: confirmPassVal,
},
Submit: htmlx.Submit{
Label: "Register",
},
},
},
}
}