| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |  * StatusNet - the distributed open-source microblogging tool | 
					
						
							|  |  |  |  * Copyright (C) 2011, StatusNet, Inc. | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |  * Register a user by their email address | 
					
						
							|  |  |  |  *  | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |  * PHP version 5 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU Affero General Public License as published by | 
					
						
							|  |  |  |  * the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  |  * (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU Affero General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @category  Email registration | 
					
						
							|  |  |  |  * @package   StatusNet | 
					
						
							|  |  |  |  * @author    Evan Prodromou <evan@status.net> | 
					
						
							|  |  |  |  * @copyright 2011 StatusNet, Inc. | 
					
						
							|  |  |  |  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 | 
					
						
							|  |  |  |  * @link      http://status.net/ | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (!defined('STATUSNET')) { | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |     // This check helps protect against security problems;
 | 
					
						
							|  |  |  |     // your code file can't be executed directly from the web.
 | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |     exit(1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |  * Email registration | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |  * There are four cases where we're called: | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |  * 1. GET, no arguments. Initial registration; ask for an email address.   | 
					
						
							|  |  |  |  * 2. POST, email address argument. Initial registration; send an email to confirm. | 
					
						
							|  |  |  |  * 3. GET, code argument. Confirming an invitation or a registration; look them up, | 
					
						
							|  |  |  |  *    create the relevant user if possible, login as that user, and  | 
					
						
							|  |  |  |  *    show a password-entry form. | 
					
						
							|  |  |  |  * 4. POST, password argument. After confirmation, set the password for the new | 
					
						
							|  |  |  |  *    user, and redirect to a registration complete action with some instructions. | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |  * @category  Action | 
					
						
							|  |  |  |  * @package   StatusNet | 
					
						
							|  |  |  |  * @author    Evan Prodromou <evan@status.net> | 
					
						
							|  |  |  |  * @copyright 2011 StatusNet, Inc. | 
					
						
							|  |  |  |  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 | 
					
						
							|  |  |  |  * @link      http://status.net/ | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | class EmailregisterAction extends Action | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |     const NEWEMAIL = 1; | 
					
						
							|  |  |  |     const SETPASSWORD = 2; | 
					
						
							|  |  |  |     const NEWREGISTER = 3; | 
					
						
							|  |  |  |     const CONFIRMINVITE = 4; | 
					
						
							|  |  |  |     const CONFIRMREGISTER = 5; | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |     const CONFIRMTYPE = 'register'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     protected $user; | 
					
						
							|  |  |  |     protected $email; | 
					
						
							|  |  |  |     protected $code; | 
					
						
							|  |  |  |     protected $invitation; | 
					
						
							|  |  |  |     protected $confirmation; | 
					
						
							|  |  |  |     protected $password1; | 
					
						
							|  |  |  |     protected $password2; | 
					
						
							|  |  |  |     protected $state; | 
					
						
							|  |  |  |     protected $error; | 
					
						
							| 
									
										
										
										
											2011-04-18 06:07:32 -04:00
										 |  |  |     protected $complete; | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     function prepare($argarray) | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |         parent::prepare($argarray); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ($this->isPost()) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $this->checkSessionToken(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $this->email = $this->trimmed('email'); | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |             if (!empty($this->email)) { | 
					
						
							|  |  |  |                 $this->email = common_canonical_email($this->email); | 
					
						
							|  |  |  |                 $this->state = self::NEWEMAIL; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $this->state = self::SETPASSWORD; | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |                 $this->code = $this->trimmed('code'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (empty($this->code)) { | 
					
						
							|  |  |  |                     throw new ClientException(_('No confirmation code.')); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 $this->invitation = Invitation::staticGet('code', $this->code); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-18 06:07:32 -04:00
										 |  |  |                 if (empty($this->invitation)) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |                     $this->confirmation = Confirm_address::staticGet('code', $this->code); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     if (empty($this->confirmation)) { | 
					
						
							| 
									
										
										
										
											2011-04-18 06:07:32 -04:00
										 |  |  |                         throw new ClientException(_('No such confirmation code.'), 403); | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 $this->password1 = $this->trimmed('password1'); | 
					
						
							|  |  |  |                 $this->password2 = $this->trimmed('password2'); | 
					
						
							|  |  |  |                  | 
					
						
							|  |  |  |                 $this->tos = $this->boolean('tos'); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else { // GET
 | 
					
						
							|  |  |  |             $this->code = $this->trimmed('code'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (empty($this->code)) { | 
					
						
							|  |  |  |                 $this->state = self::NEWREGISTER; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $this->invitation = Invitation::staticGet('code', $this->code); | 
					
						
							|  |  |  |                 if (!empty($this->invitation)) { | 
					
						
							|  |  |  |                     $this->state = self::CONFIRMINVITE; | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     $this->state = self::CONFIRMREGISTER; | 
					
						
							|  |  |  |                     $this->confirmation = Confirm_address::staticGet('code', $this->code); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     if (empty($this->confirmation)) { | 
					
						
							|  |  |  |                         throw new ClientException(_('No such confirmation code.'), 405); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |     function title() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         switch ($this->state) { | 
					
						
							|  |  |  |         case self::NEWREGISTER: | 
					
						
							|  |  |  |         case self::NEWEMAIL: | 
					
						
							|  |  |  |             // TRANS: Title for registration page.
 | 
					
						
							|  |  |  |             return _m('TITLE','Register'); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case self::SETPASSWORD: | 
					
						
							|  |  |  |         case self::CONFIRMINVITE: | 
					
						
							|  |  |  |         case self::CONFIRMREGISTER: | 
					
						
							|  |  |  |             // TRANS: Title for page where to change password.
 | 
					
						
							| 
									
										
										
										
											2011-04-17 19:24:33 -04:00
										 |  |  |             return _m('TITLE','Complete registration'); | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |      * Handler method | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |      * @param array $argarray is ignored since it's now passed in in prepare() | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     function handle($argarray=null) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         switch ($this->state) { | 
					
						
							|  |  |  |         case self::NEWREGISTER: | 
					
						
							|  |  |  |             $this->showRegistrationForm(); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case self::NEWEMAIL: | 
					
						
							|  |  |  |             $this->registerUser(); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case self::CONFIRMINVITE: | 
					
						
							| 
									
										
										
										
											2011-04-17 19:24:33 -04:00
										 |  |  |             $this->confirmRegistration(); | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case self::CONFIRMREGISTER: | 
					
						
							| 
									
										
										
										
											2011-04-17 19:24:33 -04:00
										 |  |  |             $this->confirmRegistration(); | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case self::SETPASSWORD: | 
					
						
							|  |  |  |             $this->setPassword(); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function showRegistrationForm() | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |         $this->form = new EmailRegistrationForm($this, $this->email); | 
					
						
							|  |  |  |         $this->showPage(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function registerUser() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $old = User::staticGet('email', $this->email); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!empty($old)) { | 
					
						
							|  |  |  |             $this->error = sprintf(_('A user with that email address already exists. You can use the '. | 
					
						
							|  |  |  |                                      '<a href="%s">password recovery</a> tool to recover a missing password.'), | 
					
						
							|  |  |  |                                    common_local_url('recoverpassword')); | 
					
						
							|  |  |  |             $this->showRegistrationForm(); | 
					
						
							| 
									
										
										
										
											2011-04-17 18:30:25 -04:00
										 |  |  |             return; | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $valid = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (Event::handle('StartValidateUserEmail', array(null, $this->email, &$valid))) { | 
					
						
							|  |  |  |             $valid = Validate::email($this->email, common_config('email', 'check_domain')); | 
					
						
							|  |  |  |             Event::handle('EndValidateUserEmail', array(null, $this->email, &$valid)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!$valid) { | 
					
						
							|  |  |  |             $this->error = _('Not a valid email address.'); | 
					
						
							|  |  |  |             $this->showRegistrationForm(); | 
					
						
							| 
									
										
										
										
											2011-04-17 18:30:25 -04:00
										 |  |  |             return; | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $confirm = Confirm_address::getAddress($this->email, self::CONFIRMTYPE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (empty($confirm)) { | 
					
						
							|  |  |  |             $confirm = Confirm_address::saveNew(null, $this->email, 'register'); | 
					
						
							|  |  |  |             $prompt = sprintf(_('An email was sent to %s to confirm that address. Check your email inbox for instructions.'), | 
					
						
							|  |  |  |                               $this->email); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $prompt = sprintf(_('The address %s was already registered but not confirmed. The confirmation code was resent.'), | 
					
						
							|  |  |  |                               $this->email); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |         $this->sendConfirmEmail($confirm); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->complete = $prompt; | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |         $this->showPage(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-17 19:24:33 -04:00
										 |  |  |     function confirmRegistration() | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-04-17 19:28:22 -04:00
										 |  |  |         if (!empty($this->invitation)) { | 
					
						
							|  |  |  |             $email = $this->invitation->address; | 
					
						
							|  |  |  |         } else if (!empty($this->confirmation)) { | 
					
						
							|  |  |  |             $email = $this->confirmation->address; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |         $nickname = $this->nicknameFromEmail($email); | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-17 19:24:33 -04:00
										 |  |  |         $this->form = new ConfirmRegistrationForm($this, | 
					
						
							|  |  |  |                                                   $nickname, | 
					
						
							| 
									
										
										
										
											2011-04-17 19:28:22 -04:00
										 |  |  |                                                   $email, | 
					
						
							| 
									
										
										
										
											2011-04-18 06:07:32 -04:00
										 |  |  |                                                   $this->code); | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |         $this->showPage(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function setPassword() | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |         if (!empty($this->invitation)) { | 
					
						
							|  |  |  |             $email = $this->invitation->address; | 
					
						
							|  |  |  |         } else if (!empty($this->confirmation)) { | 
					
						
							|  |  |  |             $email = $this->confirmation->address; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             throw new Exception('No confirmation thing.'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-17 19:29:55 -04:00
										 |  |  |         if (!$this->tos) { | 
					
						
							|  |  |  |             $this->error = _('You must accept the terms of service and privacy policy to register.'); | 
					
						
							|  |  |  |             $nickname = $this->nicknameFromEmail($email); | 
					
						
							|  |  |  |             $this->form = new ConfirmRegistrationForm($this, $nickname, $this->email, $this->code); | 
					
						
							|  |  |  |             $this->showPage(); | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |         $nickname = $this->nicknameFromEmail($email); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-18 06:07:32 -04:00
										 |  |  |         $this->user = User::register(array('nickname' => $nickname, | 
					
						
							|  |  |  |                                            'email' => $email, | 
					
						
							|  |  |  |                                            'email_confirmed' => true)); | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |         if (empty($this->user)) { | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |             throw new Exception("Failed to register user."); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!empty($this->invitation)) { | 
					
						
							|  |  |  |             $inviter = User::staticGet('id', $this->invitation->user_id); | 
					
						
							|  |  |  |             if (!empty($inviter)) { | 
					
						
							|  |  |  |                 Subscription::start($inviter->getProfile(), | 
					
						
							|  |  |  |                                     $user->getProfile()); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $this->invitation->delete(); | 
					
						
							|  |  |  |         } else if (!empty($this->confirmation)) { | 
					
						
							|  |  |  |             $this->confirmation->delete(); | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |             throw new Exception('No confirmation thing.'); | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-18 06:07:32 -04:00
										 |  |  |         common_redirect(common_local_url('doc', array('title' => 'welcome')), | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |                         303); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-17 18:48:58 -04:00
										 |  |  |     function sendConfirmEmail($confirm) | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |     { | 
					
						
							|  |  |  |         $sitename = common_config('site', 'name'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $recipients = array($confirm->address); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $headers['From'] = mail_notify_from(); | 
					
						
							|  |  |  |         $headers['To'] = trim($confirm->address); | 
					
						
							|  |  |  |         $headers['Subject'] = sprintf(_('Confirm your registration on %1$s'), $sitename); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-18 06:07:32 -04:00
										 |  |  |         $confirmUrl = common_local_url('register', array('code' => $confirm->code)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         common_debug('Confirm URL is ' . $confirmUrl); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |         $body = sprintf(_('Someone (probably you) has requested an account on %1$s using this email address.'. | 
					
						
							|  |  |  |                           "\n". | 
					
						
							|  |  |  |                           'To confirm the address, click the following URL or copy it into the address bar of your browser.'. | 
					
						
							|  |  |  |                           "\n". | 
					
						
							|  |  |  |                           '%2$s'. | 
					
						
							|  |  |  |                           "\n". | 
					
						
							|  |  |  |                           'If it was not you, you can safely ignore this message.'), | 
					
						
							|  |  |  |                         $sitename, | 
					
						
							| 
									
										
										
										
											2011-04-18 06:07:32 -04:00
										 |  |  |                         $confirmUrl); | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         mail_send($recipients, $headers, $body); | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function showContent() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |         if ($this->complete) { | 
					
						
							|  |  |  |             $this->elementStart('p', 'success'); | 
					
						
							|  |  |  |             $this->raw($this->complete); | 
					
						
							|  |  |  |             $this->elementEnd('p'); | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |             if ($this->error) { | 
					
						
							|  |  |  |                 $this->elementStart('p', 'error'); | 
					
						
							|  |  |  |                 $this->raw($this->error); | 
					
						
							|  |  |  |                 $this->elementEnd('p'); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (!empty($this->form)) { | 
					
						
							|  |  |  |                 $this->form->show(); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Return true if read only. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |      * MAY override | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  |      * @param array $args other arguments | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return boolean is read only action? | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2011-04-17 17:48:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  |     function isReadOnly($args) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-04-17 19:24:33 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     function nicknameFromEmail($email) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $parts = explode('@', $email); | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |         $nickname = $parts[0]; | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2011-04-17 19:29:55 -04:00
										 |  |  |         $nickname = preg_replace('/[^A-Za-z0-9]/', '', $nickname); | 
					
						
							| 
									
										
										
										
											2011-04-17 19:24:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-17 19:28:22 -04:00
										 |  |  |         $nickname = Nickname::normalize($nickname); | 
					
						
							| 
									
										
										
										
											2011-04-17 19:24:33 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $original = $nickname; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $n = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         while (User::staticGet('nickname', $nickname)) { | 
					
						
							|  |  |  |             $n++; | 
					
						
							|  |  |  |             $nickname = $original . $n; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $nickname; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-04-17 13:22:21 -04:00
										 |  |  | } |