Ejemplo n.º 1
0
 /**
  * register
  */
 public function register()
 {
     // check for request forgeries
     $this->app->zlfw->checkToken();
     // init vars
     $success = false;
     $response = array('errors' => array(), 'notices' => array());
     $data = array();
     $data['username'] = trim($this->app->request->getString('username'));
     $data['password'] = trim($this->app->request->getString('password'));
     $data['password2'] = trim($this->app->request->getString('password2'));
     $data['email'] = trim($this->app->request->getString('email'));
     $data['name'] = trim($this->app->request->getString('name'));
     $errors = array();
     if (!strlen($data['username'])) {
         $errors[] = JText::_('PLG_ZLFRAMEWORK_USERNAME_REQUIRED');
     }
     if (!strlen($data['password'])) {
         $errors[] = JText::_('PLG_ZLFRAMEWORK_PASSWORD_REQUIRED');
     }
     if (!strlen($data['email'])) {
         $errors[] = JText::_('PLG_ZLFRAMEWORK_EMAIL_REQUIRED');
     }
     if ($data['password'] != $data['password2']) {
         $errors[] = JText::_('PLG_ZLFRAMEWORK_PASSWORDS_MUST_MATCH');
     }
     if (!count($errors)) {
         $password = $data['password'];
         $user = new JUser();
         $user->id = 0;
         $user->bind($data);
         $user->groups = array(JComponentHelper::getParams('com_users')->get('new_usertype', 2));
         $success = $user->save();
         if (!$success) {
             $errors = $user->getErrors();
         } else {
             JFactory::getApplication()->login(array('username' => $data['username'], 'password' => $password));
         }
     }
     // set and return results
     $response['success'] = $success;
     $response['errors'] = $errors;
     echo json_encode($response);
     exit;
 }
Ejemplo n.º 2
0
	/**
	 * Testing creation and deletion of users
	 *
	 * @return void
	 */
	public function testCreateDeleteUser()
	{
		include_once JPATH_BASE . '/libraries/joomla/event/dispatcher.php';
		include_once JPATH_BASE . '/libraries/joomla/plugin/helper.php';
		include_once JPATH_BASE . '/libraries/joomla/application/application.php';

		//JFactory::getApplication('site');
		$mockSession = $this->getMock('JSession', array('_start', 'get'));
		$mockSession->expects($this->any())
			->method('get')
			->will($this->returnValue($this->object)
		);
		JFactory::$session = $mockSession;

		$testUser = new JUser();
		$testUser->name = "Floyd Smoot";
		$testUser->username = "******";

		$this->assertThat(
			$testUser->id,
			$this->equalTo(0),
			"Newly created id should be zero"
		);

		$this->assertThat(
			$testUser->save(),
			$this->isFalse(),
			'Cannot save without valid email'
		);

		$this->assertThat(
			$testUser->getErrors(),
			$this->equalTo(
				array('JLIB_DATABASE_ERROR_VALID_MAIL')
			),
			'Should have caused valid email error'
		);

		$testUser->email = "*****@*****.**";
		//TODO: Fix this assertion
		$this->assertThat(
			$testUser->save(true),
			// Should be false
			$this->isTrue(),
			'Line: ' . __LINE__ . ' Should not create new user when update only flag is set'
		);

		//TODO: Fix this assertion
		$this->assertThat(
			$testUser->save(),
			// Should be true
			$this->isFalse(),
			'Line: ' . __LINE__ . ' Should save the user successfully'
		);

		$this->assertThat(
			$testUser->id,
			$this->greaterThan(0),
			'Line: ' . __LINE__ . " Newly saved id should not be zero"
		);

		$testUser->email = "*****@*****.**";
		//TODO: Fix this assertion
		$this->assertThat(
			$testUser->save(),
			// Should be true
			$this->isFalse(),
			'Line: ' . __LINE__ . ' Should update existing user.'
		);

		$testUser1 = JUser::getInstance('Floyd');
		$this->assertThat(
			$testUser1->id,
			$this->equalTo($testUser1->id),
			'Line: ' . __LINE__ . " Id's should be the same"
		);

		$this->assertThat(
			$testUser->delete(),
			$this->isTrue(),
			'Line: ' . __LINE__ . ' Delete should succeed'
		);

		$testUser2 = JUser::getInstance('Floyd');
		$this->assertThat(
			$testUser2,
			$this->isFalse(),
			'Line: ' . __LINE__ . " Id should not be found"
		);

	}
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*');
$query->from('walkleaders');
$query->where('active')->where('joomlauser IS NULL')->where("loginid <> ''")->where("Email <> ''");
$db->setQuery($query);
$leaders = $db->loadAssocList();
$created = 0;
$failed = 0;
foreach ($leaders as $leader) {
    try {
        $user = new JUser();
        $userinfo = array("email" => $leader['Email'], "name" => $leader['Forename'] . " " . $leader['Surname'], "password" => "badgerx3", "username" => $leader['loginid'], "swg_extras" => array("leaderid" => $leader['ID']));
        // Get the default new user group, Registered if not specified.
        $userinfo['groups'] = array(1, 2, 13);
        // NOTE: Hardcoded - public, registered, leaders
        $user->bind($userinfo);
        if ($user->save()) {
            $created++;
        } else {
            $failed++;
        }
    } catch (Exception $e) {
        echo $e->getTraceAsString();
    }
    foreach ($user->getErrors() as $error) {
        echo $leader['loginid'] . ": " . $error . "<br />";
    }
}
printf("%d created, %d failed", $created, $failed);
die;