nextcloud/settings/ajax/changepassword.php

39 lines
1.2 KiB
PHP
Raw Normal View History

<?php
// Init owncloud
require_once('../../lib/base.php');
2011-06-20 16:51:33 +04:00
$l=new OC_L10N('settings');
// We send json data
header( "Content-Type: application/jsonrequest" );
// Check if we are a user
2011-07-29 23:36:03 +04:00
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" ) )));
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!" ) )));
exit();
}
// Check if the old password is correct
2011-07-29 23:36:03 +04:00
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!") )));
exit();
}
// Change password
2011-07-29 23:36:03 +04:00
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-08-11 19:49:36 +04:00
OC_Crypt::changekeypasscode( $_POST["password"]) {
}
else{
2011-06-20 16:51:33 +04:00
echo json_encode( array( "status" => "error", "data" => array( "message" => $l->t("Unable to change password") )));
}
?>