diff --git a/public/scripts/main.js b/public/scripts/main.js index 7a890d2..2e0c625 100644 --- a/public/scripts/main.js +++ b/public/scripts/main.js @@ -8,6 +8,32 @@ var sb = { init: function() { $('.alert-data').alert(); + }, + + usercp: { + + init: function() { + $('#usercp_newpassword,#usercp_confirmpassword').bind('keyup', sb.usercp.checkPassword); + + }, + + checkPassword: function() { + password = $('#usercp_newpassword'); + confirm = $('#usercp_confirmpassword'); + + confirm_container = confirm.parent().parent(); + + if (password.val() == confirm.val()) { + console.log("passwords match"); + confirm_container.removeClass('error').addClass('success'); + $('#usercp_confirmpassword_help').hide(); + } else { + console.log("passwords do not match"); + confirm_container.addClass('error').removeClass('success'); + $('#usercp_confirmpassword_help').show(); + } + } + } }; diff --git a/source/webui/pages/usercp.php b/source/webui/pages/usercp.php new file mode 100644 index 0000000..25a4cf7 --- /dev/null +++ b/source/webui/pages/usercp.php @@ -0,0 +1,47 @@ +request(); +$auth = $main->auth(); + +$activity = null; +$success = true; +$errors = array(); +$successes = array(); + +if ($request->exists('do')) { + $activity = $request->get('do'); + switch ($activity) { + + case 'change-password': { + $current_password = StatusBoard_Main::issetelse($_POST['currentpassword'], 'Sihnon_Exception_InvalidParameters'); + $new_password = StatusBoard_Main::issetelse($_POST['newpassword'], 'Sihnon_Exception_InvalidParameters'); + $confirm_password = StatusBoard_Main::issetelse($_POST['confirmpassword'], 'Sihnon_Exception_InvalidParameters'); + + $user = $auth->authenticatedUser(); + if ($user->checkPassword($current_password)) { + if ($new_password == $confirm_password) { + $auth->changePassword($new_password); + $successes[] = 'The password has been changed successfully.'; + } else { + $success = false; + $errors[] = 'The passwords did not match.'; + } + } else { + $success = false; + $errors[] = 'The current password was incorrect.'; + } + } break; + + default: { + $success = false; + $errors[] = "The activity '{$activity}' was not recognised."; + } break; + } +} + +$this->smarty->assign('activity', $activity); +$this->smarty->assign('successes', $successes); +$this->smarty->assign('errors', $errors); + +?> \ No newline at end of file diff --git a/source/webui/templates/navigation.tpl b/source/webui/templates/navigation.tpl index 51df6ee..d5eb43a 100644 --- a/source/webui/templates/navigation.tpl +++ b/source/webui/templates/navigation.tpl @@ -15,6 +15,6 @@ {if $authenticated}

- Logged in as {$user->username} + Logged in as {$user->username}

{/if} \ No newline at end of file diff --git a/source/webui/templates/usercp.tpl b/source/webui/templates/usercp.tpl new file mode 100644 index 0000000..aad4ad9 --- /dev/null +++ b/source/webui/templates/usercp.tpl @@ -0,0 +1,62 @@ +
+ +{if $activity} + {if $successes} + {foreach from=$successes item=message} +
+ {$message|escape:html} +
+ {/foreach} + {/if} + {if $errors} + {foreach from=$errors item=message} +
+ {$message|escape:html} +
+ {/foreach} + {/if} +{/if} + + +
+
+
+
+ Change Password + +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ + +
+
+ +
+
+   +
+
+
+
+
+
+
+ + \ No newline at end of file