public function signup()
 {
     global $config;
     global $site;
     $user = new User();
     $user->requiresContactData = true;
     $arid = '';
     if (isset($_SESSION['affiliate_referral'])) {
         $arid = $_SESSION['affiliate_referral'];
     }
     $user->referral_type = "none";
     if ($this->post) {
         $user->nickname = $this->PostData('nickname');
         $user->email = $this->PostData('email');
         $user->password = $this->PostData('password');
         $user->password_confirmation = $this->PostData('password_confirmation');
         $user->firstname = $this->PostData('firstname');
         $user->surname = $this->PostData('surname');
         $user->clan = $this->PostData('clan');
         $user->address1 = $this->PostData('address1');
         $user->address2 = $this->PostData('address2');
         $user->towncity = $this->PostData('towncity');
         $user->county = $this->PostData('county');
         $user->country_id = $this->PostData('country_id');
         $user->postcode = $this->PostData('postcode');
         $user->phone = $this->PostData('phone');
         $user->set_dateofbirth($this->PostData('dateofbirth'));
         $user->terms = $this->PostData('terms');
         $user->allow_emails = $this->PostData('allow_emails');
         $user->referral_type = $this->PostData('referral_type');
         $arid = $this->PostData('arid');
         $valid = $user->validate();
         $validCaptcha = Recaptcha::validate($this->PostData('g-recaptcha-response'), Site::RemoteIP());
         if (!$validCaptcha) {
             $this->assign("failedcaptcha", true);
         } elseif ($valid) {
             $user->save();
             // This was a referral, make a note.
             if ($arid) {
                 AffiliateReferral::create_from_arid($user, $arid);
             }
             Email::send_user_signup($user);
             Redirect("signup/complete");
         }
     }
     $this->assign("affiliate_referral_id", $arid);
     $referral_types = array_merge(array("none" => "Please choose..."), $user->referral_types);
     $this->assign("referral_types", $referral_types);
     $terms = Content::find_by_permalink("signup-terms");
     $countries = Utils::FormOptions(Country::find_all("", "countries.name ASC"));
     $this->assign('countries', $countries);
     $this->assign("user", $user);
     $this->assign("site", $site);
     $this->assign("terms", $terms);
     $this->assign('arid', $arid);
     global $config;
     $this->assign('recaptcha', $config['recaptcha']['public']);
     $this->title = "Signup";
     $this->render("user/signup.tpl");
 }