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

Source for file users_lib.php

Documentation is available at users_lib.php

  1. <?php
  2. /**
  3.  * @version $Header$
  4.  * @package users
  5.  * @subpackage functions
  6.  */
  7.  
  8. /**
  9.  * users_admin_email_user
  10.  * 
  11.  * @param array $pParamHash 
  12.  * @access public
  13.  * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
  14.  */
  15. function users_admin_email_user( &$pParamHash ) {
  16.     global $gBitSmarty, $gBitSystem;
  17.  
  18.     $ret = FALSE;
  19.     $siteName = $gBitSystem->getConfig('site_title', $_SERVER['HTTP_HOST'] );
  20.     $gBitSmarty->assign( 'siteName', $_SERVER["SERVER_NAME"] );
  21.     $gBitSmarty->assign( 'mail_site', $_SERVER["SERVER_NAME"] );
  22.     $gBitSmarty->assign( 'mail_user', $pParamHash['login'] );
  23.     if( !empty( $_REQUEST['admin_verify_user'] ) && !empty( $pParamHash['user_store']['provpass'] )) {
  24.         $apass = addslashes( substr( md5( $gBitSystem->genPass() ), 0, 25 ));
  25.         $apass = $pParamHash['user_store']['provpass'];
  26.         $machine = httpPrefix().USERS_PKG_URL.'confirm.php';
  27.         // Send the mail
  28.         $gBitSmarty->assign( 'mail_machine', $machine );
  29.         $gBitSmarty->assign( 'mailUserId', $pParamHash['user_store']['user_id'] );
  30.         $gBitSmarty->assign( 'mailProvPass', $apass );
  31.         $mail_data = $gBitSmarty->fetch( 'bitpackage:users/admin_validation_mail.tpl' );
  32.         mail( $pParamHash['email'], $siteName.' - '.tra( 'Your registration information' ),$mail_data,"From: ".$gBitSystem->getConfig( 'site_sender_email' )."\r\nContent-type: text/plain;charset=utf-8\r\n" );
  33.         $gBitSmarty->assign( 'showmsg', 'n' );
  34.  
  35.         $ret = array(
  36.             'confirm' => 'Validation email sent to '.$pParamHash['email'].'.'
  37.         );
  38.     } elseif( !empty( $pParamHash['password'] )) {
  39.         // Send the welcome mail
  40.         $gBitSmarty->assign( 'mailPassword',$pParamHash['password'] );
  41.         $gBitSmarty->assign( 'mailEmail',$pParamHash['email'] );
  42.         $mail_data = $gBitSmarty->fetch( 'bitpackage:users/admin_welcome_mail.tpl' );
  43.         mail( $pParamHash["email"], tra( 'Welcome to' ).' '.$siteName,$mail_data,"From: ".$gBitSystem->getConfig('site_sender_email')."\r\nContent-type: text/plain;charset=utf-8\r\n" );
  44.         $ret = array(
  45.             'welcome' => 'Welcome email sent to '.$pParamHash['email'].'.'
  46.         );
  47.     }
  48.     return $ret;
  49. }
  50.  
  51. /**
  52.  * scramble_email
  53.  * 
  54.  * @param array $email 
  55.  * @param string $method 
  56.  * @access public
  57.  * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
  58.  */
  59. function scramble_email( $email, $method = 'unicode' ) {
  60.     switch( $method ) {
  61.         case 'strtr':
  62.             $trans = array(    "@" => tra(" AT "),
  63.             "." => tra(" DOT ")
  64.             );
  65.             $ret = strtr($email, $trans);
  66.             break;
  67.  
  68.         case 'x' :
  69.             $encoded = $email;
  70.             for ($i = strpos($email, "@") + 1; $i < strlen($email); $i++) {
  71.                 if ($encoded[$i]  != ".") $encoded[$i] = 'x';
  72.             }
  73.             $ret = $encoded;
  74.             break;
  75.  
  76.         // for legacy code
  77.         case 'y':
  78.         case 'unicode':
  79.             $encoded = '';
  80.             for( $i = 0; $i < strlen( $email ); $i++) {
  81.                 $encoded .= '&#' . ord( $email[$i] ). ';';
  82.             }
  83.             $ret = $encoded;
  84.             break;
  85.  
  86.         default:
  87.             $ret = NULL;
  88.             break;
  89.     }
  90.     return $ret;
  91. }
  92.  
  93.  
  94. function users_httpauth(){
  95.     global $gBitSystem, $gBitUser;
  96.     // require ssl
  97.     $https_mode = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off';
  98.     // no https redirect
  99.     if( !$https_mode ){
  100.         $url = $gBitSystem->getConfig( 'site_https_domain' );
  101.         $site_https_port = $gBitSystem->getConfig('site_https_port', 443);
  102.         if ($site_https_port != 443)
  103.             $url .= ':' . $site_https_port;
  104.         $url .= $gBitSystem->getConfig( 'site_https_prefix' ) . $_SERVER['REQUEST_URI'];
  105.         if (SID)
  106.             $url .= (!empty( $_SERVER['QUERY_STRING'] )?'&':'?') . SID;
  107.         $url = preg_replace('/\/+/', '/', $url);
  108.         header("Location: https://$url");
  109.         exit;
  110.     }
  111.  
  112.     $user = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : false;
  113.     $pass = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : false;
  114.     $challenge = false;
  115.     $response = false;
  116.     // verify the user is valid first
  117.     if( $gBitUser->validate( $user, $pass, $challenge, $response ) ){
  118.         // log in user - returns a url so can't use it for validation check
  119.         $gBitUser->login( $user, $pass, $challenge, $response );
  120.         return( TRUE );
  121.     }
  122.     // require http auth
  123.     else{
  124.         header('WWW-Authenticate: Basic realm="Test"');
  125.         header('HTTP/1.0 401 Unauthorized');
  126.         $gBitSystem->fatalError( tra('HTTP Authentication Canceled') );
  127.         exit;
  128.     }
  129. }

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