get( 'allowUserRegistration' )) {
JError::raiseError( 403, JText::_( 'Access Forbidden' ));
return;
}
if ( $user->get('guest')) {
JRequest::setVar('view', 'register');
JRequest::setVar('post', $post );
$arg_params = &JComponentHelper::getParams( 'com_alpharegistration' );
if ( $arg_params->get( 'displayreferralcodeAUP' ) ) {
@session_start('alphauserpoints');
if ( @$_SESSION['referrerid']!='' )
{
JRequest::setVar('referrerid', @$_SESSION['referrerid'] );
} else JRequest::setVar('referrerid', '' );
}
} else {
$this->setRedirect('index.php?option=com_user&task=edit',JText::_('You are already registered.'));
}
parent::display();
}
/**
* Save user registration and notify users and admins if required
* @return void
*/
function register_save()
{
$app = JFactory::getApplication();
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
JPlugin::loadLanguage( 'com_user' );
jimport( 'joomla.mail.helper' );
$usersConfig = &JComponentHelper::getParams( 'com_users' );
$arg_params = &JComponentHelper::getParams( 'com_alpharegistration' );
$db =& JFactory::getDBO();
$nullDate = $db->getNullDate();
$date =& JFactory::getDate();
$now = $date->toMySQL();
$ip = $this->getClientIP();
// Purge automatically the users table
if ( $arg_params->def( 'purge_table_users', 0 ) )
{
$piordate = time();
$piordate = $piordate - (86400*$arg_params->get( 'purge_table_users' ));
$olddate =& JFactory::getDate($piordate);
$priornow = $olddate->toMySQL();
}
$view = $this->getView ( 'register','html' );
// reCaptcha
if ( $arg_params->def( 'userecaptcha', 1 ) ) {
require_once (JPATH_COMPONENT.DS.'assets'.DS.'recaptcha'.DS.'recaptchalib.php');
$privatekey = $arg_params->get( 'privkey' );
// the response from reCAPTCHA
$resp = null;
// the error code from reCAPTCHA, if any
$error = null;
// was there a reCAPTCHA response?
$recaptcha_response_field = JRequest::getVar('recaptcha_response_field', '', 'post', 'string');
if ( $recaptcha_response_field !='' ) {
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$recaptcha_response_field);
if (!$resp->is_valid) {
// set the error code so that we can display it
$error = $resp->error;
JError::raiseWarning(0, JText::_($error) );
$this->register(JRequest::get('post'));
return false;
}
} else {
JError::raiseWarning(0, JText::_('ARG_YOU_MUST_ENTER_THE_VERIFICATION_CODE') );
$this->register(JRequest::get('post'));
return false;
}
}
// check again all fields
$email = JRequest::getVar('email', '', 'post', 'string');
if ( !$arg_params->get( 'emailAsUsername', 0) ) {
// check if username >= 4 chars
$username = JRequest::getVar('username', '', 'post', 'string');
$vusername = strlen($username);
if ( $vusername<4 ) {
JError::raiseWarning('', JText::_('ARG_USERNAME_4_CHARS'));
$this->register(JRequest::get('post'));
return false;
}
// check if username is blocked
if ( $arg_params->get('usernamefilter', 0) && $arg_params->get('usernameblockedlist', '')!='' )
{
$usernamesblocked = str_replace(' ', '', $arg_params->get('usernameblockedlist'));
$usernamesblocked = preg_quote($usernamesblocked, '#');
$usernamesblocked = str_replace(array(",", '\*'), array('|', '.*'), $usernamesblocked );
$regex = "#^(?:$usernamesblocked)$#i";
$usernametest = strtolower (strval( $username ) );
if(preg_match($regex, $usernametest)) {
JError::raiseWarning('', JText::_( 'ARG_THIS_USERNAME_IS_NOT_ACCEPTED' ));
$_POST['username']='';
$this->register(JRequest::get('post'));
return false;
}
}
} elseif ( $arg_params->get( 'emailAsUsername') ) {
$username = $email;
$_POST['username']=$email;
}
$name = JRequest::getVar('name', '', 'post', 'string');
$vname = strlen($name);
if ( $vname<4 ) {
JError::raiseWarning('', JText::_('ARG_NAME_4_CHARS'));
$this->register(JRequest::get('post'));
return false;
}
$email2 = JRequest::getVar('email2', '', 'post', 'string');
if ( !JMailHelper::isEmailAddress($email) || ( $arg_params->get( 'forceToCheckEmail', 0 ) && $email2!=$email ) ) {
JError::raiseWarning('', JText::_('ARG_ENTER_A_VALID_EMAIL'));
$this->register(JRequest::get('post'));
return false;
}
if ($arg_params->get('emailfilter') && $arg_params->get('emaildomainslist')!='')
{
// check if email domain is in reject list
$pos = strrpos($email, '@');
if ( $pos )
{
$domain = substr($email,$pos+1);
//JError::raiseWarning( 0, $domain );
$domainslisttext = str_replace(" ", "", $arg_params->get('emaildomainslist'));
$domainslist = explode( ",", $domainslisttext);
$emailreject = in_array( $domain, $domainslist );
if ( $emailreject )
{
JError::raiseWarning('', JText::_('ARG_THIS_EMAIL_DOMAIN_IS_NOT_AVAILABLE'));
$this->register(JRequest::get('post'));
return false;
}
}
}
// BOTSCOUT.COM
if ($arg_params->get('useBotScout'))
{
if ($this->isBotScoutListed( $email, $ip, $arg_params ) === true )
{
JError::raiseWarning('', JText::_('ARG_MESSAGE_BLOCKED_BY_BOTSCOUT'));
$this->register(JRequest::get('post'));
return false;
}
}
$password = JRequest::getVar('password', '', 'post', 'string');
$vpassword = strlen($password);
if ( $vpassword<4 ) {
JError::raiseWarning('', JText::_('ARG_PASSWORD_4_CHARS'));
$this->register(JRequest::get('post'));
return false;
}
$badpasswordslist = array ("pass","password","sex","god","123456","123","liverpool","letmein","qwerty","monkey","azerty","merde","bite","couille","salope","connard","123123","123123123","123456789","test");
if ( in_array( strtolower($password), $badpasswordslist ) ) {
JError::raiseWarning('', JText::_('ARG_PLEASE_USE_A_STRONGER_PASSWORD'));
$this->register(JRequest::get('post'));
return false;
}
$password2 = JRequest::getVar('password2', '', 'post', 'string');
if ( $password!= $password2 ) {
JError::raiseWarning('', JText::_('ARG_CONFIRM_PASSWORD'));
$this->register(JRequest::get('post'));
return false;
}
// Birthdate (AlphaUserPoints component)
$birthdate = '';
if ( $arg_params->def( 'displaybirthdateAUP', 0 ) ) {
$birthdate = JRequest::getVar('birthdate', '0000-00-00', 'post', 'date');
// If required...
if ( $arg_params->get( 'displaybirthdateAUP')==2 && $birthdate=='' ) {
JError::raiseWarning('', JText::_('ARG_YOU_MUST_ENTER_A_BIRTHDATE'));
$this->register(JRequest::get('post'));
return false;
}
// if minimum age...
if ( $arg_params->def( 'minimum_age', 0 ) && $birthdate!='0000-00-00') {
if ( $this->date_diff($birthdate,$now) < $arg_params->get( 'minimum_age' ) ) {
JError::raiseWarning('', JText::_( 'ARG_MINIMUM_AGE' ) . ': ' . $arg_params->get( 'minimum_age' ) );
$this->register(JRequest::get('post'));
return false;
}
}
}
// Gender (AlphaUserPoints component)
$gender = '';
if ( $arg_params->def( 'displaygenderAUP', 0 ) ) {
$gender = JRequest::getVar('gender', 1, 'post', 'int');
}
// Check terms of use
if ( $arg_params->def( 'displaytermsofuse', 1 ) ) {
$terms = JRequest::getVar('terms', '', 'post', 'string');
if ( !$terms ) {
JError::raiseWarning('', JText::_('ARG_YOU_ACCEPT_TERMS'));
$this->register(JRequest::get('post'));
return false;
}
}
// Check if referral code (AlphaUserPoints component)
if ( $arg_params->def( 'displayreferralcodeAUP', 0 ) ) {
$referralexist = '';
$referrer = JRequest::getVar('referraluser', '', 'post', 'string');
$referrer = trim($referrer);
if ( $referrer ) {
$query = "SELECT id FROM #__alpha_userpoints WHERE `referreid`='".$referrer."' LIMIT 1";
$db->setQuery( $query );
$referralexist = $db->loadResult();
}
if ( $referrer && !$referralexist ) {
JError::raiseWarning('', JText::_('ARG_THIS_REFERRAL_CODE_NOT_EXIST'));
$this->register(JRequest::get('post'));
return false;
}
// If required...
if ( $arg_params->get( 'displayreferralcodeAUP')==2 && !$referrer ) {
JError::raiseWarning('', JText::_('ARG_YOU_MUST_ENTER_A_REFERRAL_USER_CODE'));
$this->register(JRequest::get('post'));
return false;
}
if ( $referralexist ) {
if ( file_exists(JPATH_SITE.DS.'components'.DS.'com_alphauserpoints'.DS.'helper.php') ) {
// Start session for AlphaUserPoints plugins system
@session_start('alphauserpoints');
$_SESSION['referrerid'] = $referrer;
// Check if exist an old referrerid with cookies
if ( isset($_COOKIE['referrerid']) ) {
setcookie('referrerid','',time()-3600);
unset($_COOKIE['referrerid']);
}
}
}
} else {
@session_start('alphauserpoints');
$_SESSION['referrerid'] = '';
if ( isset($_COOKIE['referrerid']) ) {
setcookie('referrerid','',time()-3600);
unset($_COOKIE['referrerid']);
}
}
// Check if coupon code (AlphaUserPoints component)
$couponcode = '';
$couponexist = '';
$couponcodelink = '';
if ( $arg_params->def( 'displaycouponcodeAUP', 0 ) ) {
$couponcode = JRequest::getVar('couponcode', '', 'post', 'string');
$couponcode = trim($couponcode);
if ( $couponcode ) {
$query = "SELECT * FROM #__alpha_userpoints_coupons WHERE `couponcode`='$couponcode' AND (`expires`>='$now' OR `expires`='0000-00-00 00:00:00')";
$db->setQuery( $query );
$couponexist = $db->loadObjectList();
}
if ( $couponcode && !$couponexist ) {
JError::raiseWarning('', JText::_('ARG_THIS_COUPON_CODE_IS_NOT_AVAILABLE'));
$this->register(JRequest::get('post'));
return false;
}
// If required...
if ( $arg_params->get( 'displaycouponcodeAUP')==2 && !$couponcode ) {
JError::raiseWarning('', JText::_('ARG_YOU_MUST_ENTER_A_COUPON_CODE'));
$this->register(JRequest::get('post'));
return false;
}
}
// Get required system objects
$user = clone(JFactory::getUser());
$pathway =& $app->getPathway();
$config =& JFactory::getConfig();
$authorize =& JFactory::getACL();
$document =& JFactory::getDocument();
$lang = $document->getLanguage();
// If user registration is not allowed, show 403 not authorized.
if ($usersConfig->get('allowUserRegistration') == '0') {
JError::raiseError( 403, JText::_( 'Access Forbidden' ));
return;
}
// Initialize new usertype setting
$newUsertype = $usersConfig->get( 'new_usertype' );
if (!$newUsertype) {
$newUsertype = 'Registered';
}
// Bind the post array to the user object
if (!$user->bind( JRequest::get('post'), 'usertype' )) {
JError::raiseError( 500, $user->getError());
}
// Set some initial user values
$user->set('id', 0);
//$user->set('usertype', '');
$user->set('usertype', $newUsertype);
$user->set('gid', $authorize->get_group_id( '', $newUsertype, 'ARO' ));
$date =& JFactory::getDate();
$user->set('registerDate', $date->toMySQL());
// If user activation is turned on, we need to set the activation information
$useractivation = $usersConfig->get( 'useractivation' );
if ($useractivation == '1')
{
jimport('joomla.user.helper');
$user->set('activation', JUtility::getHash( JUserHelper::genRandomPassword()) );
$user->set('block', '1');
// Used by AlphaUSerPoints
if ( $couponcode && $couponexist ) {
$couponcodelink = '&couponcode='.$couponcode.'&usr='.$username;
}
}
// If there was an error with registration, set the message and display form
if ( !$user->save() )
{
JError::raiseWarning('', JText::_( $user->getError()));
$this->register(JRequest::get('post'));
return false;
}
// If coupon code for AlphaUserPoints is enabled and if user activation is disabled
if ( $couponcode && $couponexist && $useractivation=='0' )
{
$this->getCouponCodePoints( $user->id, $couponcode, $couponexist );
}
// if birthdate
if ($birthdate) {
$this->saveBirthdate( $user->id, $birthdate );
}
// if gender
if ( $gender ) {
$this->saveGender( $user->id, $gender );
}
// Send registration confirmation mail
$password = JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW);
$password = preg_replace('/[\x00-\x1F\x7F]/', '', $password); //Disallow control chars in the email
AlpharegistrationController::_sendMail($user, $password, $couponcodelink);
// Purge automatically the users table
if ( $arg_params->def( 'purge_table_users', 0 ) )
{
$query = "DELETE FROM #__users WHERE registerDate <='".$priornow."' AND lastvisitDate='0000-00-00 00:00:00' AND block='1'";
$db->setQuery( $query );
$db->query();
}
// language specific image folder or default english image files
$folderstep2 = 'components/com_alpharegistration/assets/images';
$filenamestep2 = 'stepbystep2.png';
// importend for the file exists
$fileroute2 =(JPATH_COMPONENT.DS.'assets'.DS.'images'.DS.''.$lang.''.DS.''.$filenamestep2.'');
// Everything went fine, set relevant message depending upon user activation state and display message
if ( $useractivation == 1 ) {
$message = new stdClass();
$message->title = JText::_( 'ARG_CONFIRM_YOUR_EMAIL' );
$message->text = JText::_( 'ARG_CONFIRM_YOUR_EMAIL_TEXT' );
$message->showLoginForm = '0';
if ( $arg_params->get('displayheaderstep') ) {
// now choice the Image file
if (file_exists($fileroute2)) {
$message->headerIMG = "";
} else {
$message->headerIMG = "
";
if ( $arg_params->get( 'enabledMessagesLang' ) ) {
echo "