Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
submitreqpasswd.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * submitreqpasswd function for receiving password re-initialization
8  * request and send the user a mail containing a new generated
9  * password
10  *
11  * @author Anakeen
12  * @package FDL
13  * @subpackage
14  */
15 /**
16  * @param Action $action
17  * @throws \Dcp\Core\Exception
18  */
20 {
21  include_once ('FDL/Lib.Dir.php');
22  include_once ('FDL/freedom_util.php');
23 
24  $submitted_login = $action->getArgument('form_login');
25  $submitted_email = $action->getArgument('form_email');
26 
27  $lang = $action->getArgument("lang");
28 
30 
31  $action->parent->AddCssRef('AUTHENT:loginform.css', true);
32  $action->parent->AddCssRef('AUTHENT:submitreqpasswd.css');
33  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/resizeimg.js");
34  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/geometry.js");
35  $action->parent->addJsRef("AUTHENT:loginform.js");
36 
37  $action->lay->set('FORM_SEND_OK', False);
38  $action->lay->set('FORM_SEND_ERROR_INVALID_ARGS', False);
39  $action->lay->set('FORM_SEND_ERROR_UNKNOWN', False);
40  $action->lay->set('FORM_SEND_ERROR_EXTERNAL_AUTH', False);
41  $action->lay->set('ON_ERROR_CONTACT', $action->getParam('SMTP_FROM', ___("Address not configured","authent")));
42  $action->lay->eSet("lang", $lang);
43 
44  $userdoc = retrieveUserDoc($action, $submitted_login, $submitted_email);
45 
46  if ($userdoc == NULL) {
47  $action->lay->set('FORM_SEND_ERROR_INVALID_ARGS', True);
48  return;
49  }
50 
51  $providerList = getAuthProviderList();
52  $ldapUserFamId = getIdFromName($action->dbaccess, 'LDAPUSER');
53  if (!in_array('freedom', $providerList) || ($ldapUserFamId !== false && $userdoc->fromid == $ldapUserFamId)) {
54  $action->lay->set('FORM_SEND_ERROR_EXTERNAL_AUTH', True);
55  return;
56  }
57 
58  $ret = sendCallback($action, $userdoc);
59  if ($ret != "") {
60  error_log(__FUNCTION__ . " $ret");
61  $action->lay->set('FORM_SEND_ERROR_UNKNOWN', True);
62  return;
63  }
64  $log = new Log("", "Authent", "ChangePassword");
65  $facility = constant(getParam("AUTHENT_LOGFACILITY", "LOG_AUTH"));
66  $txt = sprintf("ask change password for %s [%d]", $userdoc->getAccount()->login, $userdoc->getAccount()->id);
67  $log->wlog("S", $txt, NULL, $facility);
68  $action->lay->set('FORM_SEND_OK', True);
69  return;
70 }
71 /**
72  * @param Action $action
73  * @param string $login
74  * @param string $email
75  * @return \Dcp\Family\Iuser|null
76  */
77 function retrieveUserDoc(Action $action, $login = "", $email = "")
78 {
79 
80  $action->lay->set('MAILMULTIPLE', false);
81  if (!$login && !$email) {
82  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Undefined email and login args.");
83  return NULL;
84  }
85 
86  $s = new SearchDoc($action->dbaccess, "IUSER");
87  if ($login != "") {
88  $s->addFilter("us_login = '%s'", $login);
89  }
90  if ($email != "") {
91  $s->addFilter("us_mail = '%s'", $email);
92  }
93 
94  $s->setObjectReturn();
95  $s->overrideViewControl();
96  $s->search();
97  if ($s->count() <= 0) {
98  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Empty search result");
99  return NULL;
100  }
101 
102  if ($s->count() > 1) {
103  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Result contains more than 1 element");
104 
105  $action->lay->set('MAILMULTIPLE', true);
106  return NULL;
107  }
108  /**
109  * @var \Dcp\Family\IUSER $uDoc
110  */
111  $uDoc = $s->getNextDoc();
112  $email = $uDoc->getMail();
113  if ($email == "") {
114  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Empty us_mail for docid '" . $uDoc->id . "'");
115  return NULL;
116  }
117 
118  return $uDoc;
119 }
120 
121 function sendCallback(Action $action, \Dcp\family\IUser $userdoc)
122 {
123  include_once ('WHAT/Class.UserToken.php');
124  include_once ("FDL/sendmail.php");
125 
126  $us_mail = $userdoc->getMail();
127  $uid = $userdoc->getRawValue("us_whatid");
128  if ($us_mail == "") {
129  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Empty us_mail for user " . $uid);
130  return "Empty us_mail for user " . $uid;
131  }
132 
133  $token = new UserToken();
134  $token->userid = $uid;
135  $token->token = $token->genToken();
136  $token->setExpiration();
137  $token->expendable = 1;
138  $token->context = serialize(array(
139  "app" => "AUTHENT",
140  "action" => "CALLBACKREQPASSWD"
141  ));
142  $token->description=___("Forget password", "authent");
143  $err = $token->add();
144  if ($err != "") {
145  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Error token->add() : " . $err);
146  return $err;
147  }
148  $err = $token->modify();
149  if ($err != "") {
150  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Error token->modify() : " . $err);
151  return $err;
152  }
153 
154  $callback_token = $token->getToken();
155  /**
156  * @var \Dcp\Family\MAILTEMPLATE $mt
157  */
158  $mt = new_doc($action->dbaccess, $action->GetParam("AUTHENT_MAILASKPWD"));
159  if (!$mt->isAlive()) {
160  return sprintf("Cannot found mail template from AUTHENT_MAILASKPWD parameter");
161  }
162  if (!is_a($mt, '_MAILTEMPLATE')) {
163  return sprintf("AUTHENT_MAILASKPWD parameter not reference a mail template");
164  }
165  $keys = array(
166  "LINK_CHANGE_PASSWORD" => sprintf("%sguest.php?app=AUTHENT&action=CALLBACKREQPASSWD&token=%s", $action->GetParam("CORE_EXTERNURL") , $callback_token)
167  );
168  $err = $mt->sendDocument($userdoc, $keys);
169 
170  return $err;
171 }
global $action
$ret
if($famId) $s
if(!function_exists('pgettext')) ___($message, $context="")
Definition: Lib.Common.php:46
submitreqpasswd(Action &$action)
$lang
Definition: lang.php:18
$log
Definition: wsh.php:33
getParam($name, $def="")
must be in core or global type
Definition: Lib.Common.php:193
$login
Definition: dav.php:40
setLanguage($lang)
Definition: Lib.Common.php:886
getParam($name, $def="")
static getArgument($k, $def= '')
getIdFromName($dbaccess, $name)
if($file) if($subject==""&&$file) if($subject=="") $err
getAuthProviderList($freedomctx="")
Definition: Lib.Common.php:564
← centre documentaire © anakeen