Made the "change password" thingie in settings working
This commit is contained in:
parent
46f1ea14c0
commit
b57823baa5
8 changed files with 83 additions and 16 deletions
|
@ -8,7 +8,7 @@ header( "Content-Type: application/jsonrequest" );
|
|||
|
||||
// Check if we are a user
|
||||
if( !OC_USER::isLoggedIn()){
|
||||
echo json_encode( array( "status" => "error", "data" => "Authentication error" ));
|
||||
echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" )));
|
||||
exit();
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ header( "Content-Type: text/plain" );
|
|||
|
||||
// Check if we are a user
|
||||
if( !OC_USER::isLoggedIn()){
|
||||
echo json_encode( array( "status" => "error", "data" => "Authentication error" ));
|
||||
echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" )));
|
||||
exit();
|
||||
}
|
||||
|
||||
|
|
|
@ -156,15 +156,15 @@ class OC_USER_DATABASE extends OC_USER_BACKEND {
|
|||
$query = OC_DB::prepare( "SELECT * FROM `*PREFIX*users` WHERE uid = ?" );
|
||||
$result = $query->execute( array( $uid ));
|
||||
|
||||
if ( $result->numRows() > 0 ){
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
if( $result->numRows() > 0 ){
|
||||
$query = OC_DB::prepare( "UPDATE *PREFIX*users SET password = ? WHERE uid = ?" );
|
||||
$result = $query->execute( array( sha1( $password ), $uid ));
|
||||
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
35
settings/ajax/changepassword.php
Normal file
35
settings/ajax/changepassword.php
Normal file
|
@ -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" )));
|
||||
}
|
||||
|
||||
?>
|
2
settings/css/settings.css
Normal file
2
settings/css/settings.css
Normal file
|
@ -0,0 +1,2 @@
|
|||
#passworderror{display:none;}
|
||||
#passwordchanged{display:none;}
|
|
@ -7,12 +7,19 @@ if( !OC_USER::isLoggedIn()){
|
|||
exit();
|
||||
}
|
||||
|
||||
// Highlight navigation entry
|
||||
OC_APP::setActiveNavigationEntry( "settings" );
|
||||
$tmpl = new OC_TEMPLATE( "settings", "index", "admin");
|
||||
OC_UTIL::addScript( "settings", "main" );
|
||||
OC_UTIL::addStyle( "settings", "settings" );
|
||||
|
||||
// calculate the disc space
|
||||
$used=OC_FILESYSTEM::filesize('/');
|
||||
$free=OC_FILESYSTEM::free_space();
|
||||
$total=$free+$used;
|
||||
$relative=round(($used/$total)*100);
|
||||
|
||||
// Return template
|
||||
$tmpl = new OC_TEMPLATE( "settings", "index", "admin");
|
||||
$tmpl->assign('usage',OC_HELPER::humanFileSize($used));
|
||||
$tmpl->assign('total_space',OC_HELPER::humanFileSize($total));
|
||||
$tmpl->assign('usage_relative',$relative);
|
||||
|
|
21
settings/js/main.js
Normal file
21
settings/js/main.js
Normal file
|
@ -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;
|
||||
});
|
||||
} );
|
|
@ -6,23 +6,25 @@
|
|||
</fieldset>
|
||||
</form>
|
||||
|
||||
<form id="user_settings">
|
||||
<form id="passwordform">
|
||||
<fieldset>
|
||||
<legend>User settings</legend>
|
||||
<legend>Change Password</legend>
|
||||
<div id="passwordchanged">You're password got changed</div>
|
||||
<div id="passworderror"></div>
|
||||
<p>
|
||||
<label for="email">Email :</label>
|
||||
<input type="text" id="email" name="email" value="user@example.net" />
|
||||
<label for="pass1">Old password:</label>
|
||||
<input type="password" id="pass1" name="oldpassword" />
|
||||
</p>
|
||||
<p>
|
||||
<label for="pass1">New password :</label>
|
||||
<input type="password" id="pass1" name="pass1" />
|
||||
<label for="pass2">New password :</label>
|
||||
<input type="password" id="pass2" name="password" />
|
||||
</p>
|
||||
<p>
|
||||
<label for="pass2">Confirm new password :</label>
|
||||
<input type="password" id="pass2" name="pass2" />
|
||||
<input type="checkbox" id="show" name="show" />
|
||||
<label for="show">Show new password</label>
|
||||
</p>
|
||||
<p class="form_footer">
|
||||
<input class="prettybutton" type="submit" value="Save" />
|
||||
<input id="passwordbutton" class="prettybutton" type="submit" value="Save" />
|
||||
</p>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
|
Loading…
Reference in a new issue