[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare - Registration * 4 * http://www.eGroupWare.org * 5 * This application written by Joseph Engo <jengo@phpgroupware.org> * 6 * Modified by Jason Wies (Zone) <zone@users.sourceforge.net> * 7 * Modified by Loic Dachary <loic@gnu.org> * 8 * Modified by Pim Snel <pim@egroupware.org> * 9 * -------------------------------------------- * 10 * Funding for this program was provided by http://www.checkwithmom.com * 11 * -------------------------------------------- * 12 * This program is free software; you can redistribute it and/or modify it * 13 * under the terms of the GNU General Public License as published by the * 14 * Free Software Foundation; either version 2 of the License, or (at your * 15 * option) any later version. * 16 \**************************************************************************/ 17 18 /* $Id: class.soreg.inc.php 20049 2005-11-29 12:08:25Z nelius_weiss $ */ 19 20 class soreg 21 { 22 var $reg_id; 23 var $db; 24 var $reg_table = 'egw_reg_accounts'; 25 26 function soreg() 27 { 28 $this->db = clone($GLOBALS['egw']->db); 29 $this->db->app = 'registration'; 30 } 31 32 function account_exists($account_lid) 33 { 34 $this->db->select($this->reg_table,'reg_dla',array( 35 'reg_lid' => $account_lid, 36 ),__LINE__,__FILE__); 37 $this->db->next_record(); 38 39 // echo (time()-$this->db->f(0)); 40 // echo "<br>"; 41 // echo time(); 42 43 if ( $GLOBALS['egw']->accounts->exists($account_lid) || ( $this->db->f(0) && (time()-$this->db->f(0))<1800 )) 44 { 45 return True; 46 } 47 else 48 { 49 // To prevent race conditions, reserve the account_lid 50 $this->db->insert($this->reg_table,array( 51 'reg_id' => '', 52 'reg_lid' => $account_lid, 53 'reg_info' => '', 54 'reg_dla' => time(), 55 ),false,__LINE__,__FILE__); 56 $GLOBALS['egw']->session->appsession('loginid','registration',$account_lid); 57 return False; 58 } 59 } 60 61 function step2($fields,$send_mail=True) 62 { 63 global $config; 64 $smtp =& CreateObject('phpgwapi.send'); 65 66 // We are not going to use link(), because we may not have the same sessionid by that time 67 // If we do, it will not affect it 68 $url = ($_SERVER['HTTPS'] ? 'https://' : 'http://').$GLOBALS['egw_info']['server']['hostname'] . $GLOBALS['egw_info']['server']['webserver_url']. "/registration/index.php"; 69 70 $account_lid = $GLOBALS['egw']->session->appsession('loginid','registration'); 71 $this->reg_id = md5(time() . $account_lid . $GLOBALS['egw']->common->randomstring(32)); 72 73 $this->db->update($this->reg_table,array( 74 'reg_id' => $this->reg_id, 75 'reg_dla' => time(), 76 'reg_info' => base64_encode(serialize($fields)) 77 ),array( 78 'reg_lid' => $account_lid, 79 ),__LINE__,__FILE__); 80 81 $GLOBALS['egw']->template->set_file(array( 82 'message' => 'confirm_email.tpl' 83 )); 84 85 $GLOBALS['egw']->template->set_var('Hi',lang('Hi')); 86 $GLOBALS['egw']->template->set_var('message1',lang('This is a confirmation email for your new account. Click on the following link to finish activating your account. This link will expire in 2 hours.')); 87 88 $GLOBALS['egw']->template->set_var('message2',lang('If you did not request this account, simply ignore this message.')); 89 90 if ($fields['n_given']) 91 { 92 $GLOBALS['egw']->template->set_var ('firstname', $fields['n_given'] . ' '); 93 } 94 95 if ($fields['n_family']) 96 { 97 $GLOBALS['egw']->template->set_var ('lastname', $fields['n_family']); 98 } 99 100 $GLOBALS['egw']->template->set_var ('activate_url',$url . '?menuaction=registration.boreg.step4®_id='. $this->reg_id); 101 102 if ($config['support_email']) 103 { 104 $GLOBALS['egw']->template->set_var ('support_email_text', lang ('Report all problems and abuse to')); 105 $GLOBALS['egw']->template->set_var ('support_email', $config['support_email']); 106 } 107 108 $subject = $config['subject_confirm'] ? lang($config['subject_confirm']) : lang('Account registration'); 109 $noreply = $config['mail_nobody'] ? ('No reply <' . $config['mail_nobody'] . '>') : ('No reply <noreply@' . $_SERVER['SERVER_NAME'] . '>'); 110 111 if ($send_mail) 112 { 113 $ret = $smtp->msg('email',$fields['email'],$subject,$GLOBALS['egw']->template->fp('out','message'),'','','',$noreply); 114 if ($ret != True) 115 { 116 print(lang("Problem Sending Email:").$smtp->desc) ; 117 print(lang("<br>Please Contact the site administrator.")) ; 118 exit() ; 119 } 120 } 121 return $this->reg_id; 122 } 123 124 // 125 // username 126 // 127 function lostpw1($account_lid) 128 { 129 global $config; 130 131 $url = ($_SERVER['HTTPS'] ? 'https://' : 'http://').$GLOBALS['egw_info']['server']['hostname'] . $GLOBALS['egw_info']['server']['webserver_url']. "/registration/index.php"; 132 133 $error = ''; 134 135 // 136 // Remember md5 string sent by mail 137 // 138 $reg_id = md5(time() . $account_lid . $GLOBALS['egw']->common->randomstring(32)); 139 $this->db->insert($this->reg_table,array( 140 'reg_id' => $reg_id, 141 'reg_lid' => $account_lid, 142 'reg_info' => '', 143 'reg_dla' => time(), 144 ),false,__LINE__,__FILE__); 145 146 // 147 // Send the mail that will allow to change the password 148 // 149 $account_id = $GLOBALS['egw']->accounts->name2id($account_lid); 150 151 if ($account_id) 152 { 153 $info = array( 154 'firstname' => $GLOBALS['egw']->accounts->id2name($account_id,'account_firstname'), 155 'lastname' => $GLOBALS['egw']->accounts->id2name($account_id,'account_lastname'), 156 'email' => $GLOBALS['egw']->accounts->id2name($account_id,'account_email'), 157 ); 158 $smtp =& CreateObject('phpgwapi.send'); 159 160 $GLOBALS['egw']->template->set_file(array( 161 'message' => 'lostpw_email.tpl' 162 )); 163 164 $GLOBALS['egw']->template->set_var('hi',lang('Hi')); 165 $GLOBALS['egw']->template->set_var('message1',lang('You requested to change your password. Please follow the URL below to do so. This URL will expire in two hours. After this delay you should go thru the lost password procedure again.')); 166 167 $GLOBALS['egw']->template->set_var('message2',lang('If you did not request this change, simply ignore this message.')); 168 169 $GLOBALS['egw']->template->set_var('firstname',$info['firstname']); 170 $GLOBALS['egw']->template->set_var('lastname',$info['lastname']); 171 $GLOBALS['egw']->template->set_var('activate_url',$url . '?menuaction=registration.boreg.lostpw2®_id=' . $reg_id); 172 173 $subject = $config['subject_lostpw'] ? lang($config['subject_lostpw']) : lang('Account password retrieval'); 174 $noreply = $config['mail_nobody'] ? ('No reply <' . $config['mail_nobody'] . '>') : ('No reply <noreply@' . $_SERVER['SERVER_NAME'] . '>'); 175 176 $ret = $smtp->msg('email',$info['email'],$subject,$GLOBALS['egw']->template->fp('out','message'),'','','',$noreply); 177 if ($ret != True) 178 { 179 print(lang("Problem Sending Email:").$smtp->desc) ; 180 print(lang("<br>Please Contact the site administrator.")) ; 181 exit() ; 182 } 183 } 184 else 185 { 186 $error = lang("Account $account_lid record could not be found, report to site administrator"); 187 } 188 189 return $error; 190 } 191 192 // 193 // link sent by mail 194 // 195 function lostpw2($account_lid) 196 { 197 $account_id = $GLOBALS['egw']->accounts->name2id($account_lid); 198 199 $GLOBALS['egw']->session->appsession('loginid','registration',$account_lid); 200 $GLOBALS['egw']->session->appsession('id','registration',$account_id); 201 } 202 203 // 204 // new password 205 // 206 function lostpw3($account_lid, $passwd) 207 { 208 $auth =& CreateObject('phpgwapi.auth'); 209 $auth->change_password(false, $passwd, $GLOBALS['egw']->session->appsession('id','registration')); 210 211 $this->db->delete($this->reg_table,array('reg_lid' => $account_lid),__LINE__,__FILE__); 212 } 213 214 function valid_reg($reg_id) 215 { 216 $this->db->select($this->reg_table,'*',array('reg_id' => $reg_id),__LINE__,__FILE__); 217 218 if (!$this->db->next_record()) return false; 219 220 return array( 221 'reg_id' => $this->db->f('reg_id'), 222 'reg_lid' => $this->db->f('reg_lid'), 223 'reg_info' => $this->db->f('reg_info'), 224 'reg_dla' => $this->db->f('reg_dla') 225 ); 226 } 227 228 function delete_reg_info($reg_id) 229 { 230 $this->db->delete($this->reg_table,array('reg_id' => $reg_id),__LINE__,__FILE__); 231 } 232 233 function create_account($account_lid,$_reg_info) 234 { 235 global $config, $reg_info; 236 237 $fields = unserialize(base64_decode($_reg_info)); 238 $fields['lid'] = "*$account_lid*"; 239 //$fields['lid'] = $account_lid; 240 241 $reg_info['lid'] = $account_lid; 242 $reg_info['fields'] = $fields; 243 244 $GLOBALS['auto_create_acct'] = array( 245 'firstname' => $fields['n_given'], 246 'lastname' => $fields['n_family'], 247 'email' => $fields['email'], 248 ); 249 $account_id = $GLOBALS['egw_info']['user']['account_id'] = $GLOBALS['egw']->accounts->auto_add($account_lid,$fields['passwd'],True,False,0,'A'); 250 251 if (!$account_id) 252 { 253 return False; 254 } 255 256 //var_dump($account_id); 257 $accounts =& CreateObject('phpgwapi.accounts',$account_id); 258 $contacts =& CreateObject('phpgwapi.contacts'); 259 260 $this->db->transaction_begin(); 261 262 $contact_fields = $fields; 263 264 if ($contact_fields['bday_day']) 265 { 266 $contact_fields['bday'] = $contact_fields['bday_month'] . '/' . $contact_fields['bday_day'] . '/' . $contact_fields['bday_year']; 267 } 268 269 /* There are certain things we don't want stored in contacts */ 270 unset ($contact_fields['passwd']); 271 unset ($contact_fields['passwd_confirm']); 272 unset ($contact_fields['bday_day']); 273 unset ($contact_fields['bday_month']); 274 unset ($contact_fields['bday_year']); 275 276 /* Don't store blank values either */ 277 foreach ($contact_fields as $num => $field) 278 { 279 if (!$contact_fields[$num]) 280 { 281 unset ($contact_fields[$num]); 282 } 283 } 284 285 //var_dump($contact_fields); 286 //echo "ac<P>"; 287 //die($account_id); 288 $contacts->add($account_id,$contact_fields,0,'P'); 289 290 $this->db->transaction_commit(); 291 292 $accounts->read_repository(); 293 if ($config['trial_accounts'] != "False") 294 { 295 $accounts->data['expires'] = time() + ((60 * 60) * ($config['days_until_trial_account_expires'] * 24)); 296 } 297 else 298 { 299 $accounts->data['expires'] = -1; 300 } 301 $accounts->save_repository(); 302 303 #if(@stat(EGW_SERVER_ROOT . '/messenger/inc/hook_registration.inc.php')) 304 #{ 305 # include(EGW_SERVER_ROOT . '/messenger/inc/hook_registration.inc.php'); 306 #} 307 } 308 309 function lostid1($email) 310 { 311 global $config; 312 313 $url = ($_SERVER['HTTPS'] ? 'https://' : 'http://').$GLOBALS['egw_info']['server']['hostname'] . $GLOBALS['egw_info']['server']['webserver_url']. "/registration/index.php"; 314 315 $error = ''; 316 317 $smtp =& CreateObject('phpgwapi.send'); 318 319 $GLOBALS['egw']->template->set_file(array('message' => 'lostid_email.tpl')); 320 321 $account_id = $GLOBALS['egw']->accounts->name2id($email,'account_email'); 322 $info = array( 323 'firstname' => $GLOBALS['egw']->accounts->id2name($account_id,'account_firstname'), 324 'lastname' => $GLOBALS['egw']->accounts->id2name($account_id,'account_lastname'), 325 'email' => $GLOBALS['egw']->accounts->id2name($account_id,'account_email'), 326 ); 327 if (is_null($info['firstname'])) 328 $info['firstname'] = lang('[Unknown first name]') ; 329 330 if (is_null($info['lastname'])) 331 $info['lastname'] = lang('[Unknown last name]') ; 332 333 $GLOBALS['egw']->template->set_var('hi',lang('Hi')); 334 $GLOBALS['egw']->template->set_var('firstname',$info['firstname']); 335 $GLOBALS['egw']->template->set_var('lastname',$info['lastname']); 336 $GLOBALS['egw']->template->set_var('message1', lang('lost_user_id_message')); 337 338 // Send the mail that tell the user id 339 $GLOBALS['egw']->template->set_var('lostids',$GLOBALS['egw']->accounts->id2name($account_id)); 340 341 $subject = $config['subject_lostid'] ? lang($config['subject_lostpid']) : lang('Lost user account retrieval'); 342 $noreply = $config['mail_nobody'] ? ('No reply <' . $config['mail_nobody'] . '>') : ('No reply <noreply@' . $_SERVER['SERVER_NAME'] . '>'); 343 344 // Debugging 345 //print('<PRE>') ; 346 //print_r($info) ; 347 //print_r($subject) ; 348 //print_r($noreply) ; 349 //print('</PRE>') ; 350 351 $ret = $smtp->msg('email',$info['email'],$subject,$GLOBALS['egw']->template->fp('out','message'),'','','',$noreply); 352 if ($ret != true) 353 { 354 print(lang("Problem Sending Email:").$smtp->desc) ; 355 print(lang("<br>Please Contact the site administrator.")) ; 356 exit() ; 357 } 358 return $error; 359 } 360 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |