'/confirm/:reg_key', ); } //-------------------------------------------- // Main registration.. this will show either the register // form or the register agreement. //-------------------------------------------- function index(&$reg, &$req, &$resp) { $session = &$reg->get('session'); $user = &$reg->get('user'); $info = &new InformationDisplay($reg, $req, $resp); //-------------------------------------------- // So.. we're logged in. //-------------------------------------------- if($user->isMember()) { $info->display('logoutRequired'); } //-------------------------------------------- // You've got to agree. :P //-------------------------------------------- if ($session->get('k4_user_agreement') === NULL) { $this->redirect('/register/agreement/'); } //-------------------------------------------- // Captcha :D //-------------------------------------------- $captcha = &$this->getExtension('captcha'); $captcha->drawCaptcha($reg, $req, $resp); //-------------------------------------------- // Template yadda yadda. //-------------------------------------------- $resp->assign('content', 'register_form.html'); $resp->assign('breadcrumbs', $this->getBreadCrumbs()); $this->setPage("Register"); $this->setLayout('forum_base.html'); } //-------------------------------------------- // Display the registration agreement. //-------------------------------------------- function agreement(&$reg, &$req, &$resp) { $user = &$reg->get('user'); if($user->isMember()) { $info = &new InformationDisplay($reg, $req, $resp); $info->display('logoutRequired'); } $resp->assign('content', 'register_agreement.html'); $this->setPage("Registration Agreement"); $this->setLayout('forum_base.html'); } //-------------------------------------------- // Agree to the registration agreement //-------------------------------------------- function agree(&$reg, &$req, &$resp) { // Because Session::set() passes by ref $true = TRUE; $session = &$reg->get('session'); $session->set('k4_user_agreement', $true); // Go back to the registration page $this->redirect('/register/'); } //-------------------------------------------- // Decline the agreement. //-------------------------------------------- function decline(&$reg, &$req, &$resp) { // Delete the accepted agreement in the session unset($_SESSION['k4_user_agreement']); // Redirect to the base url $this->redirect(K4_TPL_BASE_URL); } //-------------------------------------------- // Add the user to the database //-------------------------------------------- function adduser(&$reg, &$req, &$resp) { $user = &$reg->get('user'); $session = &$reg->get('session'); $info = &new InformationDisplay($reg, $req, $resp); //-------------------------------------------- // Why would someone try to register when logged in? //-------------------------------------------- if($user->isMember()) { $info->display('logoutRequired'); } //-------------------------------------------- // Make sure that this user has agreed. //-------------------------------------------- if(!$req->get('agree') || $session->get('k4_user_agreement') === NULL) { $this->redirect('/register/agreement/'); } else { //-------------------------------------------- // Their password and password check do not match. //-------------------------------------------- if($req->get('pass') != $req->get('pass_check')) { $info->text('You mistyped your password validation.'); } $users = &$this->getFinder('users'); //-------------------------------------------- // Check for that username and email. //-------------------------------------------- $finder = &$this->getFinder('users'); $user = &$finder->findAllWhere("name=?", array($req->get('name'))); if($user !== NULL && $user->hasNext()) { $info->text("A user already exists with that username."); } $user = &$finder->findAllWhere("email=?", array($req->get('email'))); if($user !== NULL && $user->hasNext()) { $info->text("A user already exists with that email address."); } //-------------------------------------------- // Validate captcha, if any. //-------------------------------------------- $valid = TRUE; $captcha = &$this->getExtension('captcha'); if(!$captcha->isValid($reg, $req)) { $valid = FALSE; $resp->setError('captcha_input'); } //-------------------------------------------- // Add the user... //-------------------------------------------- $register_key = k4_hash(rand() + time()); $user = &$users->createRecord(); $user->set('name', $req->get('name')); $user->set('created', time()); // 0 for unconfirmed $user->set('pass', k4_hash($req->get('pass'))); $user->set('email', $req->get('email')); //$user->set('register_key', $register_key); //-------------------------------------------- // Try to add this user. //-------------------------------------------- if($valid && $user->save()) { // add the role data //$user->setRole(2); // unconfirmed user $user->setRole(3); // member /* //-------------------------------------------- // Send them a confirmation email. //-------------------------------------------- $resp->assign('register_name', $user->get('name')); $resp->assign('confirmation_key', $register_key); $mail = &$this->getExtension('sendmail'); $msg = &$mail->getFinder('PHP'); //-------------------------------------------- // Make sure this mail layer exists. //-------------------------------------------- if($msg !== NULL) { $msg->asPlainText(); $msg->setTo($user->get('email'), $user->get('name')); $msg->setFrom('noreply@'. $this->getHost()); $msg->setSubject($this->informationText('Regsitration Confirmation')); $msg->setTemplates($resp, 'mail_register_message.html', 'mail_footer.html'); $msg->sendMessage(); } */ //-------------------------------------------- // successful registration //-------------------------------------------- $info->text('Thank you for registering.', '/', 3); } else { //-------------------------------------------- // Something went wrong when saving the new user, // look for errors and send them back to the registration form. //-------------------------------------------- $resp->assign('error_msg', TRUE); // Show the error message foreach ($user->getInvalid() as $invalid) { $resp->setError($invalid); } $this->index($reg, $req, $resp); } } } //-------------------------------------------- // Resend the confirmation email //-------------------------------------------- function resendemail(&$reg, &$req, &$resp) { $user = &$reg->get('user'); $this->informationPage('N/A'); } //-------------------------------------------- // Confirm an account with a special key supplied // in the url. //-------------------------------------------- function confirm(&$reg, &$req, &$resp) { $finder = &$this->getFinder('users'); //-------------------------------------------- // Try to get the user by their registration confirmation // key. //-------------------------------------------- $user = &$finder->findBy('register_key', $req->get('reg_key')); $info = &new InformationDisplay($reg, $req, $resp); //-------------------------------------------- // We've found the user! //-------------------------------------------- if($user !== NULL) { $user->set('register_key', NULL); $user->setRole(3); $user->save(); $info->text('Thank you for confirming your email with us.', '/', 3); } else { $info->text("We're sorry but that registration key doesn't seem to exist."); } } } ?>