This commit is contained in:
Your Name 2024-10-08 20:06:43 -04:00
parent a08c211261
commit 57e855c7d4
3 changed files with 20 additions and 20 deletions

View File

@ -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}
{"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}

14
main.go
View File

@ -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)

View File

@ -5,21 +5,21 @@
<form autocomplete='one-time-code' class=' 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 ' action='/chpass/changepassword' method='post' enctype='multipart/form-data'>
<div class='display-none text-red-800 font-bold'></div>
<div class='relative mx-auto gap-x-16 bg-slate-100 w-full lg-w-1/2 lg:px-8 lg:pt-16'>
<!-- element order 1 forms.element{Name:"theemail", Label:"Email Address", LabelClasses:"", InputClasses:"", Type:"text", Hint:"", Required:false, Classes:"", Validator:"email", vreg:(*regexp.Regexp)(nil), valid:false, FailMessage:"Must be a valid email address", Value:"", Autocomplete:"one-time-code", Order:1, OnClick:"", Choices:[]forms.choice(nil), TogglePassword:false}-->
<div class=' 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 '><label for='theemail'class='block text-sm font-medium text-gray-700'>Email Address</label><input type='text' autocomplete='one-time-code' name='theemail' class=' w-full mr-12 pr-12 rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm' value=''></div>
<div class='text-red-800 font-bold' for='theemail' ><span class='error'>Must be a valid email address</span></div>
<!-- element order 2 forms.element{Name:"theoldpassword", Label:"Old", LabelClasses:"", InputClasses:"", Type:"password", Hint:"", Required:false, Classes:"", Validator:"", vreg:(*regexp.Regexp)(nil), valid:false, FailMessage:"Passsword Incorrect", Value:"", Autocomplete:"one-time-code", Order:2, OnClick:"", Choices:[]forms.choice(nil), TogglePassword:false}-->
<div class='relative 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 '><label for='theoldpassword' class='block text-sm font-medium text-gray-700'>Old</label><input id='input-theoldpassword' autocomplete='one-time-code' type='password' name='theoldpassword' class=' w-full mr-12 pr-12 rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm' value=''>
<!-- element order 1 forms.element{Name:"field1", Label:"Email Address", LabelClasses:"", InputClasses:"", Type:"text", Hint:"", Required:false, Classes:"", Validator:"email", vreg:(*regexp.Regexp)(nil), valid:false, FailMessage:"Must be a valid email address", Value:"", Autocomplete:"one-time-code", Order:1, OnClick:"", Choices:[]forms.choice(nil), TogglePassword:false}-->
<div class=' 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 '><label for='field1'class='block text-sm font-medium text-gray-700'>Email Address</label><input type='text' autocomplete='one-time-code' name='field1' class=' w-full mr-12 pr-12 rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm' value=''></div>
<div class='text-red-800 font-bold' for='field1' ><span class='error'>Must be a valid email address</span></div>
<!-- element order 2 forms.element{Name:"field2", Label:"Old", LabelClasses:"", InputClasses:"", Type:"password", Hint:"", Required:false, Classes:"", Validator:"", vreg:(*regexp.Regexp)(nil), valid:false, FailMessage:"Passsword Incorrect", Value:"", Autocomplete:"one-time-code", Order:2, OnClick:"", Choices:[]forms.choice(nil), TogglePassword:false}-->
<div class='relative 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 '><label for='field2' class='block text-sm font-medium text-gray-700'>Old</label><input id='input-field2' autocomplete='one-time-code' type='password' name='field2' class=' w-full mr-12 pr-12 rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm' value=''>
</div>
<div class='text-red-800 font-bold' for='theoldpassword' ><span class='error'>Passsword Incorrect</span></div>
<!-- element order 3 forms.element{Name:"newpassword", Label:"New", LabelClasses:"", InputClasses:"", Type:"password", Hint:"", Required:false, Classes:"", Validator:"minlength=8;haslowercase;hasuppercase;hasdigit", vreg:(*regexp.Regexp)(nil), valid:false, 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:[]forms.choice(nil), TogglePassword:false}-->
<div class='relative 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 '><label for='newpassword' class='block text-sm font-medium text-gray-700'>New</label><input id='input-newpassword' autocomplete='one-time-code' type='password' name='newpassword' class=' w-full mr-12 pr-12 rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm' value=''>
<div class='text-red-800 font-bold' for='field2' ><span class='error'>Passsword Incorrect</span></div>
<!-- element order 3 forms.element{Name:"field3", Label:"New", LabelClasses:"", InputClasses:"", Type:"password", Hint:"", Required:false, Classes:"", Validator:"minlength=8;haslowercase;hasuppercase;hasdigit", vreg:(*regexp.Regexp)(nil), valid:false, 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:[]forms.choice(nil), TogglePassword:false}-->
<div class='relative 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 '><label for='field3' class='block text-sm font-medium text-gray-700'>New</label><input id='input-field3' autocomplete='one-time-code' type='password' name='field3' class=' w-full mr-12 pr-12 rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm' value=''>
</div>
<div class='text-red-800 font-bold' for='newpassword' ><span class='error'>Password must be at least 8 characters long and contain at least one uppercase letter, one lowercase letter and one digit</span></div>
<!-- element order 4 forms.element{Name:"confirmpassword", Label:"Confirm ", LabelClasses:"", InputClasses:"", Type:"password", Hint:"", Required:false, Classes:"", Validator:"mustmatch=newpassword", vreg:(*regexp.Regexp)(nil), valid:false, FailMessage:"Passwords do not match", Value:"", Autocomplete:"one-time-code", Order:4, OnClick:"", Choices:[]forms.choice(nil), TogglePassword:false}-->
<div class='relative 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 '><label for='confirmpassword' class='block text-sm font-medium text-gray-700'>Confirm </label><input id='input-confirmpassword' autocomplete='one-time-code' type='password' name='confirmpassword' class=' w-full mr-12 pr-12 rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm' value=''>
<div class='text-red-800 font-bold' for='field3' ><span class='error'>Password must be at least 8 characters long and contain at least one uppercase letter, one lowercase letter and one digit</span></div>
<!-- element order 4 forms.element{Name:"field4", Label:"Confirm ", LabelClasses:"", InputClasses:"", Type:"password", Hint:"", Required:false, Classes:"", Validator:"mustmatch=field3", vreg:(*regexp.Regexp)(nil), valid:false, FailMessage:"Passwords do not match", Value:"", Autocomplete:"one-time-code", Order:4, OnClick:"", Choices:[]forms.choice(nil), TogglePassword:false}-->
<div class='relative 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 '><label for='field4' class='block text-sm font-medium text-gray-700'>Confirm </label><input id='input-field4' autocomplete='one-time-code' type='password' name='field4' class=' w-full mr-12 pr-12 rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm' value=''>
</div>
<div class='text-red-800 font-bold' for='confirmpassword' ><span class='error'>Passwords do not match</span></div>
<div class='text-red-800 font-bold' for='field4' ><span class='error'>Passwords do not match</span></div>
<!-- element order 5 forms.element{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:"", vreg:(*regexp.Regexp)(nil), valid:false, FailMessage:"", Value:"", Autocomplete:"", Order:5, OnClick:"", Choices:[]forms.choice(nil), TogglePassword:false}-->
<div class=' 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 '><button autocomplete='one-time-code' type='submit' class='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'><span class='block text-sm font-medium text-gray-700'>Change Password</span></button></div>
<div class='text-red-800 font-bold' for=''><span class='error'>Invalid entry.</span></div>