Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Register
- {
- /*
- *
- * @To-DO: Add age restrictions.
- *
- */
- private $dob = null,
- $day = null,
- $month = null,
- $year = null,
- $gender = 'male',
- $username = 'Guest',
- $password = null,
- $email = null,
- $retypedEmail = null,
- $secCode = null,
- $termsOfServiceSelection = null,
- $marketing = false,
- $minAge = 11,
- $maxAge = 100;
- private $step = 1,
- $errorMessage = null,
- $currentPage = null,
- $bgClass = null;
- public function __construct()
- {
- global $Smarty;
- $this->currentPage = $_GET['page'];
- $this->_setData();
- $this->_findValidPage();
- if( $_POST )
- {
- $this->_processData();
- }
- $Smarty->assign('step', $this->grabData('step') );
- $Smarty->assign('bodyClass', $this->grabData('bgClass') );
- $Smarty->assign('error', $this->grabData('errorMessage') );
- }
- public function grabSession( $key )
- {
- return ($_SESSION[$key] ? $_SESSION[$key] : false);
- }
- public function setSession( $key, $value = '' )
- {
- $_SESSION[$key] = $value;
- }
- public function grabData( $key, $value = '' )
- {
- if( $value )
- {
- $this->$key = $value;
- return $value;
- }
- else
- {
- return $this->$key ? $this->$key : false;
- }
- }
- private function _setData()
- {
- if( $_SESSION )
- {
- foreach( $_SESSION as $key => $value )
- {
- $this->$key = $value;
- }
- }
- if( $_POST )
- {
- foreach( $_POST as $key => $value )
- {
- $key = str_replace('bean_', '', $key);
- $this->$key = $value;
- }
- }
- }
- private function _findValidPage( )
- {
- switch( $this->grabSession('step') )
- {
- default:
- $this->setSession('step', 1);
- $this->redirect();
- break;
- case 1:
- if( $this->currentPage != 'start' )
- {
- if( !$this->grabData('dob') || $this->grabData('bean_gender') )
- {
- $this->redirect();
- }
- }
- $this->grabData('bgClass', 'background-agegate');
- $this->grabData('template', 'start');
- break;
- case 2:
- if( $this->currentPage != 'email_password' )
- {
- if( !$this->grabData('email') || !$this->grabData('password') )
- {
- $this->redirect('email_password');
- }
- }
- $this->grabData('bgClass', 'background-accountdetails-'.$this->grabData('gender') );
- $this->grabData('template', 'email_password');
- break;
- case 3:
- if( $this->currentPage != 'captcha' )
- {
- if( $this->grabData('email') && $this->grabData('password') )
- {
- $this->redirect('captcha');
- }
- }
- $this->grabData('bgClass', 'background-captcha' );
- $this->grabData('template', 'captcha');
- break;
- }
- }
- private function redirect( $pageName = 'start' )
- {
- header('Location: /quickregister/' . $pageName );
- }
- private function _processData()
- {
- switch( $this->grabData('step') )
- {
- case 1:
- if( $this->gender != 'male' )
- {
- $this->gender = 'female';
- }
- else
- {
- $this->gender = 'male';
- }
- $this->setSession('gender', $this->gender);
- foreach( array ( 'day', 'month', 'year' ) as $check )
- {
- if( $this->grabData( $check ) )
- {
- $this->dob .= $this->$check . ( $check == 'year' ?: '-' );
- $this->setSession('dob', $this->dob);
- }
- else
- {
- $this->errorMessage = 'Please supply a valid birthdate.';
- break;
- }
- }
- if( !$this->errorMessage )
- {
- $this->setSession('step', 2);
- $this->redirect('password_email');
- }
- break;
- case 2:
- if( !$this->email || !filter_var( $this->email, FILTER_VALIDATE_EMAIL ) )
- {
- $this->errorMessage['email'] = 'Please enter a valid email address';
- }
- if( !$this->retypedEmail )
- {
- $this->errorMessage['retypedEmail'] = 'Please type your email again';
- }
- if( $this->email != $this->retypedEmail )
- {
- $this->errorMessage['email'] = 'Emails don\'t match';
- }
- if( MySQL::newQuery()->Query('SELECT null FROM users WHERE email = ? LIMIT 1;')->bind('s', $this->email)->count() > 0 )
- {
- $this->errorMessage['email'] = 'This email is already in use';
- }
- if( strlen( $this->password ) < 5 || strlen( $this->password ) > 20 )
- {
- $this->errorMessage['password'] = 'Please enter a valid password ';
- }
- elseif( !preg_match( '/([A-Za-z]+)/', $this->password ) || !preg_match('/([0-9]+)/', $this->password) )
- {
- $this->errorMessage['password'] = 'Your password must also include numbers';
- }
- if( !$this->termsOfServiceSelection )
- {
- $this->errorMessage['tos'] = 'Please accept the terms of service';
- }
- if( !$this->errorMessage )
- {
- $this->setSession('email', $this->email);
- $this->setSession('password', $this->password );
- $this->setSession('newsletter', $this->marketing ? true : false);
- $this->setSession('step', 3);
- $this->redirect('captcha');
- }
- break;
- case 3:
- global $config;
- require_once BASE . 'libs/class.recaptcha.php';
- $inst = recaptcha_check_answer
- (
- $config['recaptcha']['privateKey'],
- $_SERVER['REMOTE_ADDR'],
- $this->recaptcha_challenge_field,
- $this->captchaResponse
- );
- if( $inst->is_valid )
- {
- global $user;
- $userNameClunks = explode('@', $this->email);
- $this->username = $userNameClunks[0] . rand( 0, 4000 );
- MySQL::newQuery()
- ->Query('INSERT INTO users (email, password)VALUES(?, ?);')
- ->bind('ss', $this->email, User::encrypt( $this->password ) )
- ->execute();
- $uId = MySQL::$link->insert_id;
- MySQL::newQuery()
- ->Query('INSERT INTO characters
- (account_uid, username, motto, gender, last_ip, timestamp_created)
- VALUES
- (?, ?, ?, ?, ?, UNIX_TIMESTAMP() );
- ')
- ->bind('issss', $uId, $this->username, 'James rocks!', ($this->gender == 'male' ? 'M' : 'F'), $_SERVER['REMOTE_ADDR'] )
- ->execute();
- foreach( $_SESSION as $key => $value ) { $_SESSION[$key] = ''; }
- $user->login( $this->email, $this->password );
- Header('Location: /me');
- }
- else
- {
- $this->errorMessage[] = 'The security code was invalid, please try again.';
- }
- break;
- }
- }
- }
Add Comment
Please, Sign In to add comment