123 lines
3.4 KiB
PHP
123 lines
3.4 KiB
PHP
<?php
|
|
/*
|
|
Author: Riccardo Di Dato
|
|
Creation Date: 17/mar/2016
|
|
*/
|
|
|
|
require_once(dirname(__FILE__)."/load.php");
|
|
|
|
GUIHandler::generateHtmlHeaders();
|
|
|
|
try{
|
|
$changed = false;
|
|
if (!array_key_exists("req",$_GET) || strcmp("req", "")==0 || !array_key_exists("u",$_GET) || strcmp("u", "")==0){
|
|
GUIHandler::redirect("index.php");
|
|
}
|
|
$requestCode = $_GET['req'];
|
|
$userId = $_GET['u'];
|
|
|
|
$user = GlobalVariables::get("dao")->getFirst("UserModel",array("id"=>$userId));
|
|
if (is_null($user)){
|
|
GUIHandler::redirect("index.php");
|
|
}
|
|
$request = GlobalVariables::get("dao")->getFirst("PasswordRecoveryRequestModel",array("id"=>$requestCode,"target.id"=>$userId,"target.class"=>"UserModel"));
|
|
if (is_null($request)){
|
|
GUIHandler::redirect("index.php");
|
|
}
|
|
|
|
$action = PostHandler::get("action");
|
|
if (!is_null($action) && strcmp("", $action)!=0){
|
|
if (strcmp("change", $action)==0){
|
|
$err = false;
|
|
$exc = new GUIException(array());
|
|
|
|
// Validate Password
|
|
$pass = trim(PostHandler::get("password"));
|
|
if (strcmp($pass,"")==0){
|
|
$err = true;
|
|
$exc->addMessage("Inserire una nuova password");
|
|
}
|
|
if (strcmp($pass,PostHandler::get("password_confirm"))!=0){
|
|
$err = true;
|
|
$exc->addMessage("Le password inserite non coincidono");
|
|
}
|
|
$user->password = sha1($pass);
|
|
|
|
if ($err){
|
|
throw $exc;
|
|
}
|
|
|
|
GlobalVariables::get("dao")->delete($request);
|
|
GlobalVariables::get("dao")->save($user);
|
|
$changed = true;
|
|
}
|
|
}
|
|
}catch(GUIException $ex){
|
|
$error = $ex->getMessageMerged("<br/>");
|
|
}catch (Exception $exec){
|
|
LoggingFacilityManager::getLogger("gui")->log(LoggingFacility::$LEVEL_ERROR, $exec->getMessage());
|
|
$error = "Si è verificato un errore inaspettato durante l'esecuzione della pagina. Se l'errore persiste contattare il supporto tecnico.";
|
|
}
|
|
?>
|
|
<div style="width:1000px;margin-left:auto;margin-right:auto;">
|
|
<?php
|
|
GUIHandler::generateHeadPublic();
|
|
GUIHandler::generateMenu();
|
|
if ($changed){
|
|
?>
|
|
<div class="passwordChange">
|
|
<div class="title" style="text-align:center;">
|
|
La password è stata modificata con successo.
|
|
</div>
|
|
<div class="formBtns">
|
|
<a href="index.php" >Home</a>
|
|
</div>
|
|
</div>
|
|
<?php
|
|
}
|
|
else {
|
|
?>
|
|
<div class="passwordChange">
|
|
<div class="title">
|
|
Inserire la nuova password da utilizzare per utilizzare l'applicazione
|
|
</div>
|
|
<?php
|
|
if(strcmp($error, "")!=0){
|
|
echo '<div style="font-size: 16px; color:red;">'.$error.'</div>';
|
|
}
|
|
?>
|
|
<form id="passwordChangeForm" method="POST" action="">
|
|
<input type="hidden" name="action" value="" />
|
|
<div class="row">
|
|
<span class="label">Password</span>
|
|
<input type="password" name="password" value="" />
|
|
</div>
|
|
<div class="row">
|
|
<span class="label">Conferma Password</span>
|
|
<input type="password" name="password_confirm" value="" />
|
|
</div>
|
|
</form>
|
|
<div class="formBtns">
|
|
<a href="#" id="passwordChangeForm_salva" >Conferma</a>
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
$(document).ready(function(event){
|
|
$("#passwordChangeForm_salva").click(function(event){
|
|
$("form#passwordChangeForm input[type=hidden][name=action]").val("change");
|
|
$("form#passwordChangeForm").submit();
|
|
});
|
|
|
|
$("form#passwordChangeForm input[type=password][name=password_confirm]").keypress(function(event) {
|
|
if (event.which==13){
|
|
$('#passwordChangeForm_salva').click();
|
|
return false;
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
<?php
|
|
}
|
|
GUIHandler::generateFooter();
|
|
?>
|
|
</div>
|