Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
callbackreqpasswd.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Callback page when requesting a password re-initialization
9  *
10  * @author Anakeen 2009
11  * @version $Id: callbackreqpasswd.php,v 1.5 2009/01/16 13:33:00 jerome Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage
15  */
16 /**
17  */
18 
20 {
21  include_once ('FDL/Lib.Dir.php');
22  include_once ('WHAT/Class.UserToken.php');
23 
24  $action->lay->set('CALLBACK_OK', False);
25  $action->lay->set('CALLBACK_NOT_OK', False);
26  $action->lay->set('ON_ERROR_CONTACT', $action->getParam('SMTP_FROM'));
27 
28  $token = getHttpVars('token');
29  // Retrieve token from database
30  $utok = new UserToken($action->dbaccess, $token);
31  if (!is_object($utok)) {
32  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "new UserToken(" . $token . ") returned with error : " . $utok);
33  $action->lay->set('CALLBACK_NOT_OK', True);
34  return "";
35  }
36  if (!$utok->isAffected()) {
37  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "no element found for token " . $token);
38  $action->lay->set('CALLBACK_NOT_OK', True);
39  return "";
40  }
41  // If this token has expired, remove all expired tokens
42  $now = time();
43  $expire = stringDateToUnixTs($utok->expire);
44  if ($now > $expire) {
45  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Token " . $utok->token . " has expired (expire = " . $utok->expire . ")");
46  $action->lay->set('CALLBACK_NOT_OK', True);
47  $utok->deleteExpired();
48  return "";
49  }
50 
51  $freedomdb = $action->getParam('FREEDOM_DB');
52  if ($freedomdb == "") {
53  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "FREEDOM_DB is empty");
54  $action->lay->set('CALLBACK_NOT_OK', True);
55  return "";
56  }
57  // Retrieve the IUSER document associated with the token
58  $iuser = new_Doc($freedomdb, $utok->userid);
59  if (!is_object($iuser)) {
60  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "new Doc(" . $userid . ") returned with error : " . $iuser);
61  $action->lay->set('CALLBACK_NOT_OK', True);
62  return "";
63  }
64  // Reset the password for the IUSER
65  $err = $iuser->disableEditControl();
66  if ($err != "") {
67  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "error disabling edit controls on document : " . $err);
68  $action->lay->set('CALLBACK_NOT_OK', True);
69  return "";
70  }
71 
72  $password = mkpasswd();
73  $err = $iuser->setPassword($password);
74  if ($err != "") {
75  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "setPassword() returned error : " . $err);
76  $action->lay->set('CALLBACK_NOT_OK', True);
77  return "";
78  }
79  // Send the new pasword by mail
80  $err = sendResponse($action, $iuser, 'AUTHENT/Layout/callbackreqpasswd_mail.xml', $password);
81  if ($err != "") {
82  $action->lay->set('CALLBACK_NOT_OK', True);
83  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "sendResponse() returned with error : " . $err);
84  return "";
85  }
86 
87  $action->lay->set('CALLBACK_OK', True);
88  // Delete the token in the database
89  $err = $utok->delete();
90  if ($err != "") {
91  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "utok->delete() returned with error : " . $err);
92  }
93 
94  return "";
95 }
96 
97 function sendResponse($action, $userdoc, $layoutPath, $password)
98 {
99  include_once ('WHAT/Class.UserToken.php');
100  include_once ("FDL/sendmail.php");
101 
102  $us_mail = $userdoc->getValue('us_mail');
103  $us_fname = $userdoc->getValue('us_fname');
104  $us_lname = $userdoc->getValue('us_lname');
105 
106  if ($us_mail == "") {
107  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Empty us_mail for user " . $userdoc->getValue('id'));
108  return "Empty us_mail for user " . $userdoc->getValue('id');
109  }
110 
111  $from = $action->getParam('SMTP_FROM');
112  $subject = $action->getParam('AUTHENT_CALLBACKREQPASSWD_MAIL_SUBJECT');
113 
114  $layout = new Layout($layoutPath, $action);
115  if ($layout == NULL) {
116  return "error creating new Layout from $layoutPath";
117  }
118 
119  $layout->set('US_MAIL', $us_mail);
120  $layout->set('US_FNAME', $us_fname);
121  $layout->set('US_LNAME', $us_lname);
122  $layout->set('PASSWORD', $password);
123 
124  $content = $layout->gen();
125 
126  $mimemail = new Fdl_Mail_Mime("\r\n");
127  $mimemail->setHTMLBody($content);
128 
129  $ret = sendmail($us_mail, $from, NULL, NULL, $subject, $mimemail, NULL);
130  if ($ret != "") {
131  return "Error: sendmail() returned with $ret";
132  }
133 
134  return "";
135 }
136 ?>
← centre documentaire © anakeen - published under CC License - Dynacase