@@ -109,6 +109,43 @@ <h1><span class="text-white">Ampli</span><span class="text-danger">Pi</span></h1
109109 }
110110 }
111111
112+ async function set_password ( ) {
113+ const password_box = document . getElementById ( "password" ) ;
114+ const password = password_box . value
115+ const confirm_password_box = document . getElementById ( "confirm-password" ) ;
116+ const confirm_password = confirm_password_box . value
117+
118+ const button = document . getElementById ( 'password-submit' ) ;
119+ const spinner = document . getElementById ( 'password-spinner' ) ;
120+ const success = document . getElementById ( 'password-success' ) ;
121+ const fail = document . getElementById ( 'password-fail' ) ;
122+ const no_match = document . getElementById ( 'password-no-match' ) ;
123+
124+ if ( password != confirm_password ) {
125+ setVisibility ( no_match , fail , success , spinner , button ) ;
126+ } else {
127+ body = JSON . stringify ( { 'password' :password } )
128+
129+ res = await fetch ( '/password' , {
130+ method : 'POST' ,
131+ body : body ,
132+ headers : {
133+ "Content-Type" : "application/json" ,
134+ }
135+ } ) ;
136+
137+ if ( res . ok ) {
138+ setVisibility ( success , spinner , button , fail , no_match ) ;
139+ } else {
140+ setVisibility ( fail , success , spinner , button , no_match ) ;
141+ }
142+ }
143+
144+ setTimeout ( ( ) => { // Reset to default after delay at the end
145+ setVisibility ( button , spinner , success , fail , no_match ) ;
146+ } , 1500 ) ;
147+ }
148+
112149 async function getPersist ( ) {
113150 const response = await fetch ( "/settings/persist_logs" , { method : "GET" } ) ;
114151 const data = await response . json ( ) ;
@@ -180,7 +217,15 @@ <h6 class="hover-label">
180217 < input id ="confirm-password " type ="password ">
181218 </ div >
182219 < div >
183- < a id ="password " role ="button " class ="btn btn-primary btn-sm text-center " onClick ="set_password(); "> Update Password</ a >
220+ < a id ="password-submit " role ="button " class ="btn btn-primary btn-sm text-center " onClick ="set_password(); "> Update Password</ a >
221+ < a id ="password-success " role ="button " class ="btn btn-primary btn-sm text-center " style ="display: none; background-color: #00AA00; "> Success!</ a >
222+ < a id ="password-fail " role ="button " class ="btn btn-primary btn-sm text-center " style ="display: none; background-color: #DD0000; "> Failure...</ a >
223+ < a id ="password-no-match " role ="button " class ="btn btn-primary btn-sm text-center " style ="display: none; background-color: #DD0000; "> Passwords do not match!</ a >
224+ < div id ="password-spinner " style ="display: none; ">
225+ < i class ="fa fa-circle-o-notch fa-spin " style ="font-size:24px "> </ i >
226+ </ div >
227+ </ div >
228+ < div >
184229 </ div >
185230 </ div >
186231 </ div >
0 commit comments