当前位置: 首页>>代码示例>>PHP>>正文


PHP JUser::getErrors方法代码示例

本文整理汇总了PHP中JUser::getErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP JUser::getErrors方法的具体用法?PHP JUser::getErrors怎么用?PHP JUser::getErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JUser的用法示例。


在下文中一共展示了JUser::getErrors方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: register

 /**
  * 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;
 }
开发者ID:knigherrant,项目名称:decopatio,代码行数:48,代码来源:cart.php

示例2: testCreateDeleteUser

	/**
	 * 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 = "Floyd";

		$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 = "harry@sally.com";
		//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 = "sally@harry.com";
		//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"
		);

	}
开发者ID:realityking,项目名称:JAJAX,代码行数:96,代码来源:JUserTest.php

示例3: JUser

$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;
开发者ID:SheffieldWalkingGroup,项目名称:swgwebsite,代码行数:31,代码来源:registerleaders.php


注:本文中的JUser::getErrors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。