parent
46f1ea14c0
commit
b57823baa5
@ -0,0 +1,35 @@ |
||||
<?php |
||||
|
||||
// Init owncloud |
||||
require_once('../../lib/base.php'); |
||||
|
||||
// We send json data |
||||
header( "Content-Type: application/jsonrequest" ); |
||||
|
||||
// Check if we are a user |
||||
if( !OC_USER::isLoggedIn()){ |
||||
echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" ))); |
||||
exit(); |
||||
} |
||||
|
||||
// Get data |
||||
if( !isset( $_POST["password"] ) && !isset( $_POST["oldpassword"] )){ |
||||
echo json_encode( array( "status" => "error", "data" => array( "message" => "You have to enter the old and the new password!" ))); |
||||
exit(); |
||||
} |
||||
|
||||
// Check if the old password is correct |
||||
if( !OC_USER::checkPassword( $_SESSION["user_id"], $_POST["oldpassword"] )){ |
||||
echo json_encode( array( "status" => "error", "data" => array( "message" => "Your old password is wrong!" ))); |
||||
exit(); |
||||
} |
||||
|
||||
// Change password |
||||
if( OC_USER::setPassword( $_SESSION["user_id"], $_POST["password"] )){ |
||||
echo json_encode( array( "status" => "success", "data" => array( "message" => "Password changed" ))); |
||||
} |
||||
else{ |
||||
echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to change password" ))); |
||||
} |
||||
|
||||
?> |
@ -0,0 +1,2 @@ |
||||
#passworderror{display:none;} |
||||
#passwordchanged{display:none;} |
@ -0,0 +1,21 @@ |
||||
$(document).ready(function(){ |
||||
$("#passwordbutton").click( function(){ |
||||
// Serialize the data
|
||||
var post = $( "#passwordform" ).serialize(); |
||||
$('#passwordchanged').hide(); |
||||
$('#passworderror').hide(); |
||||
// Ajax foo
|
||||
$.post( 'ajax/changepassword.php', post, function(data){ |
||||
if( data.status == "success" ){ |
||||
$('#pass1').val(''); |
||||
$('#pass2').val(''); |
||||
$('#passwordchanged').show(); |
||||
} |
||||
else{ |
||||
$('#passworderror').html( data.data.message ); |
||||
$('#passworderror').show(); |
||||
} |
||||
}); |
||||
return false; |
||||
}); |
||||
} ); |
Loading…
Reference in new issue