00001 <?php
00002 abstract class GlobalRegistrationForm extends Form {
00003
00004 protected $xform;
00005
00006
00007 protected $globalUser;
00008
00009
00010 protected $alreadyRegistered = false;
00011
00012
00013 private $complete = false;
00014
00020 public function __construct($globalUser = null) {
00021 if($globalUser !== null) {
00022 $this->globalUser = $globalUser;
00023 $this->alreadyRegistered = true;
00024 }
00025
00026 SConfig::setOption("xforms.pictcha", false);
00027 $this->xform = new XFormsRenderModule();
00028 }
00029
00034 private function makeAuthForm() {
00035
00036 if(SConfig::getOption('spath.protocol') != 'https://') {
00037 SWATFunctions::redirectHTTPS();
00038 }
00039 SConfig::setOption("xforms.pictcha", true);
00040
00041 $this->addInput('input', 'Username', 'username', 'username', true);
00042 $this->addInput('password', 'Password', 'password', 'password', true);
00043 $this->addInput('password', 'Confirm Password', 'confirmPassword', 'password', true);
00044 $this->addInput('input', 'First Name', 'firstName', 'name', true);
00045 $this->addInput('input', 'Last Name', 'lastName', 'name', true);
00046 $this->addInput('input', 'Email Address', 'email', 'email', true);
00047 }
00048
00053 private function processAuth() {
00054
00055 $val = $this->xform->getValidator();
00056
00057
00058 $pass1 = $this->xform->getSubmittedValue('password');
00059 $pass2 = $this->xform->getSubmittedValue('confirmPassword');
00060
00061
00062 if ($pass1!= $pass2) {
00063 $this->xform->setErrorCode('confirmPassword', '2002');
00064 }
00065
00066
00067 if(AuthUser::exists(array('username' => $this->xform->getSubmittedValue('username')))) {
00068 $this->xform->setErrorCode('username', '2003');
00069 }
00070
00071 $val->setCustomCode('2002', "Your passwords do not match.");
00072 $val->setCustomCode('2003', "Username is already taken.");
00073 }
00074
00079 private function completeAuth() {
00080 $this->globalUser = new AuthUser;
00081 $this->globalUser->username = $this->xform->getSubmittedValue('username');
00082 authDB::setPassword($this->globalUser, $this->xform->getSubmittedValue('password'));
00083 $this->globalUser->firstName = $this->xform->getSubmittedValue('firstName');
00084 $this->globalUser->lastName = $this->xform->getSubmittedValue('lastName');
00085 $this->globalUser->email = $this->xform->getSubmittedValue('email');
00086 $this->globalUser->commit();
00087 $this->globalUser = AuthUser::retrieve(array('username' => $this->globalUser->username));
00088 }
00089
00094 private function makeForm() {
00095 if(!$this->alreadyRegistered)
00096 $this->makeAuthForm();
00097 $this->makeLocalForm();
00098 $outputXML = $this->buildForm('Register');
00099 $this->xform->loadXml($outputXML);
00100 }
00101
00106 private function complete() {
00107 if(!$this->alreadyRegistered)
00108 $this->completeAuth();
00109 $this->completeLocal();
00110 $this->complete = true;
00111 }
00112
00117 private function validate() {
00118 if(!$this->alreadyRegistered)
00119 $this->processAuth();
00120 $this->processLocal();
00121 }
00122
00127 public function process() {
00128 $this->makeForm();
00129
00130 $this->xform->processInput();
00131 if($this->xform->isSubmitted()) {
00132 $this->validate();
00133 if($this->xform->isComplete())
00134 $this->complete();
00135 }
00136 }
00137
00144 public function getXForm() {
00145 return $this->xform;
00146 }
00147
00153 public function render() {
00154 if($this->complete) {
00155 return 'Registration complete.';
00156 } else {
00157 return $this->xform->toHtml();
00158 }
00159 }
00160
00161
00162 abstract protected function processLocal();
00163
00164
00165 abstract protected function completeLocal();
00166
00167
00168 abstract protected function makeLocalForm();
00169 }
00170 ?>