2011-04-18 17:07:14 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// Init owncloud
|
|
|
|
require_once('../../lib/base.php');
|
|
|
|
|
2011-06-20 16:51:33 +04:00
|
|
|
$l=new OC_L10N('settings');
|
|
|
|
|
2011-04-18 17:07:14 +04:00
|
|
|
// We send json data
|
|
|
|
header( "Content-Type: application/jsonrequest" );
|
|
|
|
|
|
|
|
// Check if we are a user
|
|
|
|
if( !OC_USER::isLoggedIn()){
|
2011-06-20 16:51:33 +04:00
|
|
|
echo json_encode( array( "status" => "error", "data" => array( "message" => $l->t( "Authentication error" ) )));
|
2011-04-18 17:07:14 +04:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get data
|
|
|
|
if( !isset( $_POST["password"] ) && !isset( $_POST["oldpassword"] )){
|
2011-06-20 16:51:33 +04:00
|
|
|
echo json_encode( array( "status" => "error", "data" => array( "message" => $l->t( "You have to enter the old and the new password!" ) )));
|
2011-04-18 17:07:14 +04:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the old password is correct
|
|
|
|
if( !OC_USER::checkPassword( $_SESSION["user_id"], $_POST["oldpassword"] )){
|
2011-06-20 16:51:33 +04:00
|
|
|
echo json_encode( array( "status" => "error", "data" => array( "message" => $l->t("Your old password is wrong!") )));
|
2011-04-18 17:07:14 +04:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change password
|
|
|
|
if( OC_USER::setPassword( $_SESSION["user_id"], $_POST["password"] )){
|
2011-06-20 16:51:33 +04:00
|
|
|
echo json_encode( array( "status" => "success", "data" => array( "message" => $l->t("Password changed") )));
|
2011-04-18 17:07:14 +04:00
|
|
|
}
|
|
|
|
else{
|
2011-06-20 16:51:33 +04:00
|
|
|
echo json_encode( array( "status" => "error", "data" => array( "message" => $l->t("Unable to change password") )));
|
2011-04-18 17:07:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|