Add user control panel and ability to change own password
This commit is contained in:
@@ -8,6 +8,32 @@ var sb = {
|
|||||||
|
|
||||||
init: function() {
|
init: function() {
|
||||||
$('.alert-data').alert();
|
$('.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
47
source/webui/pages/usercp.php
Normal file
47
source/webui/pages/usercp.php
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$main = StatusBoard_Main::instance();
|
||||||
|
$request = $main->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);
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -15,6 +15,6 @@
|
|||||||
|
|
||||||
{if $authenticated}
|
{if $authenticated}
|
||||||
<p class="pull-right">
|
<p class="pull-right">
|
||||||
Logged in as <a href="#">{$user->username}</a>
|
Logged in as <a href="{$base_uri}usercp/">{$user->username}</a>
|
||||||
</p>
|
</p>
|
||||||
{/if}
|
{/if}
|
||||||
62
source/webui/templates/usercp.tpl
Normal file
62
source/webui/templates/usercp.tpl
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<div class="container">
|
||||||
|
|
||||||
|
{if $activity}
|
||||||
|
{if $successes}
|
||||||
|
{foreach from=$successes item=message}
|
||||||
|
<div class="alert-message success">
|
||||||
|
{$message|escape:html}
|
||||||
|
</div>
|
||||||
|
{/foreach}
|
||||||
|
{/if}
|
||||||
|
{if $errors}
|
||||||
|
{foreach from=$errors item=message}
|
||||||
|
<div class="alert-message error">
|
||||||
|
{$message|escape:html}
|
||||||
|
</div>
|
||||||
|
{/foreach}
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="span16">
|
||||||
|
<form id="usercp_pwchange" method="post" action="{$base_uri}usercp/do/change-password/">
|
||||||
|
<fieldset>
|
||||||
|
<legend>Change Password</legend>
|
||||||
|
|
||||||
|
<div class="clearfix">
|
||||||
|
<label for="usercp_currentpassword">Current Password</label>
|
||||||
|
<div class="password">
|
||||||
|
<input class="xlarge span5" id="usercp_currentpassword" name="currentpassword" type="password"/>
|
||||||
|
</div>
|
||||||
|
</div><!-- /clearfix -->
|
||||||
|
|
||||||
|
<div class="clearfix">
|
||||||
|
<label for="usercp_newpassword">New Password</label>
|
||||||
|
<div class="password">
|
||||||
|
<input class="xlarge span5" id="usercp_newpassword" name="newpassword" type="password"/>
|
||||||
|
</div>
|
||||||
|
</div><!-- /clearfix -->
|
||||||
|
|
||||||
|
<div class="clearfix">
|
||||||
|
<label for="usercp_confirmpassword">Confirm Password</label>
|
||||||
|
<div class="password">
|
||||||
|
<input class="xlarge span5" id="usercp_confirmpassword" name="confirmpassword" type="password"/>
|
||||||
|
<span class="help-inline" style="display: none" id="usercp_confirmpassword_help">The passwords do not match.</span>
|
||||||
|
</div>
|
||||||
|
</div><!-- /clearfix -->
|
||||||
|
|
||||||
|
<div class="input">
|
||||||
|
<div class="clearfix">
|
||||||
|
<input type="submit" class="btn primary" value="Change Password"> <button type="reset" class="btn">Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
</div><!-- /span16 -->
|
||||||
|
</div><!-- /row -->
|
||||||
|
</div><!-- /container -->
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
$('document').ready(sb.usercp.init);
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user