Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
change_password.php
Go to the documentation of this file.
1 <?php
3  function handle($params){
4 
7  $user = $auth->getLoggedInUser();
8  $username = $auth->getLoggedInUsername();
9 
10  if ( !$user or !$username ){
11  return Dataface_Error::permissionDenied('You must be logged in to change your password');
12  }
13 
14  if ( $_POST ){
15 
16  try {
17 
18  if ( !@$_POST['--password1'] || !@$_POST['--password2'] ){
19  throw new Exception("Please enter your new password in both fields provided.");
20  }
21 
22  if ( !@$_POST['--current-password'] ){
23  throw new Exception("Please enter your current password in the field provided.");
24 
25  }
26 
27  $_REQUEST['UserName'] = $username;
28  $_REQUEST['Password'] = $_POST['--current-password'];
29 
30  if ( !$auth->checkCredentials() ){
31  throw new Exception("The password you entered is incorrect. Please try again.");
32  }
33 
34  if ( strcmp($_POST['--password1'], $_POST['--password2'])!==0 ){
35  throw new Exception("Your new passwords don't match. Please ensure that you retype your new password correctly.");
36 
37  }
38 
39  $res = $auth->setPassword($_POST['--password1']);
40 
41  $this->out(array(
42  'code'=>200,
43  'message'=>'Your password has been successfully changed'
44  ));
45  exit;
46  } catch (Exception $ex){
47  $this->out(array(
48  'code'=> $ex->getCode(),
49  'message'=>$ex->getMessage()
50  ));
51  exit;
52  }
53 
54  } else {
55 
57  $jt->import('change_password.js');
58 
59  df_display(array(), 'change_password.html');
60  }
61 
62 
63 
64  }
65 
66 
67  function out($params){
68  header('Content-type: application/json; charset="'.Dataface_Application::getInstance()->_conf['oe'].'"');
69  echo json_encode($params);
70  }
71 }