| [ Index ] |
|
Code source de Claroline 188 |
1 <?php // $Id: lostPassword.php,v 1.45 2006/12/15 14:11:29 moosh Exp $ 2 /** 3 * CLAROLINE 4 * 5 * This script allows users to retrieve the password of their profile(s) 6 * on the basis of their e-mail address. The password is send via email 7 * to the user. 8 * 9 * Special case : If the password are encrypted in the database, we have 10 * to generate a new one. 11 * 12 * @version 1.8 $Revision: 1.45 $ 13 * 14 * @copyright (c) 2001-2006 Universite catholique de Louvain (UCL) 15 * 16 * @license http://www.gnu.org/copyleft/gpl.html (GPL) GENERAL PUBLIC LICENSE 17 * 18 * @package CLAUTH 19 * 20 * @author Claro Team <cvs@claroline.net> 21 */ 22 23 require '../inc/claro_init_global.inc.php'; 24 25 $nameTools = get_lang('Lost password'); 26 27 // DB tables definition 28 $tbl_mdb_names = claro_sql_get_main_tbl(); 29 $tbl_user = $tbl_mdb_names['user']; 30 31 // library for authentification and mail 32 include_once(get_path('incRepositorySys') . '/lib/user.lib.php'); 33 include_once(get_path('incRepositorySys') . '/lib/sendmail.lib.php'); 34 35 // Initialise variables 36 37 $msg = ''; 38 $extAuthPasswordCount = 0; 39 $passwordFound = false; 40 $userAccountList = array(); 41 42 // Get the forgotten email from the form 43 44 if ( isset ($_REQUEST['Femail']) ) $emailTo = strtolower(trim($_REQUEST['Femail'])); 45 else $emailTo = ''; 46 47 // Main section 48 49 if ( isset($_REQUEST['searchPassword']) && !empty($emailTo) ) 50 { 51 // search user with this email 52 53 $sql = "SELECT `user_id` `uid` , 54 `nom` `lastName` , 55 `prenom` `firstName` , 56 `username` `loginName` , 57 `password` , 58 `email` , 59 `authSource` , 60 `creatorId` 61 FROM `" . $tbl_user . "` 62 WHERE LOWER(email) = '" . addslashes($emailTo) . "'"; 63 64 $userList = claro_sql_query_fetch_all($sql); 65 66 if ( count($userList) > 0 ) 67 { 68 foreach ( $userList as $user ) 69 { 70 if ( in_array(strtolower($user['authSource']), 71 array('claroline', 'clarocrypt'))) 72 { 73 $passwordFound = true; 74 75 if (get_conf('userPasswordCrypted',false)) 76 { 77 /* 78 * If password are crypted, we can not send them as such. 79 * We have to generate new ones. 80 */ 81 82 $user['password'] = generate_passwd(); 83 84 // UPDATE THE DB WITH THE NEW GENERATED PASSWORD 85 86 $sql = 'UPDATE `' . $tbl_user . '` 87 SET `password` = "'. addslashes(md5($user['password'])) .'" 88 WHERE `user_id` = "'.$user['uid'].'"'; 89 90 if ( claro_sql_query($sql) === false ) 91 { 92 trigger_error('<p align="center">'. get_lang('Wrong operation') . '</p>', E_USER_ERROR); 93 } 94 } 95 96 // Build user account list for email 97 $userAccountList[] = 98 $user['firstName'] .' ' . $user['lastName'] . "\r\n\r\n" 99 . "\t" . get_lang('Username') . ' : ' . $user['loginName'] . "\r\n" 100 . "\t" . get_lang('Password') . ' : ' . $user['password'] . " \r\n" ; 101 102 } 103 else 104 { 105 $extAuthPasswordCount ++; 106 } 107 } 108 109 if ( $passwordFound ) 110 { 111 112 /* 113 * Prepare the email message wich has to be send to the user 114 */ 115 116 // mail subject 117 $emailSubject = get_lang('Login request') . ' ' . get_conf('siteName'); 118 119 $emailBody = $emailSubject."\r\n" 120 .get_path('rootWeb')."\r\n" 121 .get_lang('This is your account Login-Pass')."\r\n\r\n" ; 122 123 // mail body 124 if ( count($userAccountList) > 0 ) 125 { 126 $emailBody .= implode ("\r\n\r\n", $userAccountList); 127 } 128 129 // send message 130 if( claro_mail_user($userList[0]['uid'], $emailBody, $emailSubject) ) 131 { 132 $msg = get_lang('Your password has been emailed to'). ' : ' . $emailTo; 133 } 134 else 135 { 136 $msg = get_lang('The system is unable to send you an e-mail.') . '<br />' 137 . get_lang('Please contact') . ' : ' 138 . '<a href="mailto:' . get_conf('administrator_email') . '?BODY=' . $emailTo . '">' 139 . get_lang('Platform Administrator') 140 . '</a>'; 141 } 142 } 143 } 144 else 145 { 146 $msg = '<p>' . get_lang('There is no user account with this email address.') . '</p>'; 147 } 148 149 if ($extAuthPasswordCount > 0 ) 150 { 151 if ( $extAuthPasswordCount == count($userList) ) 152 { 153 $msg .= '<p>' 154 . get_lang('Your password(s) is (are) recorded in an external authentication system outside the platform.') . '<br />' 155 . get_lang('For more information take contact with the platform administrator.') 156 . '</p>'; 157 } 158 else 159 { 160 $msg .= '<p>' 161 . get_lang('Passwords of some of your user account(s) are recorded an in external authentication system outside the platform.') . '<br />' 162 . get_lang('For more information take contact with the platform administrator.') 163 . '</p>'; 164 } 165 } 166 } 167 else 168 { 169 $msg = '<p>' . get_lang('Enter your email so we can send you your password.') . '</p>'; 170 } 171 172 173 //////////////////////////////////////////////////// 174 // display section 175 176 include get_path('incRepositorySys') . '/claro_init_header.inc.php'; 177 178 // display title 179 180 echo claro_html_tool_title($nameTools); 181 182 // display message box 183 184 if ( ! $passwordFound ) 185 { 186 $msg .= '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">' 187 . '<input type="hidden" name="searchPassword" value="1" />' 188 . '<label for="Femail">' . get_lang('Email') . ' : </label>' 189 . '<br />' 190 . '<input type="text" name="Femail" id="Femail" size="50" maxlength="100" value="' . htmlspecialchars($emailTo) . '" />' 191 . '<br /><br />' 192 . '<input type="submit" name="retrieve" value="' . get_lang('Ok') . '" /> ' 193 . claro_html_button(get_conf('urlAppend') . '/index.php', get_lang('Cancel')) 194 . '</form>' 195 ; 196 } 197 198 if ( ! empty($msg) ) echo claro_html_message_box($msg); 199 200 // display form 201 202 include get_path('incRepositorySys') . '/claro_init_footer.inc.php'; 203 204 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Thu Nov 29 14:38:42 2007 | par Balluche grâce à PHPXref 0.7 |
|