![]() |
Xataface 2.0
Xataface Application Framework
|
00001 <?php 00002 class dataface_actions_change_password { 00003 function handle($params){ 00004 00005 $app = Dataface_Application::getInstance(); 00006 $auth = Dataface_AuthenticationTool::getInstance(); 00007 $user = $auth->getLoggedInUser(); 00008 $username = $auth->getLoggedInUsername(); 00009 00010 if ( !$user or !$username ){ 00011 return Dataface_Error::permissionDenied('You must be logged in to change your password'); 00012 } 00013 00014 if ( $_POST ){ 00015 00016 try { 00017 00018 if ( !@$_POST['--password1'] || !@$_POST['--password2'] ){ 00019 throw new Exception("Please enter your new password in both fields provided."); 00020 } 00021 00022 if ( !@$_POST['--current-password'] ){ 00023 throw new Exception("Please enter your current password in the field provided."); 00024 00025 } 00026 00027 $_REQUEST['UserName'] = $username; 00028 $_REQUEST['Password'] = $_POST['--current-password']; 00029 00030 if ( !$auth->checkCredentials() ){ 00031 throw new Exception("The password you entered is incorrect. Please try again."); 00032 } 00033 00034 if ( strcmp($_POST['--password1'], $_POST['--password2'])!==0 ){ 00035 throw new Exception("Your new passwords don't match. Please ensure that you retype your new password correctly."); 00036 00037 } 00038 00039 $res = $auth->setPassword($_POST['--password1']); 00040 00041 $this->out(array( 00042 'code'=>200, 00043 'message'=>'Your password has been successfully changed' 00044 )); 00045 exit; 00046 } catch (Exception $ex){ 00047 $this->out(array( 00048 'code'=> $ex->getCode(), 00049 'message'=>$ex->getMessage() 00050 )); 00051 exit; 00052 } 00053 00054 } else { 00055 00056 $jt = Dataface_JavascriptTool::getInstance(); 00057 $jt->import('change_password.js'); 00058 00059 df_display(array(), 'change_password.html'); 00060 } 00061 00062 00063 00064 } 00065 00066 00067 function out($params){ 00068 header('Content-type: text/json; charset="'.Dataface_Application::getInstance()->_conf['oe'].'"'); 00069 echo json_encode($params); 00070 } 00071 }