From b57823baa5d4f0d23be8d034550a0ffcb788a2ca Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Mon, 18 Apr 2011 15:07:14 +0200 Subject: [PATCH] Made the "change password" thingie in settings working --- files/ajax/rename.php | 2 +- files/ajax/upload.php | 2 +- lib/User/database.php | 8 ++++---- settings/ajax/changepassword.php | 35 ++++++++++++++++++++++++++++++++ settings/css/settings.css | 2 ++ settings/index.php | 9 +++++++- settings/js/main.js | 21 +++++++++++++++++++ settings/templates/index.php | 20 ++++++++++-------- 8 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 settings/ajax/changepassword.php create mode 100644 settings/css/settings.css create mode 100644 settings/js/main.js diff --git a/files/ajax/rename.php b/files/ajax/rename.php index 86cb7944a8..65763fceb9 100644 --- a/files/ajax/rename.php +++ b/files/ajax/rename.php @@ -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(); } diff --git a/files/ajax/upload.php b/files/ajax/upload.php index 959794913b..194d84f4be 100644 --- a/files/ajax/upload.php +++ b/files/ajax/upload.php @@ -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(); } diff --git a/lib/User/database.php b/lib/User/database.php index 3abaf9e1f4..eeabb592c2 100644 --- a/lib/User/database.php +++ b/lib/User/database.php @@ -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; + } } /** diff --git a/settings/ajax/changepassword.php b/settings/ajax/changepassword.php new file mode 100644 index 0000000000..1a9ad73610 --- /dev/null +++ b/settings/ajax/changepassword.php @@ -0,0 +1,35 @@ + "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" ))); +} + +?> diff --git a/settings/css/settings.css b/settings/css/settings.css new file mode 100644 index 0000000000..23561ec367 --- /dev/null +++ b/settings/css/settings.css @@ -0,0 +1,2 @@ +#passworderror{display:none;} +#passwordchanged{display:none;} \ No newline at end of file diff --git a/settings/index.php b/settings/index.php index 9bf89145cc..1a442eca81 100644 --- a/settings/index.php +++ b/settings/index.php @@ -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); diff --git a/settings/js/main.js b/settings/js/main.js new file mode 100644 index 0000000000..e05fc68743 --- /dev/null +++ b/settings/js/main.js @@ -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; + }); +} ); diff --git a/settings/templates/index.php b/settings/templates/index.php index 33d27922d8..2d5e9d9140 100644 --- a/settings/templates/index.php +++ b/settings/templates/index.php @@ -6,23 +6,25 @@ -
+
- User settings + Change Password +
You're password got changed
+

- - + +

- - + +

- - + +