@@ -1392,8 +1392,10 @@ function update_status(status) {
13921392
13931393
13941394function with_req ( method , path , body , fun , on404fun ) {
1395+ if ( password_change_in_progress ) {
1396+ return ;
1397+ }
13951398 if ( ! has_auth_credentials ( ) ) {
1396- // Clear any lingering auth settings in local storage and navigate to the login form.
13971399 clear_auth ( ) ;
13981400 location . reload ( ) ;
13991401 return ;
@@ -1518,6 +1520,9 @@ function check_bad_response(req, full_page_404, on404fun) {
15181520 if ( ( req . status >= 200 && req . status < 300 ) || req . status == 1223 ) {
15191521 return true ;
15201522 }
1523+ else if ( password_change_in_progress ) {
1524+ return false ;
1525+ }
15211526 else if ( req . status == 404 && full_page_404 ) {
15221527 var html = format ( '404' , { } ) ;
15231528 replace_content ( 'main' , html ) ;
@@ -1942,3 +1947,52 @@ function check_version() {
19421947 location . reload ( )
19431948 }
19441949}
1950+
1951+ var password_change_in_progress = false ;
1952+
1953+ function change_own_password ( sammy ) {
1954+ var params = params_magic ( sammy . params ) ;
1955+ var path = 'api' + fill_path_template ( '/users/:username' , params ) ;
1956+ var new_password = sammy . params [ 'password' ] ;
1957+ var username = sammy . params [ 'username' ] ;
1958+ var done = false ;
1959+
1960+ password_change_in_progress = true ;
1961+ pause_auto_refresh ( ) ;
1962+ for ( var i in outstanding_reqs ) {
1963+ outstanding_reqs [ i ] . abort ( ) ;
1964+ }
1965+ outstanding_reqs = [ ] ;
1966+
1967+ function finish ( ) {
1968+ if ( done ) return ;
1969+ done = true ;
1970+ password_change_in_progress = false ;
1971+ resume_auto_refresh ( ) ;
1972+ }
1973+
1974+ var timeout = setTimeout ( function ( ) {
1975+ finish ( ) ;
1976+ show_popup ( 'warn' ,
1977+ 'Password change request timed out. Please try logging in again.' ) ;
1978+ } , 30000 ) ;
1979+
1980+ var req = xmlHttpRequest ( ) ;
1981+ req . open ( 'PUT' , path , true ) ;
1982+ req . setRequestHeader ( 'content-type' , 'application/json' ) ;
1983+ req . setRequestHeader ( 'authorization' , authorization_header ( ) ) ;
1984+ req . onreadystatechange = function ( ) {
1985+ if ( req . readyState == 4 && ! done ) {
1986+ clearTimeout ( timeout ) ;
1987+ if ( req . status >= 200 && req . status < 300 ) {
1988+ set_basic_auth ( username , new_password ) ;
1989+ finish ( ) ;
1990+ go_to ( '#/users' ) ;
1991+ } else {
1992+ finish ( ) ;
1993+ check_bad_response ( req , false ) ;
1994+ }
1995+ }
1996+ } ;
1997+ req . send ( JSON . stringify ( params ) ) ;
1998+ }
0 commit comments