83 lines
1.8 KiB
Go
83 lines
1.8 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.DefaultNavCollapse(),
|
|
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",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|