2013-07-01 16:28:37 +00:00
|
|
|
<?php
|
2013-09-13 22:39:03 +00:00
|
|
|
/**
|
|
|
|
* This function is beign used to change the users password.
|
|
|
|
* It will first check if the user who executed this function is the person of whom the emailaddress is or if it's a mod/admin. If this is not the case the page will be redirected to an error page.
|
|
|
|
* If the executing user tries to change someone elses password, he doesn't has to fill in the previous password. The password will be validated first. If the checking was successful the password will be updated and the settings template will be reloaded. Errors made by invalid data will be shown
|
|
|
|
* also after reloading the template.
|
|
|
|
* @author Daan Janssens, mentored by Matthew Lagoe
|
|
|
|
*/
|
2013-07-01 16:28:37 +00:00
|
|
|
function change_password(){
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-07-01 16:28:37 +00:00
|
|
|
try{
|
2013-07-01 21:29:16 +00:00
|
|
|
//if logged in
|
|
|
|
if(WebUsers::isLoggedIn()){
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-07-01 21:29:16 +00:00
|
|
|
if(isset($_POST['target_id'])){
|
|
|
|
$adminChangesOther = false;
|
|
|
|
//if target_id is the same as session id or is admin
|
2013-09-09 01:47:32 +00:00
|
|
|
if( ($_POST['target_id'] == $_SESSION['id']) || Ticket_User::isMod(unserialize($_SESSION['ticket_user'])) ){
|
2013-07-01 21:29:16 +00:00
|
|
|
if($_POST['target_id'] == $_SESSION['id']){
|
2013-09-13 22:39:03 +00:00
|
|
|
//if the password is of the executing user himself
|
2013-07-01 21:29:16 +00:00
|
|
|
$target_username = $_SESSION['user'];
|
|
|
|
}else{
|
2013-09-13 22:39:03 +00:00
|
|
|
//if the password is of someone else.
|
2013-08-05 15:31:36 +00:00
|
|
|
$webUser = new WebUsers($_POST['target_id']);
|
|
|
|
$target_username = $webUser->getUsername();
|
2013-07-01 21:29:16 +00:00
|
|
|
//isAdmin is true when it's the admin, but the target_id != own id
|
|
|
|
$adminChangesOther = true;
|
|
|
|
$_POST["CurrentPass"] = "dummypass";
|
|
|
|
}
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-08-05 15:31:36 +00:00
|
|
|
$webUser = new WebUsers($_POST['target_id']);
|
2013-07-01 21:29:16 +00:00
|
|
|
$params = Array( 'user' => $target_username, 'CurrentPass' => $_POST["CurrentPass"], 'NewPass' => $_POST["NewPass"], 'ConfirmNewPass' => $_POST["ConfirmNewPass"], 'adminChangesOther' => $adminChangesOther);
|
|
|
|
$result = $webUser->check_change_password($params);
|
|
|
|
if ($result == "success"){
|
|
|
|
//edit stuff into db
|
2013-07-03 01:05:01 +00:00
|
|
|
global $SITEBASE;
|
2013-09-09 01:47:32 +00:00
|
|
|
require_once($SITEBASE . '/inc/settings.php');
|
2013-07-03 01:05:01 +00:00
|
|
|
$succresult = settings();
|
2013-09-09 01:47:32 +00:00
|
|
|
$status = WebUsers::setPassword($target_username, $_POST["NewPass"]);
|
2013-07-02 01:36:49 +00:00
|
|
|
if($status == 'ok'){
|
2013-07-02 02:42:12 +00:00
|
|
|
$succresult['SUCCESS_PASS'] = "OK";
|
2013-07-02 01:36:49 +00:00
|
|
|
}else if($status == 'shardoffline'){
|
2013-07-02 02:42:12 +00:00
|
|
|
$succresult['SUCCESS_PASS'] = "SHARDOFF";
|
2013-07-02 01:36:49 +00:00
|
|
|
}
|
2013-09-09 01:47:32 +00:00
|
|
|
$succresult['permission'] = unserialize($_SESSION['ticket_user'])->getPermission();
|
2013-07-02 01:36:49 +00:00
|
|
|
$succresult['no_visible_elements'] = 'FALSE';
|
2013-07-03 01:05:01 +00:00
|
|
|
$succresult['username'] = $_SESSION['user'];
|
2013-07-02 01:36:49 +00:00
|
|
|
$succresult['target_id'] = $_POST['target_id'];
|
|
|
|
helpers :: loadtemplate( 'settings', $succresult);
|
2014-09-03 05:23:39 +00:00
|
|
|
throw new SystemExit();
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-07-01 21:29:16 +00:00
|
|
|
}else{
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-07-04 22:37:48 +00:00
|
|
|
$result['prevCurrentPass'] = filter_var($_POST["CurrentPass"], FILTER_SANITIZE_STRING);
|
|
|
|
$result['prevNewPass'] = filter_var($_POST["NewPass"], FILTER_SANITIZE_STRING);
|
|
|
|
$result['prevConfirmNewPass'] = filter_var($_POST["ConfirmNewPass"], FILTER_SANITIZE_STRING);
|
2013-09-09 01:47:32 +00:00
|
|
|
$result['permission'] = unserialize($_SESSION['ticket_user'])->getPermission();
|
2013-07-01 21:29:16 +00:00
|
|
|
$result['no_visible_elements'] = 'FALSE';
|
2013-07-04 22:37:48 +00:00
|
|
|
$result['username'] = $_SESSION['user'];
|
2013-07-01 21:29:16 +00:00
|
|
|
$result['target_id'] = $_POST['target_id'];
|
2013-07-03 01:05:01 +00:00
|
|
|
|
|
|
|
global $SITEBASE;
|
2013-09-09 01:47:32 +00:00
|
|
|
require_once($SITEBASE . '/inc/settings.php');
|
2013-07-03 01:05:01 +00:00
|
|
|
$settings = settings();
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-07-03 01:05:01 +00:00
|
|
|
$result = array_merge($result,$settings);
|
2013-07-01 21:29:16 +00:00
|
|
|
helpers :: loadtemplate( 'settings', $result);
|
2014-09-03 05:23:39 +00:00
|
|
|
throw new SystemExit();
|
2013-07-01 21:29:16 +00:00
|
|
|
}
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-07-01 16:28:37 +00:00
|
|
|
}else{
|
2013-07-01 21:29:16 +00:00
|
|
|
//ERROR: permission denied!
|
2013-07-04 22:37:48 +00:00
|
|
|
$_SESSION['error_code'] = "403";
|
2014-09-03 05:36:10 +00:00
|
|
|
header("Cache-Control: max-age=1");
|
2013-07-04 22:37:48 +00:00
|
|
|
header("Location: index.php?page=error");
|
2014-09-03 05:23:39 +00:00
|
|
|
throw new SystemExit();
|
2013-07-01 16:28:37 +00:00
|
|
|
}
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-07-01 21:29:16 +00:00
|
|
|
}else{
|
|
|
|
//ERROR: The form was not filled in correclty
|
2014-09-03 05:36:10 +00:00
|
|
|
header("Cache-Control: max-age=1");
|
2013-07-04 22:37:48 +00:00
|
|
|
header("Location: index.php?page=settings");
|
2014-09-03 05:23:39 +00:00
|
|
|
throw new SystemExit();
|
2014-09-03 05:06:43 +00:00
|
|
|
}
|
2013-07-01 21:29:16 +00:00
|
|
|
}else{
|
|
|
|
//ERROR: user is not logged in
|
2014-09-03 05:36:10 +00:00
|
|
|
header("Cache-Control: max-age=1");
|
2013-07-04 22:37:48 +00:00
|
|
|
header("Location: index.php");
|
2014-09-03 05:23:39 +00:00
|
|
|
throw new SystemExit();
|
2013-07-01 21:29:16 +00:00
|
|
|
}
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-07-01 21:29:16 +00:00
|
|
|
}catch (PDOException $e) {
|
|
|
|
//go to error page or something, because can't access website db
|
|
|
|
print_r($e);
|
2014-09-03 05:23:39 +00:00
|
|
|
throw new SystemExit();
|
2013-07-01 21:29:16 +00:00
|
|
|
}
|
2014-09-03 05:06:43 +00:00
|
|
|
|
2013-07-01 16:28:37 +00:00
|
|
|
}
|
|
|
|
|