/** * Create a new account. * * @return */ public function executeCreate($request) { if ($request->getMethod() != coreRequest::POST) { // setup form // development /* if (CORE_ENVIRONMENT==='dev') { $request->getParameterHolder()->add(array( 'username' => '...' . rand(1,1000), 'email' => '...', 'password'=>'xxxxx', 'password2'=>'xxxxx', 'location'=>'Foo Bar') ); }*/ } else { $validator = new coreValidator($this->getActionName()); if ($validator->validate($request->getParameterHolder()->getAll())) { $this->username = trim($request->getParameter('username')); $raw_password = trim($request->getParameter('password')); if (UsersPeer::usernameExists($this->username)) { $request->setError('username_duplicate', 'Sorry, that username is already taken, please pick another one.'); return coreView::SUCCESS; } $userinfo = array('username' => trim($request->getParameter('username')), 'password' => $this->getUser()->getSaltyHashedPassword($raw_password), 'email' => trim($request->getParameter('email')), 'location' => trim($request->getParameter('location', ''))); // username is available, create user UsersPeer::createUser($userinfo); // create user on the PunBB forum with same username and password // NOT IN STAGING -- staging does not have a "test" forum database if (coreContext::getInstance()->getConfiguration()->getEnvironment() !== 'staging' && coreConfig::get('app_path_to_punbb') !== null) { try { $forumAccountSuccess = PunBBUsersPeer::createAccount($userinfo); } catch (coreException $e) { $forumAccountSuccess = false; } if (!$forumAccountSuccess) { $url = $this->getController()->genUrl('@contact'); $request->setError('forum_account', 'Oops, there was a problem while accessing the forum database.<br/>' . 'Please <a href="' . $url . '">contact the webmaster</a> with your username and password,<br/>' . 'and we will create your forum account as soon as possible.'); } } else { // STAGING $forumAccountSuccess = false; $request->setError('forum_account', '(Forum account NOT created in test environment)'); } // send email confirmation $mailer = new rtkMail(); $mailer->sendNewAccountConfirmation($userinfo['email'], $userinfo['username'], $raw_password); return 'Done'; } } }
public function init() { parent::init(); // Verify we're on the correct database //print_r(coreConfig::get('database_connection'));exit; $connectionInfo = coreConfig::get('database_connection'); $this->verbose("Using database: %s", $connectionInfo['database']); $username = trim($this->getOption('username')); $raw_password = trim($this->getOption('password')); if (empty($username) || empty($raw_password)) { $this->throwError('Username or password is empty.'); } if (UsersPeer::usernameExists($username)) { $this->throwError('That username already exists, foo!'); } $this->createUser($username, $raw_password); $this->verbose('Success!'); }