root/wifidog/tags/wifidog-auth_1.0/lost_password.php

Revision 395, 7.1 kB (checked in by syrus, 1 year ago)

Version Prod 20071208

Line 
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 // +-------------------------------------------------------------------+
6 // | WiFiDog Authentication Server                                     |
7 // | =============================                                     |
8 // |                                                                   |
9 // | The WiFiDog Authentication Server is part of the WiFiDog captive  |
10 // | portal suite.                                                     |
11 // +-------------------------------------------------------------------+
12 // | PHP version 5 required.                                           |
13 // +-------------------------------------------------------------------+
14 // | Homepage:     http://www.wifidog.org/                             |
15 // | Source Forge: http://sourceforge.net/projects/wifidog/            |
16 // +-------------------------------------------------------------------+
17 // | This program is free software; you can redistribute it and/or     |
18 // | modify it under the terms of the GNU General Public License as    |
19 // | published by the Free Software Foundation; either version 2 of    |
20 // | the License, or (at your option) any later version.               |
21 // |                                                                   |
22 // | This program is distributed in the hope that it will be useful,   |
23 // | but WITHOUT ANY WARRANTY; without even the implied warranty of    |
24 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     |
25 // | GNU General Public License for more details.                      |
26 // |                                                                   |
27 // | You should have received a copy of the GNU General Public License |
28 // | along with this program; if not, contact:                         |
29 // |                                                                   |
30 // | Free Software Foundation           Voice:  +1-617-542-5942        |
31 // | 59 Temple Place - Suite 330        Fax:    +1-617-542-2652        |
32 // | Boston, MA  02111-1307,  USA       gnu@gnu.org                    |
33 // |                                                                   |
34 // +-------------------------------------------------------------------+
35
36 /**
37  * Resends the password
38  *
39  * @package    WiFiDogAuthServer
40  * @author     Philippe April
41  * @author     Benoit Grégoire <bock@step.polymtl.ca>
42  * @author     Max Horvath <max.horvath@maxspot.de>
43  * @copyright  2004-2006 Philippe April
44  * @copyright  2004-2006 Benoit Grégoire, Technologies Coeus inc.
45  * @copyright  2006 Max Horvath, maxspot GmbH
46  * @version    Subversion $Id: lost_password.php 1031 2006-05-10 18:56:02Z benoitg $
47  * @link       http://www.wifidog.org/
48  */
49
50 /**
51  * Load required files
52  */
53 require_once(dirname(__FILE__) . '/include/common.php');
54
55 require_once('include/common_interface.php');
56 require_once('classes/User.php');
57 require_once('classes/MainUI.php');
58
59 /**
60  * Process recovering username
61  */
62
63 // Init ALL smarty SWITCH values
64 $smarty->assign('sectionTOOLCONTENT', false);
65 $smarty->assign('sectionMAINCONTENT', false);
66
67 // Init ALL smarty values
68 $smarty->assign('message', "");
69 $smarty->assign('error', "");
70 $smarty->assign('auth_sources', "");
71 $smarty->assign('selected_auth_source', "");
72 $smarty->assign('SelectNetworkUI', "");
73
74 $smarty->assign('username', "");
75 $smarty->assign('email', "");
76
77 if (isset($_REQUEST['form_request'])) {
78     $account_origin = Network::getObject($_REQUEST['auth_source']);
79
80     try {
81         /*
82          * Tool content
83          */
84
85         // Set section of Smarty template
86         $smarty->assign('sectionTOOLCONTENT', true);
87
88         // Compile HTML code
89         $html = $smarty->fetch("templates/sites/lost_password.tpl");
90
91         /*
92          * Main content
93          */
94
95         // Reset ALL smarty SWITCH values
96         $smarty->assign('sectionTOOLCONTENT', false);
97         $smarty->assign('sectionMAINCONTENT', false);
98
99         // Set section of Smarty template
100         $smarty->assign('sectionMAINCONTENT', true);
101
102         if (empty($account_origin)) {
103             throw new Exception(_("Sorry, this network does not exist !"));
104         }
105
106         if (!$_REQUEST['username'] && !$_REQUEST['email']) {
107             throw new Exception(_("Please specify a username or email address"));
108         }
109
110         $username = $db->escapeString($_REQUEST['username']);
111         $email = $db->escapeString($_REQUEST['email']);
112
113         /*
114          * Get a list of users associated with either a username of an e-mail
115          */
116         if ($username) {
117             $user = User::getUserByUsernameAndOrigin($username, $account_origin);
118         }
119
120         if ($email) {
121             $user = User::getUserByEmailAndOrigin($email, $account_origin);
122         }
123
124         /*
125          * In case that both previous function calls failed to return a users
126          * list throw an exception
127          */
128         if ($user != null) {
129             $user->sendLostPasswordEmail();
130         } else {
131             throw new Exception(_("This username or email could not be found in our database"));
132         }
133
134         $smarty->assign('message', _('A new password has been emailed to you.'));
135
136         // Compile HTML code
137         $html_body = $smarty->fetch("templates/sites/validate.tpl");
138
139         /*
140          * Render output
141          */
142         $ui = new MainUI();
143         $ui->addContent('left_area_middle', $html);
144         $ui->addContent('main_area_middle', $html_body);
145         $ui->display();
146
147         // We're done ...
148         exit;
149     } catch (Exception $e) {
150         $smarty->assign("error", $e->getMessage());
151
152         // Reset HTML output
153         $html = "";
154         $html_body = "";
155
156         // Reset ALL smarty SWITCH values
157         $smarty->assign('sectionTOOLCONTENT', false);
158         $smarty->assign('sectionMAINCONTENT', false);
159     }
160 }
161
162 /*
163  * Tool content
164  */
165
166 // Set section of Smarty template
167 $smarty->assign('sectionTOOLCONTENT', true);
168
169 // Compile HTML code
170 $html = $smarty->fetch("templates/sites/lost_password.tpl");
171
172 /*
173  * Main content
174  */
175
176 // Reset ALL smarty SWITCH values
177 $smarty->assign('sectionTOOLCONTENT', false);
178 $smarty->assign('sectionMAINCONTENT', false);
179
180 // Set section of Smarty template
181 $smarty->assign('sectionMAINCONTENT', true);
182
183 // Add the auth servers list to smarty variables
184 $sources = array();
185
186 // Preserve keys
187 $network_array=Network::getAllNetworks();
188
189 foreach ($network_array as $network) {
190     if ($network->getAuthenticator()->isRegistrationPermitted()) {
191         $sources[$network->getId()] = $network->getName();
192     }
193 }
194
195 if (isset($sources)) {
196     $smarty->assign('auth_sources', $sources);
197 }
198
199 // Pass the account_origin along, if it's set
200 if (isset($_REQUEST["auth_source"])) {
201     $smarty->assign('selected_auth_source', $_REQUEST["auth_source"]);
202 }
203
204 $smarty->assign('SelectNetworkUI', Network::getSelectNetworkUI('auth_source'));
205
206 // Compile HTML code
207 $html_body = $smarty->fetch("templates/sites/lost_password.tpl");
208
209 /*
210  * Render output
211  */
212 $ui = new MainUI();
213 $ui->addContent('left_area_middle', $html);
214 $ui->addContent('main_area_middle', $html_body);
215 $ui->display();
216
217 /*
218  * Local variables:
219  * tab-width: 4
220  * c-basic-offset: 4
221  * c-hanging-comment-ender-p: nil
222  * End:
223  */
224
225 ?>
226
Note: See TracBrowser for help on using the browser.