$$(document).on('page:init', '.page[data-name="password_change"]', function(e) {

  $(document).off("click", "#password_change").on("click", "#password_change_button", function(e) {

  console.log('app password_change ready')

    let userData = JSON.parse(localStorage.getItem('f05_user'));

    var password = $("#password22").val();

    var newpassword = $("#newpassword22").val();

    var confirmPwd = $("#confirmpassword22").val();

    let req = {

      uuid: userData.uuid,

      sess_token: userData.sess_token,

      password,

      newpassword,

      confirmPwd

    }

    if (password && newpassword && confirmPwd) {

      app.preloader.show();

      promiseTimeout(30000, password_change(req))

        .then(res => {

          if (res.status) {

            app.preloader.hide();

            app.dialog.alert(res.message, "Password Changed", () => {

              localStorage.removeItem('f05_user')

              //localStorage.clear();

              app.views.main.router.navigate('/signin/');

            });

          } else {

            if (res.message === 'Unauthorized access') {

              localStorage.removeItem('f05_user')

              //localStorage.clear();

              app.dialog.alert('Session timeout, please login again', 'Session timeout', () => {

                app.views.main.router.navigate('/signin/');

              })

            }

            app.preloader.hide();

            app.dialog.alert(res.message, "Password Changed")

          }

        }).catch(err => {

          app.preloader.hide();

          app.dialog.alert(err, "Timed Out");

        });

    } else {

      app.dialog.alert("Please enter your username and password", "Login Errors");

    }

  });

})