public function registerAction() { //Check to see if user is already login if ($this->loggedEmail) { $this->_redirect('/'); return; } //get referrer $ns = new Zend_Session_Namespace('referrer'); $this->view->referby = $ns->referrer; if ($this->getRequest()->isPost()) { //Validation // Valid email address? if (!Zend_Validate::is($this->_request->getPost('email'), 'EmailAddress') && $this->_request->getPost('email') != 'me2@localhost') { $this->view->errors[] = "Invalid e-mail address."; } //E-mail cannot already exist in the database $user = new Default_Model_User(); $foundUser = $user->getUserByEmail($this->_request->getPost('email')); if (isset($foundUser->id)) { $this->view->errors[] = "Email address already in database."; } //Handle must be between 2-20 characters $validator = new Zend_Validate_StringLength(2, 20); if (!$validator->isValid($this->_request->getPost('handle'))) { $this->view->errors[] = "Handle must be between 2 and 14 characters."; } // Handle must consist solely of alphanumeric characters $validHandle = new Zend_Validate_Alnum(); if (!$validHandle->isValid($this->_request->getPost('handle'))) { $this->view->errors[] = "Handle must consist of letters and numbers."; } // end valid handle // Handle cannot already exist in database $foundUser = $user->getUserByHandle($this->_request->getPost('handle')); if (isset($foundUser->id)) { $this->view->errors[] = "Handle already exists in database."; } // Password must between 6 to 20 characters $validPswd = new Zend_Validate_StringLength(6, 20); if (!$validPswd->isValid($this->_request->getPost('password'))) { $this->view->errors[] = "Password must be at least 6 characters."; } // end valid password // First name must not be empty $validFirstName = new Zend_Validate_NotEmpty(); if (!$validFirstName->isValid($this->_request->getPost('first_name'))) { $this->view->errors[] = "Please provide your first name."; } // end valid first name // Last name must not be empty $validLastName = new Zend_Validate_NotEmpty(); if (!$validLastName->isValid($this->_request->getPost('last_name'))) { $this->view->errors[] = "Please provide your last name."; } // end valid last name // Valid gender? if (!Zend_Validate::is($this->_request->getPost('gender'), 'NotEmpty')) { $this->view->errors[] = "Please identify your gender."; } // end valid gender //Address not empty? if (!Zend_Validate::is($this->_request->getPost('address'), 'NotEmpty')) { $this->view->errors[] = "Please enter your address."; } //if errors exist, prepopulate the form if (count($this->view->errors) > 0) { $this->view->email = $this->_request->getPost('email'); $this->view->handle = $this->_request->getPost('handle'); $this->view->first_name = $this->_request->getPost('first_name'); $this->view->last_name = $this->_request->getPost('last_name'); $this->view->gender = $this->_request->getPost('gender'); $this->view->address = $this->_request->getPost('address'); } else { //No errors, add user to the database and send confirmation e-mail //Generate random keys used for registration confirmation $registrationKey = $this->_helper->generator(32, 'alpha'); // Prepare the data array for database insertion $data = array('email' => $this->_request->getPost('email'), 'password' => md5($this->_request->getPost('password')), 'registration_key' => $registrationKey, 'handle' => $this->_request->getPost('handle'), 'first_name' => $this->_request->getPost('first_name'), 'last_name' => $this->_request->getPost('last_name'), 'gender' => $this->_request->getPost('gender'), 'address' => $this->_request->getPost('address'), 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), 'last_login' => date('Y-m-d H:i:s'), 'referby' => $this->_request->getPost('referrer')); //Create a new mail object try { $mail = new Zend_Mail(); // Set the From, To, and Subject headers $mail->setFrom($this->config->email->from_admin); $mail->addTo($this->_request->getPost('email'), "{$this->_request->getPost('first_name')}\n\t\t\t\t\t {$this->_request->getPost('last_name')}"); $mail->setSubject('Your game account has been created'); // Retrieve the e-mail template include "emailTemplates/_email-confirm-registration.phtml"; // Attach the e-mail template to the e-mail and send it $mail->setBodyText($email); $mail->send(); $this->view->success = 1; } catch (Exception $e) { $this->view->errors[] = "We were unable to send your confirmation \t\t\n\t\t\t\t\t\t e-mail.\n\t\t\t\t\tPlease contact {$this->config->email->support}."; } //If succcessful at sending mail, insert into database if ($this->view->success == 1) { // Insert the registration data into the database $user = new Default_Model_User(); $user->insert($data); } } //end else (w/ no errors) } //end if isPost() }