khanat-opennel-code/code/web/public_php/ams/func/change_password.php

100 lines
4.8 KiB
PHP
Raw Normal View History

2013-07-01 16:28:37 +00:00
<?php
/**
* 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{
//if logged in
if(WebUsers::isLoggedIn()){
2014-09-03 05:06:43 +00:00
if(isset($_POST['target_id'])){
$adminChangesOther = false;
//if target_id is the same as session id or is admin
if( ($_POST['target_id'] == $_SESSION['id']) || Ticket_User::isMod(unserialize($_SESSION['ticket_user'])) ){
if($_POST['target_id'] == $_SESSION['id']){
//if the password is of the executing user himself
$target_username = $_SESSION['user'];
}else{
//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();
//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']);
$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
global $SITEBASE;
require_once($SITEBASE . '/inc/settings.php');
$succresult = settings();
$status = WebUsers::setPassword($target_username, $_POST["NewPass"]);
2013-07-02 01:36:49 +00:00
if($status == 'ok'){
$succresult['SUCCESS_PASS'] = "OK";
2013-07-02 01:36:49 +00:00
}else if($status == 'shardoffline'){
$succresult['SUCCESS_PASS'] = "SHARDOFF";
2013-07-02 01:36:49 +00:00
}
$succresult['permission'] = unserialize($_SESSION['ticket_user'])->getPermission();
2013-07-02 01:36:49 +00:00
$succresult['no_visible_elements'] = 'FALSE';
$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
}else{
2014-09-03 05:06:43 +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);
$result['permission'] = unserialize($_SESSION['ticket_user'])->getPermission();
$result['no_visible_elements'] = 'FALSE';
$result['username'] = $_SESSION['user'];
$result['target_id'] = $_POST['target_id'];
global $SITEBASE;
require_once($SITEBASE . '/inc/settings.php');
$settings = settings();
2014-09-03 05:06:43 +00:00
$result = array_merge($result,$settings);
helpers :: loadtemplate( 'settings', $result);
2014-09-03 05:23:39 +00:00
throw new SystemExit();
}
2014-09-03 05:06:43 +00:00
2013-07-01 16:28:37 +00:00
}else{
//ERROR: permission denied!
$_SESSION['error_code'] = "403";
2014-09-03 05:36:10 +00:00
header("Cache-Control: max-age=1");
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
}else{
//ERROR: The form was not filled in correclty
2014-09-03 05:36:10 +00:00
header("Cache-Control: max-age=1");
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
}
}else{
//ERROR: user is not logged in
2014-09-03 05:36:10 +00:00
header("Cache-Control: max-age=1");
header("Location: index.php");
2014-09-03 05:23:39 +00:00
throw new SystemExit();
}
2014-09-03 05:06:43 +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();
}
2014-09-03 05:06:43 +00:00
2013-07-01 16:28:37 +00:00
}