Example #1
0
    /**
     * Generate dummy users
     * @param  integer $count Number of Users to create
     * @return false
     */
    public static function generateDummies($count = 100)
    {
        $characters = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','Y','X','Z');

        $titles = \CPFCMembers\Form::getTitleOptions();
        $firstNames = array('Jake','Jon','Rohit','Victoria','Sophie','Thomas','Paul','Oliver','Stuart','Mel','Binal');
        $lastNames = array('Smith','Rogers','Jones','McDonald','Johnson-Thompson','Ellis','Ashley','O\'Flynn','Samuels','Barnard','Doe');
        $dob = array('start'=>mktime(0,0,0,1,1,1900),'finish'=>mktime(0,0,0,date("n"),date("j") ,date("Y")-13));
        $emailAddress = '*****@*****.**';
        $password = '******';
        $daytimeNumber = array('02%d%d %d%d%d %d%d%d%d', '01%d%d%d %d%d%d%d%d%d');
        $mobileNumber = array('07%d%d%d %d%d%d%d%d%d', '');
        $houseNameNumbers = array('a','b','c','d','','','','','','','','','','','','');
        $streets = array('firstPart'=>array('Demo ','Test ','Layer ',''),'secondPart'=>array('Lane','Road','Street','Avenue','Crescent','Rd.','Av.','Close','St.'));
        $towns = array('Norwich','London','Bedford','Newquay','Nottingham','Edinburgh','Cardiff','Glasgow','Bangor','Reading','Stevenage','Swansea','Gloucester', '', '', '', '');
        $counties = array('Essex','London','Suffolk','Norfolk','Perthshire','Cornwall','Surrey','Kent','Yorkshire','Lancs','Gloucestershire','Herefordshire','Warwickshire', '', '', '', '');
        $postcode = array('%s%s%d %d%s%s', '');
        $countries = array_keys(\CPFCMembers\Form::getCountryOptions());
        $registrationStatuses = array('verified','unverified');
        $statuses = array('active','disabled','deleted');
        $membershipLevels = \CPFCMembers\MembershipLevelModel::fetchAll();
        $seeTicketsAccountNumber = array('%s%s%s-%d%d%d','','','','','');
        $loyaltyPoints = array('%d','0','0','','','');
        $source = 'website';
        $registeredDate = array('start'=>mktime(0,0,0,1,11,2014),'finish'=>time());

        $i = 0;
        while ($i < $count) {
            $User = new \CPFCMembers\UserModel();

            $User->setTitle($titles[array_rand($titles)]);
            $User->setFirstName($firstNames[array_rand($firstNames)]);
            $User->setLastName($lastNames[array_rand($lastNames)]);
            $User->setDob(date('Y-m-d',mt_rand($dob['start'],$dob['finish'])));
            $User->setEmailAddress(sprintf($emailAddress,sha1(mt_rand())));
            $User->setPassword($password);
            $User->setDaytimePhone(vsprintf($daytimeNumber[array_rand($daytimeNumber)], array(
                mt_rand(0,9),mt_rand(0,9),mt_rand(0,9),mt_rand(0,9),mt_rand(0,9),mt_rand(0,9),mt_rand(0,9),mt_rand(0,9),mt_rand(0,9))
            ));
            $User->setMobilePhone(vsprintf($mobileNumber[array_rand($mobileNumber)], array(
                mt_rand(0,9),mt_rand(0,9),mt_rand(0,9),mt_rand(0,9),mt_rand(0,9),mt_rand(0,9),mt_rand(0,9),mt_rand(0,9),mt_rand(0,9))
            ));
            $User->setHouseNameNumber(mt_rand(1,999).$houseNameNumbers[array_rand($houseNameNumbers)]);
            $User->setStreet(trim($streets['firstPart'][array_rand($streets['firstPart'])].$streets['secondPart'][array_rand($streets['secondPart'])]));
            $User->setTown($towns[array_rand($towns)]);
            $User->setCounty($counties[array_rand($counties)]);
            $User->setPostcode(vsprintf($postcode[array_rand($postcode)], array($characters[array_rand($characters)],$characters[array_rand($characters)],mt_rand(0,9),mt_rand(0,9),$characters[array_rand($characters)],$characters[array_rand($characters)])
            ));
            $User->setCountry($countries[array_rand($countries)]);
            $User->setRegistrationStatus($registrationStatuses[array_rand($registrationStatuses)]);
            $User->setStatus($statuses[array_rand($statuses)]);
            $User->setMembershipLevel(array_rand($membershipLevels));
            $User->setPreferenceRegularNewsletter(mt_rand(0,1));
            $User->setPreferenceBreakingNews(mt_rand(0,1));
            $User->setPreferencePartners(mt_rand(0,1));
            $User->setSeeTicketsAccountNumber(vsprintf($seeTicketsAccountNumber[array_rand($seeTicketsAccountNumber)],array($characters[array_rand($characters)],$characters[array_rand($characters)],$characters[array_rand($characters)],mt_rand(0,9),mt_rand(0,9),mt_rand(0,9))));
            $User->setLoyaltyPoints(sprintf($loyaltyPoints[array_rand($loyaltyPoints)],mt_rand(0,750)));
            $User->setSource($source);
            $User->setRegisteredDate(date('Y-m-d H:i:s',mt_rand($registeredDate['start'],$registeredDate['finish'])));

            $User->save(false);

            $i++;
        }
    }
Example #2
0
    /**
     * Register process
     */
    protected function _register()
    {
        // Can't access if already logged in as Member
        if (\CPFCMembers\Auth::isLoggedIn()) {
            wp_redirect(cpfc_home_url(CPFC_MEMBERS_HOME_URL, CPFC_MEMBERS_HTTP_MODE), 301);
            exit();
        }

        if (Input::isPost()) {
            $form = \CPFCMembers\RegistrationForm::getInstance();
            $form->setValues(Input::post());
            $form->validate();

            if ($form->isValid()) {
                $User = new \CPFCMembers\UserModel();
                $User->populateFromArray($form->getValues());
                $User->setRegistrationStatus('unverified');
                $User->setStatus('active');
                $User->setMembershipLevel('free');
                $User->setRegisteredDate(date('Y-m-d H:i:s'));
                $User->setSource('website');
                $User->generateAndStoreVerificationCode();
                if ($User->save(true)) {
                    $email = new \CPFCMembers\Email('email_templates/initial_registration', array('User'=>$User));
                    $email->send($User->getEmailAddress(), 'Your Account has been created');

                    // Log User in automatically
                    $Auth = \CPFCMembers\Auth::getInstance();
                    $Auth->authenticate($User->getEmailAddress(), $User->getPassword(), $remember);

					if($loginRedirect = \CPFCMembers\Session::get('login_redirect')){
						\CPFCMembers\Session::delete('login_redirect');
					}
					else{
						$loginRedirect = cpfc_home_url(CPFC_MEMBERS_HOME_URL, CPFC_MEMBERS_HTTP_MODE) . '?registered';
					}

                    if ($loginRedirect == '' || $loginRedirect == '/') {
                        $loginRedirect .= '?registered';
                    }

					wp_redirect($loginRedirect, 301);
                    exit();
                } else {
                    $form->addError('form', 'Your registration could not be completed at this time');
                }
            }
        }
    }