diff --git a/form.json b/form.json index 3c06202..5ff6782 100644 --- a/form.json +++ b/form.json @@ -1 +1 @@ -{"Elements":[{"Name":"theemail","Label":"Email Address","LabelClasses":"","InputClasses":"","Type":"text","Hint":"","Required":false,"Classes":"","Validator":"email","FailMessage":"Must be a valid email address","Value":"","Autocomplete":"one-time-code","Order":1,"OnClick":"","Choices":null,"TogglePassword":false},{"Name":"theoldpassword","Label":"Old","LabelClasses":"","InputClasses":"","Type":"password","Hint":"","Required":false,"Classes":"","Validator":"","FailMessage":"Passsword Incorrect","Value":"","Autocomplete":"one-time-code","Order":2,"OnClick":"","Choices":null,"TogglePassword":false},{"Name":"newpassword","Label":"New","LabelClasses":"","InputClasses":"","Type":"password","Hint":"","Required":false,"Classes":"","Validator":"minlength=8;haslowercase;hasuppercase;hasdigit","FailMessage":"Password must be at least 8 characters long and contain at least one uppercase letter, one lowercase letter and one digit","Value":"","Autocomplete":"one-time-code","Order":3,"OnClick":"","Choices":null,"TogglePassword":false},{"Name":"confirmpassword","Label":"Confirm ","LabelClasses":"","InputClasses":"","Type":"password","Hint":"","Required":false,"Classes":"","Validator":"mustmatch=newpassword","FailMessage":"Passwords do not match","Value":"","Autocomplete":"one-time-code","Order":4,"OnClick":"","Choices":null,"TogglePassword":false},{"Name":"","Label":"Change Password","LabelClasses":"","InputClasses":"flex w-full justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600","Type":"submit","Hint":"","Required":false,"Classes":"","Validator":"","FailMessage":"","Value":"","Autocomplete":"","Order":5,"OnClick":"","Choices":null,"TogglePassword":false}],"Route":"/chpass/changepassword","Classes":" py-2 text-indigo-300 md:px-10 lg:col-start-2 lg:row-start-1 lg:mx-auto lg:w-full lg:max-w-lg lg:bg-transparent lg:px-0 ","LabelClasses":"block text-sm font-medium text-gray-700","InputClasses":" w-full mr-12 pr-12 rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm","ErrorClasses":"text-red-800 font-bold","ContainerClasses":"relative mx-auto gap-x-16 bg-slate-100 w-full lg-w-1/2 lg:px-8 lg:pt-16","Autocomplete":"one-time-code","Editable":true} \ No newline at end of file +{"Elements":[{"Name":"field1","Label":"Email Address","LabelClasses":"","InputClasses":"","Type":"text","Hint":"","Required":false,"Classes":"","Validator":"email","FailMessage":"Must be a valid email address","Value":"","Autocomplete":"one-time-code","Order":1,"OnClick":"","Choices":null,"TogglePassword":false},{"Name":"field2","Label":"Old","LabelClasses":"","InputClasses":"","Type":"password","Hint":"","Required":false,"Classes":"","Validator":"","FailMessage":"Passsword Incorrect","Value":"","Autocomplete":"one-time-code","Order":2,"OnClick":"","Choices":null,"TogglePassword":false},{"Name":"field3","Label":"New","LabelClasses":"","InputClasses":"","Type":"password","Hint":"","Required":false,"Classes":"","Validator":"minlength=8;haslowercase;hasuppercase;hasdigit","FailMessage":"Password must be at least 8 characters long and contain at least one uppercase letter, one lowercase letter and one digit","Value":"","Autocomplete":"one-time-code","Order":3,"OnClick":"","Choices":null,"TogglePassword":false},{"Name":"field4","Label":"Confirm ","LabelClasses":"","InputClasses":"","Type":"password","Hint":"","Required":false,"Classes":"","Validator":"mustmatch=field3","FailMessage":"Passwords do not match","Value":"","Autocomplete":"one-time-code","Order":4,"OnClick":"","Choices":null,"TogglePassword":false},{"Name":"","Label":"Change Password","LabelClasses":"","InputClasses":"flex w-full justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600","Type":"submit","Hint":"","Required":false,"Classes":"","Validator":"","FailMessage":"","Value":"","Autocomplete":"","Order":5,"OnClick":"","Choices":null,"TogglePassword":false}],"Route":"/chpass/changepassword","Classes":" py-2 text-indigo-300 md:px-10 lg:col-start-2 lg:row-start-1 lg:mx-auto lg:w-full lg:max-w-lg lg:bg-transparent lg:px-0 ","LabelClasses":"block text-sm font-medium text-gray-700","InputClasses":" w-full mr-12 pr-12 rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm","ErrorClasses":"text-red-800 font-bold","ContainerClasses":"relative mx-auto gap-x-16 bg-slate-100 w-full lg-w-1/2 lg:px-8 lg:pt-16","Autocomplete":"one-time-code","Editable":true} \ No newline at end of file diff --git a/main.go b/main.go index d73279f..66a30dd 100644 --- a/main.go +++ b/main.go @@ -47,7 +47,7 @@ func main() { e.Type = "text" e.Validator = "email" e.FailMessage = "Must be a valid email address" - e.Name = "theemail" + e.Name = "field1" f.Add(e) e = forms.NewElement() @@ -55,7 +55,7 @@ func main() { e.Type = "password" e.Validator = "" e.FailMessage = "Passsword Incorrect" - e.Name = "theoldpassword" + e.Name = "field2" f.Add(e) e = forms.NewElement() @@ -63,15 +63,15 @@ func main() { e.Type = "password" e.FailMessage = "Password must be at least 8 characters long and contain at least one uppercase letter, one lowercase letter and one digit" e.Validator = "minlength=8;haslowercase;hasuppercase;hasdigit" - e.Name = "newpassword" + e.Name = "field3" f.Add(e) e = forms.NewElement() e.Label = "Confirm " e.Type = "password" e.FailMessage = "Passwords do not match" - e.Validator = "mustmatch=newpassword" - e.Name = "confirmpassword" + e.Validator = "mustmatch=field3" + e.Name = "field4" f.Add(e) e = forms.NewElement() @@ -122,14 +122,14 @@ func main() { defer c.Quit() // Authenticate. - if err := c.Auth(f.GetValue("theemail"), f.GetValue("theoldpassword")); err != nil { + if err := c.Auth(f.GetValue("field1"), f.GetValue("field2")); err != nil { f.MakeInvalid("theoldpassword", "Invalid password") d.Body = f.Render(true) tmpl.Execute(w, d) return } // Change the password - if !modifyPasswordFile(f.GetValue("theemail"), f.GetValue("newpassword")) { + if !modifyPasswordFile(f.GetValue("field1"), f.GetValue("field3")) { log.Println(err) d.Body = "Internal error" tmpl.Execute(w, d) diff --git a/test.html b/test.html index c0edd4c..54143c4 100644 --- a/test.html +++ b/test.html @@ -5,21 +5,21 @@
- -
-
Must be a valid email address
- -
+ +
+
Must be a valid email address
+ +
-
Passsword Incorrect
- -
+
Passsword Incorrect
+ +
-
Password must be at least 8 characters long and contain at least one uppercase letter, one lowercase letter and one digit
- -
+
Password must be at least 8 characters long and contain at least one uppercase letter, one lowercase letter and one digit
+ +
-
Passwords do not match
+
Passwords do not match
Invalid entry.