Platform  3.1
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  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * submitreqpasswd function for receiving password re-initialization
9  * request and send the user a mail containing a new generated
10  * password
11  *
12  * @author Anakeen 2009
13  * @version $Id: submitreqpasswd.php,v 1.4 2009/01/16 13:33:00 jerome Exp $
14  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
15  * @package FDL
16  * @subpackage
17  */
18 /**
19  */
20 
22 {
23  include_once ('FDL/Lib.Dir.php');
24  include_once ('FDL/freedom_util.php');
25 
26  $submitted_login = GetHttpVars('form_login');
27  $submitted_email = GetHttpVars('form_email');
28 
29  $action->lay->set('FORM_SEND_OK', False);
30  $action->lay->set('FORM_SEND_ERROR_INVALID_ARGS', False);
31  $action->lay->set('FORM_SEND_ERROR_UNKNOWN', False);
32  $action->lay->set('FORM_SEND_ERROR_EXTERNAL_AUTH', False);
33  $action->lay->set('ON_ERROR_CONTACT', $action->getParam('SMTP_FROM'));
34 
35  $userdoc = getUserDoc($action, $submitted_login, $submitted_email);
36  if ($userdoc == NULL) {
37  $action->lay->set('FORM_SEND_ERROR_INVALID_ARGS', True);
38  return;
39  }
40 
41  $providerList = getAuthProviderList();
42  $ldapUserFamId = getIdFromName($action->dbaccess, 'LDAPUSER');
43  if (!in_array('freedom', $providerList) || ($ldapUserFamId !== false && $userdoc['fromid'] == $ldapUserFamId)) {
44  $action->lay->set('FORM_SEND_ERROR_EXTERNAL_AUTH', True);
45  return;
46  }
47 
48  $ret = sendCallback($action, $userdoc, 'AUTHENT/Layout/submitreqpasswd_mail.xml');
49  if ($ret != "") {
50  $action->lay->set('FORM_SEND_ERROR_UNKNOWN', True);
51  return;
52  }
53 
54  $action->lay->set('FORM_SEND_OK', True);
55  return;
56 }
57 
58 function getUserDoc($action, $login = "", $email = "")
59 {
60  $dbaccess = $action->getParam('FREEDOM_DB');
61 
62  $filter = array();
63 
64  if ($login != "") {
65  $filter[] = "us_login = '" . pg_escape_string($login) . "'";
66  }
67  if ($email != "") {
68  $filter[] = "us_mail = '" . pg_escape_string($email) . "'";
69  }
70 
71  if (count($filter) <= 0) {
72  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Undefined email and login args.");
73  return NULL;
74  }
75  $res = getChildDoc($dbaccess, 0, '0', 'ALL', $filter, 1, 'TABLE', 'IUSER');
76  if (count($res) <= 0) {
77  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Empty search result");
78  return NULL;
79  }
80 
81  if (count($res) > 1) {
82  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Result contains more than 1 element");
83  return NULL;
84  }
85 
86  $email = $res[0]['us_mail'];
87 
88  if ($email == "") {
89  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Empty us_mail for docid '" . $res[0]['id'] . "'");
90  return NULL;
91  }
92 
93  return $res[0];
94 }
95 
96 function sendCallback($action, $userdoc, $layoutPath)
97 {
98  include_once ('WHAT/Class.UserToken.php');
99  include_once ("FDL/sendmail.php");
100 
101  $us_mail = $userdoc['us_mail'];
102  $us_fname = $userdoc['us_fname'];
103  $us_lname = $userdoc['us_lname'];
104 
105  if ($us_mail == "") {
106  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Empty us_mail for user " . $userdoc['id']);
107  return "Empty us_mail for user " . $userdoc['id'];
108  }
109 
110  $from = $action->getParam('SMTP_FROM');
111  $subject = $action->getParam('AUTHENT_SUBMITREQPASSWD_MAIL_SUBJECT');
112 
113  $token = new UserToken();
114  $token->userid = $userdoc['id'];
115  $token->token = $token->genToken();
116  $token->setExpiration();
117  $token->expendable = 1;
118  $err = $token->add();
119  if ($err != "") {
120  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Error token->add() : " . $err);
121  return $err;
122  }
123  $err = $token->modify();
124  if ($err != "") {
125  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . "Error token->modify() : " . $err);
126  return $err;
127  }
128 
129  $callback_token = $token->getToken();
130 
131  $layout = new Layout($layoutPath, $action);
132  if ($layout == NULL) {
133  return "error creating new Layout from $layoutPath";
134  }
135 
136  $layout->set('US_MAIL', $us_mail);
137  $layout->set('US_FNAME', $us_fname);
138  $layout->set('US_LNAME', $us_lname);
139  $layout->set('CALLBACK_TOKEN', $callback_token);
140 
141  $content = $layout->gen();
142 
143  $mimemail = new Fdl_Mail_Mime("\r\n");
144  $mimemail->setHTMLBody($content);
145 
146  $ret = sendmail($us_mail, $from, NULL, NULL, $subject, $mimemail, NULL);
147  if ($ret != "") {
148  # $action->exitError("Error: sendmail() returned with $ret");
149  return "Error: sendmail() returned with $ret";
150  }
151 
152  return "";
153 }
154 ?>
← centre documentaire © anakeen - published under CC License - Dynacase