Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
change_user_password.php
Go to the documentation of this file.
1 <?php
2 
3 include_once "FDL/freedom_util.php";
4 
5 /**
6  * Change password for the current user
7  *
8  * @param Action $action
9  * @throws Exception
10  */
12 {
13 
14  $return = array(
15  "success" => true,
16  "error" => array(),
17  "data" => array()
18  );
19 
20  try {
21 
22  $usage = new ActionUsage($action);
23 
24  $oldPassword = $usage->addRequiredParameter("old_password", "old password value");
25  $newPassword1 = $usage->addRequiredParameter("new_password_1", "new password");
26  $newPassword2 = $usage->addRequiredParameter("new_password_2", "new password verif value");
27 
28  $usage->setStrictMode(false);
29  $usage->verify(true);
30 
31  $user = new_Doc('', $action->user->fid);
32  /* @var $user _IUSER */
33  $err = $user->canEdit();
34  if ($err) {
35  throw new Exception(_("CHANGE_PASSWORD:You can't modify your account"));
36  }
37 
38  if (!$action->user->checkpassword($oldPassword)) {
39  throw new Exception(_("CHANGE_PASSWORD:The old password is not good"));
40  }
41 
42  $err = $user->constraintPassword($newPassword1, $newPassword2, $action->user->login);
43  if (isset($err["err"]) && !empty($err["err"])) {
44  throw new Exception(sprintf(_("CHANGE_PASSWORD:The provided password is not good (%s)"), $err["err"]));
45  }
46 
47  $err = $user->testForcePassword($newPassword1);
48  if ($err) {
49  throw new Exception(sprintf(_("CHANGE_PASSWORD:The provided password is not good (%s)"), $err));
50  }
51 
52  $err = $user->setPassword($newPassword1);
53  if ($err) {
54  throw new Exception(sprintf(_("CHANGE_PASSWORD:Unable to change password (%s)"), $err));
55  }
56 
57  } catch (Exception $e) {
58  $return["success"] = false;
59  $return["error"][] = $e->getMessage();
60  unset($return["data"]);
61  }
62 
63  $action->lay->template = json_encode($return);
64  $action->lay->noparse = true;
65  header('Content-type: application/json');
66 
67 }
global $action
change_user_password(Action &$action)
Verify arguments for action function.
new_Doc($dbaccess, $id= '', $latest=false)
if($file) if($subject==""&&$file) if($subject=="") $err
$usage
← centre documentaire © anakeen