[ Index ]

PHP Cross Reference of Mambo 4.6.5

[ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/components/com_registration/ -> registration.php (source)

   1  <?php
   2  /**
   3  * @package Mambo
   4  * @author Mambo Foundation Inc see README.php
   5  * @copyright (C) 2000 - 2009 Mambo Foundation Inc.
   6  * See COPYRIGHT.php for copyright notices and details.
   7  * @license GNU/GPL Version 2, see LICENSE.php
   8  *
   9  * Redistributions of files must retain the above copyright notice.
  10  *
  11  * Mambo is free software; you can redistribute it and/or
  12  * modify it under the terms of the GNU General Public License
  13  * as published by the Free Software Foundation; version 2 of the License.
  14  */
  15  
  16  /** ensure this file is being included by a parent file */
  17  defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  18  
  19  $task = mosGetParam( $_REQUEST, 'task', "" );
  20  require_once( $mainframe->getPath( 'front_html' ) );
  21  
  22  switch( $task ) {
  23      case "lostPassword":
  24      lostPassForm( $option );
  25      break;
  26  
  27      case "sendNewPass":
  28      sendNewPass( $option );
  29      break;
  30  
  31      case "register":
  32      case "reviseRegistration":
  33      registerForm( $option, $mosConfig_useractivation );
  34      break;
  35  
  36      case "confirmRegistration":
  37      confirmRegistration( $option );
  38      break;
  39  
  40      case "saveRegistration":
  41      saveRegistration( $option );
  42      break;
  43  
  44      case "activate":
  45      activate( $option );
  46      break;
  47  }
  48  
  49  function lostPassForm( $option ) {
  50      global $mainframe;
  51      $mainframe->SetPageTitle(T_('Lost your Password?'));
  52      HTML_registration::lostPassForm($option);
  53  }
  54  
  55  function sendNewPass( $option ) {
  56      global $database, $Itemid;
  57      global $mosConfig_live_site, $mosConfig_sitename, $mosConfig_fromname;
  58  
  59      $_live_site = $mosConfig_live_site;
  60      $_sitename = $mosConfig_sitename;
  61  
  62      // ensure no malicous sql gets past
  63      $checkusername = trim( mosGetParam( $_POST, 'checkusername', '') );
  64      $checkusername = $database->getEscaped( $checkusername );
  65      $confirmEmail = trim( mosGetParam( $_POST, 'confirmEmail', '') );
  66      $confirmEmail = $database->getEscaped( $confirmEmail );
  67  
  68      $database->setQuery( "SELECT id FROM #__users"
  69      . "\nWHERE username='$checkusername' AND email='$confirmEmail'"
  70      );
  71  
  72      if (!($user_id = $database->loadResult()) || !$checkusername || !$confirmEmail) {
  73          mosRedirect( "index.php?option=$option&task=lostPassword&mosmsg=".T_('Sorry, no corresponding user was found.  Please make sure you entered a valid username and a valid email address.  Both are required.') );
  74      }
  75  
  76      $database->setQuery( "SELECT name, email FROM #__users"
  77      . "\n WHERE usertype='super administrator'" );
  78      $rows = $database->loadObjectList();
  79      foreach ($rows AS $row) {
  80          $adminName = $row->name;
  81          $adminEmail = $row->email;
  82      }
  83  
  84      $rawpass = mosMakePassword();
  85      $message = sprintf(T_("The user account %s has this email associated with it.\n
  86  A web user from %s has just requested that a new password be sent.\n\n
  87  Your New Password is: %s\n\n
  88  If you didn't ask for this, don't worry. You are seeing this message, not them. 
  89  If this was an error just login with your new password and then change your password to what you would like it to be."),
  90                 $checkusername, $mosConfig_live_site, $rawpass);
  91      #eval ("\$message = \"$message\";");
  92      $subject = sprintf(T_('%s :: New password for - %s'),$_sitename, $checkusername);
  93      #eval ("\$subject = \"$subject\";");
  94  
  95      mosMail($mosConfig_mailfrom, $mosConfig_fromname, $confirmEmail, $subject, $message);
  96  
  97      $newpass = md5( $rawpass );
  98      $sql = "UPDATE #__users SET password='$newpass' WHERE id='$user_id'";
  99      $database->setQuery( $sql );
 100      if (!$database->query()) {
 101          die("SQL error" . $database->stderr(true));
 102      }
 103      $loginfo = new mosLoginDetails($checkusername, $rawpass);
 104      $mambothandler =& mosMambotHandler::getInstance();
 105      $mambothandler->loadBotGroup('authenticator');
 106      $mambothandler->trigger('userChange', array($loginfo));
 107  
 108      mosRedirect( "index.php?Itemid=$Itemid&mosmsg=".T_('New User Password created and sent!') );
 109  }
 110  
 111  function registerForm( $option, $useractivation ) {
 112      global $mainframe, $database, $my, $acl;
 113  
 114      if (!$mainframe->getCfg( 'allowUserRegistration' )) {
 115          mosNotAuth();
 116          return;
 117      }
 118  
 119    $mainframe->SetPageTitle(T_('Registration'));
 120      HTML_registration::registerForm($option, $useractivation);
 121  }
 122  
 123  
 124  function confirmRegistration ($option)
 125  {
 126  $name = trim( mosGetParam( $_REQUEST, 'name', "" ) );
 127  $username = trim( mosGetParam( $_REQUEST, 'username', "" ) );
 128  $password = trim( mosGetParam( $_REQUEST, 'password', "" ) );
 129  $email = trim( mosGetParam( $_REQUEST, 'email', "" ) );
 130  $useractivation = trim( mosGetParam( $_REQUEST, 'useractivation', "" ) );
 131      HTML_registration::confirmForm($option, $name, $username, $password, $email, $useractivation);
 132  }
 133  
 134  function saveRegistration( $option ) {
 135      global $database, $my, $acl;
 136      global $mosConfig_sitename, $mosConfig_live_site, $mosConfig_useractivation, $mosConfig_allowUserRegistration;
 137      global $mosConfig_mailfrom, $mosConfig_fromname, $mosConfig_mailfrom, $mosConfig_fromname;
 138  
 139      if ($mosConfig_allowUserRegistration=='0') {
 140          mosNotAuth();
 141          return;
 142      }
 143  
 144      $row = new mosUser( $database );
 145  
 146      if (!$row->bind( $_POST, 'usertype' )) {
 147          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 148          exit();
 149      }
 150  
 151      mosMakeHtmlSafe($row);
 152  
 153      $row->id = 0;
 154      $row->usertype = 'Registered';
 155      $row->gid = $acl->get_group_id( 'Registered', 'ARO' );
 156  
 157      if ($mosConfig_useractivation == '1') {
 158          $row->activation = md5( mosMakePassword() );
 159          $row->block = '1';
 160      }
 161  
 162      if (!$row->check()) {
 163          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 164          exit();
 165      }
 166  
 167      $pwd = $row->password;
 168      $row->password = md5( $row->password );
 169      $row->registerDate = date("Y-m-d H:i:s");
 170  
 171      if (!$row->store()) {
 172          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 173          exit();
 174      }
 175      $row->checkin();
 176  
 177      $name = $row->name;
 178      $email = $row->email;
 179      $username = $row->username;
 180  
 181      $subject = sprintf (T_('Account details for %s at %s'), $name, $mosConfig_sitename);
 182      $subject = html_entity_decode($subject, ENT_QUOTES);
 183      $mambothandler =& mosMambotHandler::getInstance();
 184      $mambothandler->loadBotGroup('authenticator');
 185      if ($mosConfig_useractivation=="1"){
 186          $message = sprintf (T_('Hello %s,
 187  
 188  Thank you for registering at %s. Your account has been created but, as a precaution, it must be activated by you before you can use it.
 189  To activate the account click on the following link or copy and paste it in your browser:
 190  %s
 191  
 192  After activation you may login to %s using the following username and password:
 193  
 194  Username - %s
 195  Password - %s'), 
 196                    $name, $mosConfig_sitename, $mosConfig_live_site."/index.php?option=com_registration&task=activate&activation=".$row->activation, $mosConfig_live_site, $username, $pwd);
 197          $loginfo = new mosLoginDetails($username, $pwd);
 198          $mambothandler->trigger('userRegister', array($loginfo));
 199      }
 200      else {
 201          $message = sprintf (T_("Hello %s,
 202  
 203  Thank you for registering at %s.
 204  
 205  You may now login to %s using the username and password you registered with."),
 206                    $name, $mosConfig_sitename, $mosConfig_live_site);
 207          $loginfo = new mosLoginDetails($username, $pwd);
 208          $mambothandler->trigger('userRegister', array($loginfo));
 209          $mambothandler->trigger('userActivate', array($loginfo));
 210      }
 211  
 212      $message = html_entity_decode($message, ENT_QUOTES);
 213      // Send email to user
 214      if ($mosConfig_mailfrom != "" && $mosConfig_fromname != "") {
 215          $adminName2 = $mosConfig_fromname;
 216          $adminEmail2 = $mosConfig_mailfrom;
 217      } else {
 218          $database->setQuery( "SELECT name, email FROM #__users"
 219          ."\n WHERE usertype='super administrator'" );
 220          $rows = $database->loadObjectList();
 221          $row2 = $rows[0];
 222          $adminName2 = $row2->name;
 223          $adminEmail2 = $row2->email;
 224      }
 225  
 226      mosMail($adminEmail2, $adminName2, $email, $subject, $message);
 227  
 228      // Send notification to all administrators
 229      $subject2 = sprintf (T_('Account details for %s at %s'), $name, $mosConfig_sitename);
 230      $message2 = sprintf (T_('Hello %s,
 231  
 232  A new user has registered at %s.
 233  This email contains their details:
 234  
 235  Name - %s
 236  e-mail - %s
 237  Username - %s
 238  
 239  Please do not respond to this message as it is automatically generated and is for information purposes only'), 
 240                  $adminName2, $mosConfig_sitename, $row->name, $email, $username);
 241      $subject2 = html_entity_decode($subject2, ENT_QUOTES);
 242      $message2 = html_entity_decode($message2, ENT_QUOTES);
 243  
 244      // get superadministrators id
 245      $admins = $acl->get_group_objects( 25, 'ARO' );
 246  
 247      foreach ( $admins['users'] AS $id ) {
 248          $database->setQuery( "SELECT email, sendEmail FROM #__users"
 249              ."\n WHERE id='$id'" );
 250          $rows = $database->loadObjectList();
 251  
 252          $row = $rows[0];
 253  
 254          if ($row->sendEmail) {
 255              mosMail($adminEmail2, $adminName2, $row->email, $subject2, $message2);
 256          }
 257      }
 258  
 259      if ( $mosConfig_useractivation == "1" ){
 260          echo '<div class="componentheading">'.T_('Registration Complete').'</div><br />';
 261          echo T_('Your account has been created and an activation link has been sent to the e-mail address you entered. Note that you must activate the account by clicking on the activation link before you can login.');
 262      } else {
 263          echo '<div class="componentheading">'.T_('Registration Complete').'</div><br />';        
 264          echo T_('You may now login.');
 265      }
 266  
 267  }
 268  
 269  function activate( $option ) {
 270      global $database;
 271      global $mosConfig_useractivation, $mosConfig_allowUserRegistration;
 272  
 273      if ($mosConfig_allowUserRegistration == '0' || $mosConfig_useractivation == '0') {
 274          mosNotAuth();
 275          return;
 276      }
 277  
 278      $activation = mosGetParam( $_REQUEST, 'activation', '' );
 279      $activation = $database->getEscaped( $activation );
 280  
 281      if (empty( $activation )) {
 282          echo '<div class="componentheading">'.T_('Invalid Activation Link!').'</div><br />';
 283          echo T_('There is no such account in our database or the account has already been activated.');
 284          return;
 285      }
 286  
 287      $database->setQuery( "SELECT username FROM #__users"
 288      ."\n WHERE activation='$activation' AND block='1'" );
 289      $username = $database->loadResult();
 290  
 291      if ($username) {
 292          $database->setQuery( "UPDATE #__users SET block='0', activation='' WHERE activation='$activation' AND block='1'" );
 293          if (!$database->query()) {
 294              echo "SQL error" . $database->stderr(true);
 295          }
 296          echo '<div class="componentheading">'.T_('Activation Complete!').'</div><br />';
 297          echo T_('Your account has been activated successfully. You can now login using the username and password you chose during registration.');
 298          $loginfo = new mosLoginDetails($username);
 299          $mambothandler =& mosMambotHandler::getInstance();
 300          $mambothandler->loadBotGroup('authenticator');
 301          $mambothandler->trigger('userActivate', array($loginfo));
 302      } else {
 303          echo '<div class="componentheading">'.T_('Invalid Activation Link!').'</div><br />';
 304          echo T_('There is no such account in our database or the account has already been activated.');
 305      }
 306  }
 307  
 308  function is_email($email){
 309      $rBool=false;
 310  
 311      if(preg_match("/[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}/", $email)){
 312          $rBool=true;
 313      }
 314      return $rBool;
 315  }
 316  ?>