當前位置: 首頁>>代碼示例>>PHP>>正文


PHP UserTable::loadByUsername方法代碼示例

本文整理匯總了PHP中CB\Database\Table\UserTable::loadByUsername方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserTable::loadByUsername方法的具體用法?PHP UserTable::loadByUsername怎麽用?PHP UserTable::loadByUsername使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在CB\Database\Table\UserTable的用法示例。


在下文中一共展示了UserTable::loadByUsername方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: register

	/**
	 * Registers a new user
	 *
	 * @param UserTable           $user
	 * @param Hybrid_User_Profile $profile
	 * @return bool
	 */
	private function register( $user, $profile )
	{
		global $_CB_framework, $_PLUGINS, $ueConfig;

		if ( ! $profile->identifier ) {
			cbRedirect( $this->_returnUrl, CBTxt::T( 'PROVIDER_PROFILE_MISSING', '[provider] profile could not be found.', array( '[provider]' => $this->_providerName ) ), 'error' );
			return false;
		}

		$mode						=	$this->params->get( $this->_provider . '_mode', 1, GetterInterface::INT );
		$approve					=	$this->params->get( $this->_provider . '_approve', 0, GetterInterface::INT );
		$confirm					=	$this->params->get( $this->_provider . '_confirm', 0, GetterInterface::INT );
		$usergroup					=	$this->params->get( $this->_provider . '_usergroup', null, GetterInterface::STRING );
		$approval					=	( $approve == 2 ? $ueConfig['reg_admin_approval'] : $approve );
		$confirmation				=	( $confirm == 2 ? $ueConfig['reg_confirmation'] : $confirm );
		$usernameFormat				=	$this->params->get( $this->_provider . '_username', null, GetterInterface::STRING );
		$username					=	null;
		$dummyUser					=	new UserTable();

		if ( $usernameFormat ) {
			$extras					=	array( 'provider' => $this->_provider, 'provider_id' => $this->_providerId, 'provider_name' => $this->_providerName );

			foreach ( (array) $profile as $k => $v ) {
				if ( ( ! is_array( $v ) ) && ( ! is_object( $v ) ) ) {
					$k				=	'profile_' . $k;

					$extras[$k]		=	$v;
				}
			}

			$username				=	preg_replace( '/[<>\\\\"%();&\']+/', '', trim( cbReplaceVars( $usernameFormat, $user, true, false, $extras, false ) ) );
		} else {
			if ( isset( $profile->username ) ) {
				$username			=	preg_replace( '/[<>\\\\"%();&\']+/', '', trim( $profile->username ) );
			}

			if ( ( ! $username ) || ( $username && $dummyUser->loadByUsername( $username ) ) ) {
				$username			=	preg_replace( '/[<>\\\\"%();&\']+/', '', trim( $profile->displayName ) );
			}
		}

		if ( ( ! $username ) || ( $username && $dummyUser->loadByUsername( $username ) ) ) {
			$username				=	(string) $profile->identifier;
		}

		if ( $mode == 2 ) {
			$user->set( 'email', $profile->email );
		} else {
			if ( $dummyUser->loadByUsername( $username ) ) {
				cbRedirect( $this->_returnUrl, CBTxt::T( 'UE_USERNAME_NOT_AVAILABLE', "The username '[username]' is already in use.", array( '[username]' =>  htmlspecialchars( $username ) ) ), 'error' );
				return false;
			}

			if ( ! $this->email( $user, $profile ) ) {
				return false;
			}

			if ( $dummyUser->loadByEmail( $user->get( 'email' ) ) ) {
				cbRedirect( $this->_returnUrl, CBTxt::T( 'UE_EMAIL_NOT_AVAILABLE', "The email '[email]' is already in use.", array( '[email]' =>  htmlspecialchars( $user->get( 'email' ) ) ) ), 'error' );
				return false;
			}

			$this->avatar( $user, $profile, $mode );

			if ( ! $usergroup ) {
				$gids				=	array( (int) $_CB_framework->getCfg( 'new_usertype' ) );
			} else {
				$gids				=	cbToArrayOfInt( explode( '|*|', $usergroup ) );
			}

			$user->set( 'gids', $gids );
			$user->set( 'sendEmail', 0 );
			$user->set( 'registerDate', $_CB_framework->getUTCDate() );
			$user->set( 'password', $user->hashAndSaltPassword( $user->getRandomPassword() ) );
			$user->set( 'registeripaddr', cbGetIPlist() );

			if ( $approval == 0 ) {
				$user->set( 'approved', 1 );
			} else {
				$user->set( 'approved', 0 );
			}

			if ( $confirmation == 0 ) {
				$user->set( 'confirmed', 1 );
			} else {
				$user->set( 'confirmed', 0 );
			}

			if ( ( $user->get( 'confirmed' ) == 1 ) && ( $user->get( 'approved' ) == 1 ) ) {
				$user->set( 'block', 0 );
			} else {
				$user->set( 'block', 1 );
			}
//.........這裏部分代碼省略.........
開發者ID:kosmosby,項目名稱:medicine-prof,代碼行數:101,代碼來源:component.cbconnect.php

示例2: login

 /**
  * Logins on host CMS using any allowed authentication methods
  *
  * @param  string          $username        The username
  * @param  string|boolean  $password        Well, The password OR strictly boolean false for login without password
  * @param  boolean         $rememberMe      If login should be remembered in a cookie to be sent back to user's browser
  * @param  boolean         $message         If an alert message should be prepared on successful login
  * @param  string          $return          IN & OUT: IN: return URL NOT SEFED for normal login completition (unless an event says different), OUT: redirection url (no htmlspecialchars) NOT SEFED
  * @param  array           $messagesToUser  OUT: messages to display to user (html)
  * @param  array           $alertMessages   OUT: messages to alert to user (text)
  * @param  int             $loginType       0: username, 1: email, 2: username or email, 3: username, email or CMS authentication
  * @param  string          $secretKey       secretKey used for two step authentication
  * @return string                           Error message if error
  */
 public function login($username, $password, $rememberMe, $message, &$return, &$messagesToUser, &$alertMessages, $loginType = 0, $secretKey = null)
 {
     global $_CB_framework, $ueConfig, $_PLUGINS;
     $returnURL = null;
     $loggedIn = false;
     if (!$username || !$password && $password !== false) {
         $resultError = CBTxt::T('LOGIN_INCOMPLETE', 'Please complete the username and password fields.');
     } else {
         $_PLUGINS->loadPluginGroup('user');
         $_PLUGINS->trigger('onBeforeLogin', array(&$username, &$password, &$secretKey));
         $resultError = null;
         $showSysMessage = true;
         $stopLogin = false;
         $firstLogin = false;
         $row = new UserTable();
         if ($_PLUGINS->is_errors()) {
             $resultError = $_PLUGINS->getErrorMSG();
         } else {
             $foundUser = false;
             // Try login by CB authentication trigger:
             $_PLUGINS->trigger('onLoginAuthentication', array(&$username, &$password, &$row, $loginType, &$foundUser, &$stopLogin, &$resultError, &$messagesToUser, &$alertMessages, &$return, &$secretKey));
             if (!$foundUser) {
                 if ($loginType != 2) {
                     // login by username:
                     $foundUser = $row->loadByUsername($username) && ($password === false || $row->verifyPassword($password));
                 }
                 if (!$foundUser && $loginType >= 1) {
                     // login by email:
                     $foundUser = $row->loadByEmail($username) && ($password === false || $row->verifyPassword($password));
                     if ($foundUser) {
                         $username = $row->username;
                     }
                 }
                 if (!$foundUser && $loginType > 2) {
                     // If no result, try login by CMS authentication:
                     if ($_CB_framework->login($username, $password, $rememberMe, null, $secretKey)) {
                         $foundUser = $row->load((int) $_CB_framework->myId());
                         // core user might not have username set, so we use id (bug #3303 fix)
                         $this->cbSplitSingleName($row);
                         $row->confirmed = 1;
                         $row->approved = 1;
                         $row->store();
                         // synchronizes with comprofiler table
                         $loggedIn = true;
                     }
                 }
             }
             if ($foundUser) {
                 $returnPluginsOverrides = null;
                 $pluginResults = $_PLUGINS->trigger('onDuringLogin', array(&$row, 1, &$returnPluginsOverrides));
                 if ($returnPluginsOverrides) {
                     $return = $returnPluginsOverrides;
                 }
                 if (is_array($pluginResults) && count($pluginResults)) {
                     foreach ($pluginResults as $res) {
                         if (is_array($res)) {
                             if (isset($res['messagesToUser'])) {
                                 $messagesToUser[] = $res['messagesToUser'];
                             }
                             if (isset($res['alertMessage'])) {
                                 $alertMessages[] = $res['alertMessage'];
                             }
                             if (isset($res['showSysMessage'])) {
                                 $showSysMessage = $showSysMessage && $res['showSysMessage'];
                             }
                             if (isset($res['stopLogin'])) {
                                 $stopLogin = $stopLogin || $res['stopLogin'];
                             }
                         }
                     }
                 }
                 if ($_PLUGINS->is_errors()) {
                     $resultError = $_PLUGINS->getErrorMSG();
                 } elseif ($stopLogin) {
                     // login stopped: don't even check for errors...
                 } elseif ($row->approved == 2) {
                     $resultError = CBTxt::T('LOGIN_REJECTED', 'Your sign up request was rejected!');
                 } elseif ($row->confirmed != 1) {
                     if ($row->cbactivation == '') {
                         $row->store();
                         // just in case the activation code was missing
                     }
                     $cbNotification = new cbNotification();
                     $cbNotification->sendFromSystem($row->id, CBTxt::T(stripslashes($ueConfig['reg_pend_appr_sub'])), CBTxt::T(stripslashes($ueConfig['reg_pend_appr_msg'])), true, isset($ueConfig['reg_email_html']) ? (int) $ueConfig['reg_email_html'] : 0);
                     $resultError = CBTxt::T('LOGIN_NOT_CONFIRMED', 'Your sign up process is not yet complete! Please check again your email for further instructions that have just been resent. If you don\'t find the email, check your spam-box. Make sure that your email account options are not set to immediately delete spam. If that was the case, just try logging in again to receive a new instructions email.');
                 } elseif ($row->approved == 0) {
//.........這裏部分代碼省略.........
開發者ID:Raul-mz,項目名稱:web-erpcya,代碼行數:101,代碼來源:CBAuthentication.php

示例3: login

 /**
  * User login into CMS framework
  *
  * @param  string          $username    The username
  * @param  string|boolean  $password    if boolean FALSE: login without password if possible
  * @param  int             $rememberMe  1 for "remember-me" cookie method
  * @param  int             $userId      used for "remember-me" login function only
  * @param  string          $secretKey   used for "two step authentication" login function only
  * @return boolean                      Login success
  */
 public function login($username, $password, $rememberMe = 0, $userId = null, $secretKey = null)
 {
     header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
     // needed for IE6 to accept this anti-spam cookie in higher security setting.
     if ($password !== false) {
         $result = $this->_baseFramework->login(array('username' => $username, 'password' => $password, 'secretkey' => $secretKey), array('remember' => $rememberMe));
     } else {
         // login without password:
         jimport('joomla.user.authentication');
         // load user plugins:
         JPluginHelper::importPlugin('user');
         // get JAuthentication object:
         JAuthentication::getInstance();
         $dispatcher = JDispatcher::getInstance();
         // 2.5 has only JDispatcher. Only 3.0 introduced JEventDispatcher
         $response = new JAuthenticationResponse();
         // prepare our SUCCESS login response including user data:
         $row = new UserTable();
         $row->loadByUsername(stripslashes($username));
         $response->status = JAuthentication::STATUS_SUCCESS;
         $response->username = $username;
         $response->fullname = $row->name;
         // now we attempt user login and check results:
         $login = $dispatcher->trigger('onUserLogin', array((array) $response, array('action' => 'core.login.site')));
         $result = !in_array(false, $login, true);
     }
     return $result;
 }
開發者ID:bobozhangshao,項目名稱:HeartCare,代碼行數:38,代碼來源:CBframework.php

示例4: sendNewPass

function sendNewPass($option)
{
    global $_CB_framework, $ueConfig, $_PLUGINS, $_POST;
    $loginType = isset($ueConfig['login_type']) ? (int) $ueConfig['login_type'] : 0;
    if ($loginType == 4) {
        cbRedirect($_CB_framework->viewUrl('done', false), CBTxt::Th('UE_NOT_AUTHORIZED', 'You are not authorized to view this page!'), 'error');
        return;
    }
    // simple spoof check security
    checkCBPostIsHTTPS();
    cbSpoofCheck('lostPassForm');
    cbRegAntiSpamCheck();
    $liveSite = $_CB_framework->getCfg('live_site');
    $usernameExists = $loginType != 2;
    // ensure no malicous sql gets past
    $checkusername = trim(cbGetParam($_POST, 'checkusername', ''));
    $confirmEmail = trim(cbGetParam($_POST, 'checkemail', ''));
    $_PLUGINS->loadPluginGroup('user');
    $_PLUGINS->trigger('onStartNewPassword', array(&$checkusername, &$confirmEmail));
    if ($_PLUGINS->is_errors()) {
        cbRedirect($_CB_framework->viewUrl('lostpassword', false), $_PLUGINS->getErrorMSG(), 'error');
        return;
    }
    $checkusername = stripslashes($checkusername);
    $confirmEmail = stripslashes($confirmEmail);
    $res = false;
    $error = null;
    if ($usernameExists && $confirmEmail != '' && !$checkusername) {
        $user = new UserTable();
        if (!$user->loadByEmail($confirmEmail)) {
            cbRedirect($_CB_framework->viewUrl('lostpassword', false), CBTxt::Th('UE_EMAIL_DOES_NOT_EXISTS_ON_SITE', "The email '[email]' does not exist on this site.", array('[email]' => htmlspecialchars($confirmEmail))), 'error');
        }
        $message = str_replace('\\n', "\n", sprintf(CBTxt::T('UE_USERNAMEREMINDER_MSG', 'Hello,\\nA username reminder has been requested for your %s account.\\n\\nYour username is: %s\\n\\nTo log in to your account, click on the link below:\\n%s\\n\\nThank you.\\n'), $_CB_framework->getCfg('sitename'), $user->username, $liveSite));
        /*
        'Hello,\n'
        .'A username reminder has been requested for your %s account.\n\n'
        .'Your username is: %s\n\n'
        .'To log in to your account, click on the link below:\n'
        .'%s\n\n'
        .'Thank you.\n'
        */
        $subject = sprintf(CBTxt::T('UE_USERNAMEREMINDER_SUB', 'Username reminder for %s'), $user->username);
        $_PLUGINS->trigger('onBeforeUsernameReminder', array($user, &$subject, &$message));
        if ($_PLUGINS->is_errors()) {
            cbRedirect($_CB_framework->viewUrl('lostpassword', false), $_PLUGINS->getErrorMSG(), 'error');
            return;
        }
        $cbNotification = new cbNotification();
        $res = $cbNotification->sendFromSystem($user->id, $subject, $message);
        $error = $cbNotification->errorMSG;
        $_PLUGINS->trigger('onAfterUsernameReminder', array($user, &$res));
        if ($res) {
            cbRedirect($_CB_framework->viewUrl('done', false), sprintf(CBTxt::Th('UE_USERNAME_REMINDER_SENT', 'Username reminder sent to your email address %s. Please check your email (and if needed your spambox too)!'), htmlspecialchars($confirmEmail)));
        } else {
            cbRedirect($_CB_framework->viewUrl('done', false), $error ? CBTxt::Th('SENDING_EMAIL_FAILED_ERROR_ERROR', 'Sending Email Failed! Error: [error]', array('[error]' => $error)) : CBTxt::Th('UE_EMAIL_SENDING_ERROR', 'Error sending email'), 'error');
        }
    } elseif ($confirmEmail != '') {
        $user = new UserTable();
        if ($usernameExists) {
            $foundUser = $user->loadByUsername($checkusername);
            if ($foundUser && cbutf8_strtolower($user->email) != cbutf8_strtolower($confirmEmail)) {
                $foundUser = false;
            }
        } else {
            $foundUser = $user->loadByEmail($confirmEmail);
        }
        if (!$foundUser) {
            cbRedirect($_CB_framework->viewUrl('lostpassword', false), CBTxt::Th('ERROR_PASS', 'Sorry, no corresponding user was found'), 'error');
        }
        $resetTime = (int) $_CB_framework->getCfg('reset_time');
        $resetCount = (int) $_CB_framework->getCfg('reset_count');
        $hoursSinceLastReset = ($_CB_framework->getUTCNow() - (int) $_CB_framework->getUTCTimestamp($user->lastResetTime)) / 3600;
        if ($hoursSinceLastReset > $resetTime) {
            $user->lastResetTime = $_CB_framework->getUTCDate();
            $user->resetCount = 1;
        } else {
            $user->resetCount = $user->resetCount + 1;
        }
        if ($resetCount && $user->resetCount > $resetCount) {
            cbRedirect($_CB_framework->viewUrl('lostpassword', false), CBTxt::Th('EXCEEDED_MAXIMUM_PASSWORD_RESETS', 'You have exceeded the maximum number of password resets allowed. Please try again in %%COUNT%% hours.|You have exceeded the maximum number of password resets allowed. Please try again in 1 hour.', array('%%COUNT%%' => $resetTime)), 'error');
        }
        $newpass = $user->getRandomPassword();
        $message = str_replace('\\n', "\n", sprintf(CBTxt::T('UE_NEWPASS_MSG', 'The user account %s has this email associated with it.\\nA web user from %s has just requested that a new password be sent.\\n\\nYour New Password is: %s\\n\\nIf you didn\'t ask for this, don\'t worry. You are seeing this message, not them. If this was an error just log in with your new password and then change your password to what you would like it to be.'), $user->username, $liveSite, $newpass));
        /*
        'The user account %s has this email associated with it.\n'
        .'A web user from %s has just requested that a new password be sent.\n\n'
        .'Your New Password is: %s\n\n'
        .'If you didn\'t ask for this, don\'t worry. You are seeing this message, not them. If this was an error just log in with your new password and then change your password to what you would like it to be.'
        */
        $subject = sprintf(CBTxt::T('UE_NEWPASS_SUB', 'New password for: %s'), $user->username);
        $_PLUGINS->trigger('onBeforeNewPassword', array($user, &$newpass, &$subject, &$message));
        if ($_PLUGINS->is_errors()) {
            cbRedirect($_CB_framework->viewUrl('lostpassword', false), $_PLUGINS->getErrorMSG(), 'error');
        }
        $_PLUGINS->trigger('onNewPassword', array($user, $newpass));
        $storeValues = array('password' => $newpass, 'lastResetTime' => $user->lastResetTime, 'resetCount' => $user->resetCount);
        if (!$user->storeDatabaseValues($storeValues)) {
            cbRedirect($_CB_framework->viewUrl('lostpassword', false), $user->getError(), 'error');
        } else {
            $cbNotification = new cbNotification();
//.........這裏部分代碼省略.........
開發者ID:ankaau,項目名稱:GathBandhan,代碼行數:101,代碼來源:comprofiler.php


注:本文中的CB\Database\Table\UserTable::loadByUsername方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。