Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
callbackreqpasswd.php
Go to the documentation of this file.
1 <?php
2 /*
3  * Callback page when requesting a password re-initialization
4  * @author Anakeen
5  * @package FDL
6 */
7 function callbackreqpasswd(Action & $action)
8 {
9  include_once ('FDL/Lib.Dir.php');
10  include_once ('WHAT/Class.UserToken.php');
11  // $action->parent->AddCssRef('AUTHENT:callbackreqpasswd.css');
12  $action->parent->AddCssRef('AUTHENT:loginform.css', true);
13  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/resizeimg.js");
14  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/geometry.js");
15  $action->parent->addJsRef("AUTHENT:loginform.js", true);
16  $action->lay->set('CALLBACK_OK', False);
17  $action->lay->set('CALLBACK_NOT_OK', False);
18  $action->lay->set('ON_ERROR_CONTACT', $action->getParam('SMTP_FROM'));
19  $au = new ActionUsage($action);
20  $token = $au->addRequiredParameter("token", "token number");
21  $uid = $au->addOptionalParameter("uid", "user id");
22  $pwd1 = $au->addOptionalParameter("pwd1", "new password 1");
23  $pwd2 = $au->addOptionalParameter("pwd2", "new password 2");
24  $au->verify();
25  // Retrieve token from database
26  $utok = new UserToken($action->dbaccess, $token);
27 
28  if (!$utok->isAffected()) {
29  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "no element found for token " . $token);
30  $action->exitError(_("Cannot access interface to change password"));
31  return "";
32  }
33  // If this token has expired, remove all expired tokens
35  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Token " . $utok->token . " has expired (expire = " . $utok->expire . ")");
36  $action->exitError(_("Cannot access interface to change password"));
37  return "";
38  }
39 
40  if (!$utok->context || !openAuthenticator::verifyOpenAccess($utok)) {
41  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "context not valid");
42  $action->exitError(_("Cannot access interface to change password"));
43  return "";
44  }
45  $context = unserialize($utok->context);
46  if (empty($context["app"]) || empty($context["action"])) {
47  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "context not valid");
48  $action->exitError(_("Cannot access interface to change password"));
49  }
50  // Retrieve the IUSER document associated with the token
51  $u = new Account('', $utok->userid);
52  if (!$u->isAffected()) {
53  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "new Doc(" . $utok->userid . ") returned with error : " . $utok->userid);
54  $action->exitError(_("Cannot access interface to change password"));
55  return "";
56  }
57 
58  $action->lay->eset("uid", $u->id);
59  $action->lay->eset("token", $token);
60  $finish = false;
61  $action->lay->eset("username", $u->getDisplayName($u->id));
62  $err = '';
63  if ($uid == $utok->userid) {
64  if ($pwd1 != '' && $pwd2 == $pwd1) {
65  // verify force
66 
67  /**
68  * @var \Dcp\Family\IUSER $udoc
69  */
70  $udoc = new_doc($action->dbaccess, $u->fid);
71  $udoc->disableEditControl();
72  if ($udoc->isAlive()) {
73  $err = $udoc->testForcePassword($pwd1);
74  if ($err == '') {
75  $u->password_new = $pwd1;
76  $err = $u->modify();
77  if ($err == "") {
78  $udoc->addHistoryEntry(_("Change password by token"));
79  }
80  // Delete the token in the database
81  $err = $utok->delete();
82  if ($err != "") {
83  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "utok->delete() returned with error : " . $err);
84  }
85  authLog(sprintf("Change password succeeded for %s [%d]", $u->login, $u->id));
86  $finish = true;
87  }
88  }
89  $udoc->enableEditControl();
90  } else {
91  if ($pwd1 == '') {
92  $err = _("password must not be empty");
93  } else {
94  $err = _("the two passwords must be the same");
95  }
96  }
97  } else {
98  if ($uid) {
99  $err = _("acking detection : clear token");
100  $utok->delete();
101  }
102  }
103 
104  if ($err) authLog(sprintf("Fail to change password for %s [%d] : %s", $u->login, $u->id, $err));
105  else if (!$finish) authLog(sprintf("Try to change password for %s [%d]", $u->login, $u->id));
106  $action->lay->set("errortxt", $err);
107  $action->lay->set("ERROR", ($err != ''));
108  $action->lay->set("finish", $finish);
109 
110  return "";
111 }
112 
113 function authLog($txt)
114 {
115  $log = new Log("", "Authent", "ChangePassword");
116  $facility = constant(getParam("AUTHENT_LOGFACILITY", "LOG_AUTH"));
117  $log->wlog("S", $txt, NULL, $facility);
118 }
global $action
static verifyOpenExpire(\UserToken $token)
$log
Definition: wsh.php:33
exitError($texterr, $exit=true, $code="")
authLog($txt)
getParam($name, $def="")
must be in core or global type
Definition: Lib.Common.php:193
Verify arguments for action function.
getParam($name, $def="")
static verifyOpenAccess(\UserToken $token)
if($file) if($subject==""&&$file) if($subject=="") $err
← centre documentaire © anakeen