Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add way to change password WIP
  • Loading branch information
NLiefrink committed Feb 22, 2021
1 parent 00b417f commit 1925fa6
Show file tree
Hide file tree
Showing 9 changed files with 450 additions and 7 deletions.
12 changes: 11 additions & 1 deletion index.php
Expand Up @@ -145,6 +145,7 @@
<script type="text/javascript" src="website_code/scripts/moment.js?version=<?php echo $version;?>"></script>
<script type="text/javascript" src="website_code/scripts/jquery-ui-i18n.min.js?version=<?php echo $version;?>"></script>
<script type="text/javascript" src="website_code/scripts/result.js?version=<?php echo $version;?>"></script>
<script type="text/javascript" src="website_code/scripts/user_settings.js?version=<?php echo $version;?>"></script>

<?php
_include_javascript_file("website_code/scripts/xapi_dashboard_data.js?version=" . $version);
Expand Down Expand Up @@ -288,7 +289,16 @@

<div class="userbar">
<?PHP //echo "&nbsp;&nbsp;&nbsp;" . INDEX_LOGGED_IN_AS . " " .;
echo $_SESSION['toolkits_firstname'] . " " . $_SESSION['toolkits_surname']; ?>
echo $_SESSION['toolkits_firstname'] . " " . $_SESSION['toolkits_surname'] ?>
<div class="settingsDropdown">
<?PHP echo '<button onclick="settingsDropdown()" title=" ' . INDEX_SETTINGS_BUTTON . ' " class="fa fa-cog xerte_button settingsButton"></button>'?>
<div id="settings" class="settings-content">
<?PHP echo '<button class="xerte_button" onclick="changepasswordPopup()">' . INDEX_CHANGE_PASSWORD . '</button> '?>
<button class="xerte_button">Placeholder</button>
<button class="xerte_button">Placeholder</button>
<button class="xerte_button">Placeholder</button>
</div>
</div>
<div style="display: inline-block"><?php display_language_selectionform("general"); ?></div>
<?PHP if($xerte_toolkits_site->authentication_method != "Guest") {
?><button title="<?PHP echo INDEX_BUTTON_LOGOUT; ?>" type="button" class="xerte_button_c_no_width"
Expand Down
6 changes: 5 additions & 1 deletion languages/en-GB/index.inc
Expand Up @@ -104,4 +104,8 @@ define("INDEX_XAPI_DASHBOARD_SHOW_HIDE_COLUMNS", "Show / hide columns");

define("INDEX_XAPI_DASHBOARD_QUESTION_OVERVIEW", "Interaction overview");

define("INDEX_XAPI_DASHBOARD_PRINT", "Print");
define("INDEX_XAPI_DASHBOARD_PRINT", "Print");

define("INDEX_CHANGE_PASSWORD", "Change Password");

define("INDEX_SETTINGS_BUTTON", "Settings");
21 changes: 21 additions & 0 deletions languages/en-GB/user_settings.inc
@@ -0,0 +1,21 @@
<?PHP

/**
*
* properties english language file
*
* @author Patrick Lockley
* @version 1.0
* @copyright Pat Lockley
* @package
*/

define("USER_SETTINGS_PASSWORD_TITLE","Change Password");
define("USER_SETTINGS_PASSWORD_DISPLAY_TITLE","Change Password");

define("USER_SETTINGS_PASSWORD_OLD", "Current Password");
define("USER_SETTINGS_PASSWORD_NEW", "New Password");
define("USER_SETTINGS_PASSWORD_NEW_REPEAT", "Repeat new Password");
define("USER_SETTINGS_PASSWORD_SUBMIT", "Submit");

?>
13 changes: 13 additions & 0 deletions languages/en-GB/website_code/scripts/user_settings.js
@@ -0,0 +1,13 @@

/**
*
* workspace properties, javascript for the workspace properties tab
*
* @author Patrick Lockley
* @version 1.0
* @package
*/


var PASS_FAILED = "Failed to change password:";
var NOT_SAME_PASS = "New password needs to match in both input fields.";
13 changes: 11 additions & 2 deletions library/Xerte/Authentication/Db/changepassword.php
Expand Up @@ -13,7 +13,12 @@

require(dirname(__FILE__) . "/../../../../website_code/php/user_library.php");

if(is_user_admin()){
//check to see if user is admin, or that the username provided in POST is the same as in the session
$supposed_user = $_POST['username'];
$real_user = $_SESSION['toolkits_logon_username'];
$personal = $_POST['personal'];

if(is_user_admin() || $supposed_user == $real_user){

global $authmech, $xerte_toolkits_site;

Expand Down Expand Up @@ -54,7 +59,11 @@
{
$finalmesg = "<p><font color = \"green\">" . AUTH_DB_CHANGEPASSWORD_SUCCEEDED . "</font></p>";
}
$authmech->getUserList(true, $finalmesg);
if (!$personal){
$authmech->getUserList(true, $finalmesg);
}else{
echo $finalmesg;
}
}

?>
115 changes: 115 additions & 0 deletions user_settings.php
@@ -0,0 +1,115 @@
<?php
/**
* Licensed to The Apereo Foundation under one or more contributor license
* agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
* The Apereo Foundation licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

require_once(dirname(__FILE__) . "/config.php");
require_once(dirname(__FILE__) . "/website_code/php/template_library.php");

_load_language_file("/user_settings.inc");
?><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo USER_SETTINGS_PASSWORD_TITLE; ?></title>

<!--
Properties HTML page
Version 1.0
-->

<link href="website_code/styles/frontpage.css" media="screen" type="text/css" rel="stylesheet" />
<link href="website_code/styles/user_settings.css" media="screen" type="text/css" rel="stylesheet" />
<link href="website_code/styles/xerte_buttons.css" media="screen" type="text/css" rel="stylesheet" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="editor/js/vendor/jquery-1.9.1.min.js"><\/script>')</script>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="editor/js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
<script type="text/javascript" src="editor/js/vendor/jquery.ui-1.10.4.js"></script>
<script type="text/javascript" src="editor/js/vendor/jquery.layout-1.3.0-rc30.79.min.js"></script>
<script type="text/javascript" src="editor/js/vendor/jquery.ui.touch-punch.min.js"></script>

<script type="text/javascript" language="javascript" src="website_code/scripts/ajax_management.js"></script>

<script type="text/javascript" language="javascript">

var site_url = "<?php echo $xerte_toolkits_site->site_url; ?>";
var ajax_php_path = "website_code/php/";

</script>
<script type="text/javascript" language="javascript" src="website_code/scripts/validation.js"></script>
<?php
_include_javascript_file("website_code/scripts/import.js");
_include_javascript_file("website_code/scripts/screen_display.js");
_include_javascript_file("website_code/scripts/user_settings.js");
?>
<link rel="stylesheet" type="text/css" href="modules/xerte/parent_templates/Nottingham/common_html5/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="modules/xerte/parent_templates/Nottingham/common_html5/font-awesome-4.3.0/css/font-awesome.min.css">

<?php
if (file_exists($xerte_toolkits_site->root_file_path . "branding/branding.css"))
{
?>
<link href='branding/branding.css' rel='stylesheet' type='text/css'>
<?php
}
else {
?>
<?php
}
?>

</head>


<body>
<div class="properties_main">
<div class="main_area">
<div>
<span id="title">
<img src="website_code/images/Icon_Page.gif" style="vertical-align:middle; padding-left:10px;" />
<?php echo USER_SETTINGS_PASSWORD_DISPLAY_TITLE; ?>
</span>
</div>
<div id="data_area">

<div id="dynamic_area">
<form>
<?php echo '<label for="oldpass">' . USER_SETTINGS_PASSWORD_OLD . '</label><br>'?>
<input type='password' id="oldpass "required><br>
<?php echo '<label for="newpass">' . USER_SETTINGS_PASSWORD_NEW . '</label><br>'?>
<input type='password' id="newpass" required><br>
<?php echo '<label for="newpassrepeat">' . USER_SETTINGS_PASSWORD_NEW_REPEAT . '</label><br>'?>
<input type='password' id="newpassrepeat" required><br>
<?php echo "<button class='xerte_button' onclick='changePassword(\"". $_SESSION['toolkits_logon_username'] ."\")'>" . USER_SETTINGS_PASSWORD_SUBMIT . "</button>"?>
</form>
<div id="result"></div>
</div>
</div>
</div>
<div style="clear:both;"></div>
</div>
<div style="clear:both;"></div>
</div>

</body>
</html>
99 changes: 99 additions & 0 deletions website_code/scripts/user_settings.js
@@ -0,0 +1,99 @@
/**
* Licensed to The Apereo Foundation under one or more contributor license
* agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
* The Apereo Foundation licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
*
* code to handle settings dropdown menu
*
* @author Noud Liefrink
* @version 1.0
* @package
*/

/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function settingsDropdown() {
document.getElementById("settings").classList.toggle("show");
}

// Close the dropdown menu if the user clicks outside of it
$(function() {
$("body").click(function(e) {
if (!(e.target.class == "settingsDropdown" || $(e.target).parents(".settingsDropdown").length)) {
var dropdowns = $(".settings-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
});
})

/**
* Password change popup and form code:
*/

function changepasswordPopup() {
if(setup_ajax()!=false){
var changePassWindow = window.open(site_url + "user_settings.php", "settingswindow", "height=665, width=800");

changePassWindow.window_reference = self;

changePassWindow.focus();
}
}

var xmlHttp = new XMLHttpRequest();

function authdb_ajax_send_prepare(url){

xmlHttp.open("post","library/Xerte/Authentication/Db/" + url,true);
xmlHttp.onreadystatechange=authdb_stateChanged;
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

}
function authdb_stateChanged(){

if (xmlHttp.readyState==4){
document.getElementById('result').innerHTML = xmlHttp.responseText;
}
}

function changePassword(username){
//TODO: first check if old password is correct:
//this whole option should only be possible on Db

var url="changepassword.php";

authdb_ajax_send_prepare(url);

var passwd1 = $("#newpass").val();
var passwd2 = $("#newpassrepeat").val();
if (passwd1 == passwd2) {
var encodedpasswd = encodeURIComponent(passwd1);
var message = 'username=' + encodeURIComponent(username) + '&password=' + encodeURIComponent(passwd1) + '&personal=' + true;
xmlHttp.send('username=' + encodeURIComponent(username) + '&password=' + encodeURIComponent(passwd1) + '&personal=' + true);
}else{
document.getElementById('result').innerHTML = "<p>" + PASS_FAILED + "</p><p><font color = \"red\"><ul><li>" + NOT_SAME_PASS + "</li></ul></font></p>";
}
}

26 changes: 23 additions & 3 deletions website_code/styles/frontpage.css
Expand Up @@ -328,7 +328,7 @@ body{
margin:0 auto;
padding-top:6px;
/* padding-bottom:5px; */
background-color:#ededed;
background-color:#ededed;
}

.userbar {
Expand Down Expand Up @@ -786,7 +786,7 @@ div.ui-layout-center {
#pagecontainer .content {
padding: 5px;
position: relative;
overflow: auto;
overflow: auto;
background: #fff;
}

Expand Down Expand Up @@ -819,4 +819,24 @@ div.ui-layout-center {

.xerte_info_button {
color:#f86718;
}
}

/* Settings dropdown: */

/* The container <div> - needed to position the dropdown content */
.settingsDropdown {
position: relative;
display: inline-block;
}

/* Dropdown Content (Hidden by Default) */
.settings-content {
display: none;
position: absolute;
z-index: 1;
background-color:#ededed;
}


/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
.show {display:block;}

0 comments on commit 1925fa6

Please sign in to comment.