users
[ class tree: users ] [ index: users ] [ all elements ]

Source for file register.php

Documentation is available at register.php

  1. <?php
  2. /**
  3.  * register new user
  4.  *
  5.  * @copyright (c) 2004-15 bitweaver.org
  6.  *
  7.  * @package users
  8.  * @subpackage functions
  9.  */
  10.  
  11. /**
  12.  * required setup
  13.  */
  14. // Avoid user hell
  15. if( isset( $_REQUEST['tk'] ) ) {
  16.     unset( $_REQUEST['tk'] );
  17. }
  18.  
  19. require_once( '../kernel/setup_inc.php' );
  20. require_once( KERNEL_PKG_PATH.'BitBase.php' );
  21. include_once( KERNEL_PKG_PATH.'notification_lib.php' );
  22. require_once( USERS_PKG_PATH.'classes/recaptchalib.php' );
  23.  
  24. $gBitSystem->verifyFeature( 'users_allow_register' );
  25.  
  26. // Everything below here is needed for registration
  27.  
  28. require_once( USERS_PKG_PATH.'BaseAuth.php' );
  29.  
  30. if( !empty( $_REQUEST['returnto'] ) ) {
  31.     $_SESSION['returnto'] = $_REQUEST['returnto'];
  32. } elseif( !empty( $_SERVER['HTTP_REFERER'] ) && !strpos( $_SERVER['HTTP_REFERER'], 'login.php' )  && !strpos( $_SERVER['HTTP_REFERER'], 'register.php' ) ) {
  33.     $from = parse_url( $_SERVER['HTTP_REFERER'] );
  34.     if( !empty( $from['path'] ) && $from['host'] == $_SERVER['SERVER_NAME'] ) {
  35.         $_SESSION['loginfrom'] = $from['path'].'?'.( !empty( $from['query'] ) ? $from['query'] : '' );
  36.     }
  37. }
  38.  
  39. if( $gBitUser->isRegistered() ) {
  40.     bit_redirect( $gBitSystem->getDefaultPage() );
  41. }
  42. if( isset( $_REQUEST["register"] ) ) {
  43.  
  44.     $reg = $_REQUEST;
  45.  
  46.     // Register the new user
  47.     $userClass = $gBitSystem->getConfig( 'user_class', 'BitPermUser' );
  48.     $newUser = new $userClass();
  49.     if( $newUser->preRegisterVerify( $reg ) && $newUser->register( $reg ) ) {
  50.         $gBitUser->mUserId = $newUser->mUserId;
  51.  
  52.         // add user to user-selected group
  53.         if ( !empty( $_REQUEST['group'] ) ) {
  54.             $groupInfo = $gBitUser->getGroupInfo( $_REQUEST['group'] );
  55.             if ( empty($groupInfo) || $groupInfo['is_public'] != 'y' ) {
  56.                 $errors[] = "You can't use this group";
  57.                 $gBitSmarty->assign_by_ref( 'errors', $errors );
  58.             } else {
  59.                 $userId = $newUser->getUserId();
  60.                 $gBitUser->addUserToGroup( $userId, $_REQUEST['group'] );
  61.                 $gBitUser->storeUserDefaultGroup( $userId, $_REQUEST['group'] );
  62.             }
  63.         }
  64.  
  65.         // set the user to private if necessary. defaults to public
  66.         if(!empty($_REQUEST['users_information']) && $_REQUEST['users_information'] == 'private'){
  67.             $newUser->storePreference('users_information','private');
  68.         }
  69.  
  70.         // requires validation by email 
  71.         if( $gBitSystem->isFeatureActive( 'users_validate_user' ) ) {
  72.             $gBitSmarty->assign('msg',tra('You will receive an email with information to login for the first time into this site'));
  73.             $gBitSmarty->assign('showmsg','y');
  74.         } else {
  75.             if( !empty( $_SESSION['loginfrom'] ) ) {
  76.                 unset( $_SESSION['loginfrom'] );
  77.             }
  78.             // registration login, fake the cookie so the session gets updated properly.
  79.             if( empty($_COOKIE[$gBitUser->getSiteCookieName()] ) ) {
  80.                 $_COOKIE[$gBitUser->getSiteCookieName()] = session_id();
  81.             }
  82.             // login with email since login is not technically required in the form, as it can be auto generated during store
  83.             $afterRegDefault = $newUser->login( $reg['email'], $reg['password'], FALSE, FALSE );
  84.             $url = $gBitSystem->getConfig( 'after_reg_url' )?BIT_ROOT_URI.$gBitSystem->getConfig( 'after_reg_url' ):$afterRegDefault;
  85.             // return to referring page
  86.             if( !empty( $_SESSION['returnto'] ) ) {
  87.                 $url = $_SESSION['returnto'];
  88.             // forward to group post-registration page 
  89.             } elseif ( !empty( $_REQUEST['group'] ) && !empty( $groupInfo['after_registration_page'] ) ) {
  90.                 if ( $newUser->verifyId( $groupInfo['after_registration_page'] ) ) {
  91.                     $url = BIT_ROOT_URI."index.php?content_id=".$groupInfo['after_registration_page'];
  92.                 } elseif( strpos( $groupInfo['after_registration_page'], '/' ) === FALSE ) {
  93.                     $url = BitPage::getDisplayUrlFromHash( $groupInfo['after_registration_page'] );
  94.                 } else {
  95.                     $url = $groupInfo['after_registration_page'];
  96.                 }
  97.             }
  98.             header( 'Location: '.$url );
  99.             exit;
  100.         }
  101.     } else {
  102.         $gBitSystem->setHttpStatus( HttpStatusCodes::HTTP_BAD_REQUEST );
  103.         $gBitSmarty->assign_by_ref( 'errors', $newUser->mErrors );
  104.     }
  105.  
  106.     $gBitSmarty->assign_by_ref( 'reg', $reg );
  107.  
  108. } else {
  109.     if( $gBitSystem->isFeatureActive( 'custom_user_fields' ) ) {
  110.         $fields= explode( ',', $gBitSystem->getConfig( 'custom_user_fields' )  );
  111.         trim_array( $fields );
  112.         $gBitSmarty->assign('customFields', $fields);
  113.     }
  114.  
  115.     for( $i=0; $i < BaseAuth::getAuthMethodCount(); $i++ ) {
  116.         $instance = BaseAuth::init( $i );
  117.         if( $instance && $instance->canManageAuth() ) {
  118.             $auth_reg_fields = $instance->getRegistrationFields();
  119.             foreach( array_keys( $auth_reg_fields ) as $auth_field ) {
  120.                 $auth_reg_fields[$auth_field]['value'] = $auth_reg_fields[$auth_field]['default'];
  121.             }
  122.             $gBitSmarty->assign( 'auth_reg_fields', $auth_reg_fields );
  123.             break;
  124.         }
  125.     }
  126. }
  127.  
  128. $languages = array();
  129. $languages = $gBitLanguage->listLanguages();
  130. $gBitSmarty->assign_by_ref( 'languages', $languages );
  131. $gBitSmarty->assign_by_ref( 'gBitLanguage', $gBitLanguage );
  132.  
  133. // Get flags here
  134. $flags = array();
  135. $h = opendir( USERS_PKG_PATH.'icons/flags/' );
  136. while( $file = readdir( $h )) {
  137.     if( strstr( $file, ".gif" )) {
  138.         $parts = explode( '.', $file );
  139.         $flags[] = $parts[0];
  140.     }
  141. }
  142. closedir( $h );
  143. sort( $flags );
  144. $gBitSmarty->assign('flags', $flags);
  145.  
  146. $listHash = array(
  147.     'is_public' => 'y',
  148.     'sort_mode' => array( 'is_default_asc', 'group_desc_asc' ),
  149. );
  150. $groupList = $gBitUser->getAllGroups( $listHash );
  151. $gBitSmarty->assign_by_ref( 'groupList', $groupList );
  152.  
  153. // include preferences settings from other packages - these will be included as individual tabs
  154. $packages = array();
  155. foreach( $gBitSystem->mPackages as $package ) {
  156.     if( $gBitSystem->isPackageActive( $package['name'] )) {
  157.         $php_file = $package['path'].'user_register_inc.php';
  158.         $tpl_file = $package['path'].'templates/user_register_inc.tpl';
  159.         if( file_exists( $tpl_file )) {
  160.             if( file_exists( $php_file ))  {
  161.                 require( $php_file );
  162.             }
  163.             $p=array();
  164.             $p['template'] = $tpl_file;
  165.             $packages[] = $p;
  166.         }
  167.     }
  168. }
  169. $gBitSmarty->assign_by_ref('packages',$packages );
  170.  
  171. if( !empty( $_REQUEST['error'] ) ) {
  172.     $gBitSmarty->assign( 'error', $_REQUEST['error'] );
  173.     $gBitSystem->setHttpStatus( HttpStatusCodes::HTTP_UNAUTHORIZED );
  174. }
  175.  
  176. $gBitSmarty->assign( 'metaKeywords', 'Login, Sign in, Registration, Register, Create new account' );
  177. $gBitSystem->display('bitpackage:users/register.tpl', 'Register' , array( 'display_mode' => 'display' ));
  178. ?>

Documentation generated on Wed, 29 Jul 2015 13:57:19 +0000 by phpDocumentor 1.5.0-lsces