protected function findProfile()
	{
		$adapter_profile = $this->getAdapterProfile();
		$ProfileModel = $this->config['db']['profilemodel'];
		$UserModel = $this->config['db']['usermodel'];
		$user = NULL;

		//check if the provider profile already exists
		$profile_builder = call_user_func_array(
			"$ProfileModel::where",
			array('provider', $this->provider)
		);

		if ($profile = $profile_builder->where('identifier', $adapter_profile->identifier)->first())
		{
			//we found an existing user
			$user = $profile->user()->first();
		}
		elseif ($adapter_profile->email)
		{
			//it's a new profile, but it may not be a new user, so check the users by email
			$user_builder = call_user_func_array(
				"$UserModel::where",
				array('email', $adapter_profile->email)
			);

			$user = $user_builder->first();
		}

		//if we haven't found a user, we need to create a new one
		if (!$user)
		{
			$user = new $UserModel();

			//map in anything from the profile that we want in the User
			$map = $this->config['db']['profiletousermap'];

			foreach ($map as $apkey => $ukey)
			{
				$user->$ukey = $adapter_profile->$apkey;
			}

			$values = $this->config['db']['uservalues'];

			foreach ($values as $key=>$value)
			{
				if (is_callable($value))
				{
					$user->$key = $value($user, $adapter_profile);
				}
				else
				{
					$user->$key = $value;
				}
			}

			//$user->username = $adapter_profile->email;
			$user->email = $adapter_profile->email;

			if (!$user->save($this->config['db']['userrules']))
			{
				return NULL;
			}
		}

		//if we didn't find the profile, we need to create a new one
		if (!$profile)
		{
			$profile = $this->createProfileFromAdapterProfile($adapter_profile, $user);
		}
		//if we did find a profile, make sure we update any changes to the source
		else
		{
			$profile = $this->applyAdapterProfileToExistingProfile($adapter_profile, $profile);
		}

		if (!$profile->save())
		{
			return NULL;
		}

		return $profile;
	}
protected function findProfile()
	{
		$adapter_profile = $this->getAdapterProfile();
		$ProfileModel = $this->config['db']['profilemodel'];
		$UserModel = $this->config['db']['usermodel'];
		$user = NULL;

		//check if the provider profile already exists
		$profile_builder = call_user_func_array(
			"$ProfileModel::where",
			array('provider', $this->provider)
		);

		if ($profile = $profile_builder->where('identifier', $adapter_profile->identifier)->first())
		{
			//we found an existing user
			$user = $profile->user()->first();
		}
		elseif ($adapter_profile->email)
		{
			//it's a new profile, but it may not be a new user, so check the users by email
			$user_builder = call_user_func_array(
				"$UserModel::where",
				array('email', $adapter_profile->email)
			);

			$user = $user_builder->first();
		}

		//if we haven't found a user, we need to create a new one
		if (!$user)
		{
			$user = new $UserModel();

			//map in anything from the profile that we want in the User
			$map = $this->config['db']['profiletousermap'];

			foreach ($map as $apkey => $ukey)
			{
				$user->$ukey = $adapter_profile->$apkey;
			}

			$values = $this->config['db']['uservalues'];

			foreach ($values as $key=>$value)
			{
				if (is_callable($value))
				{
					$user->$key = $value($user, $adapter_profile);
				}
				else
				{
					$user->$key = $value;
				}
			}

			//$user->username = $adapter_profile->email;
			$user->email = $adapter_profile->email;

			if (!$user->save($this->config['db']['userrules']))
			{
				return NULL;
			}
		}

		//if we didn't find the profile, we need to create a new one
		if (!$profile)
		{
			$profile = $this->createProfileFromAdapterProfile($adapter_profile, $user);
		}
		//if we did find a profile, make sure we update any changes to the source
		else
		{
			$profile = $this->applyAdapterProfileToExistingProfile($adapter_profile, $profile);
		}

		if (!$profile->save())
		{
			return NULL;
		}

		return $profile;
	}
protected function findProfile ( ) { $ adapter_profile = $ this -> getAdapterProfile ( ) ; $ ProfileModel = $ this -> config [ 'db' ] [ 'profilemodel' ] ; $ UserModel = $ this -> config [ 'db' ] [ 'usermodel' ] ; $ user = NULL ; //check if the provider profile already exists $ profile_builder = call_user_func_array ( "$ProfileModel::where" , array ( 'provider' , $ this -> provider ) ) ; if ( $ profile = $ profile_builder -> where ( 'identifier' , $ adapter_profile -> identifier ) -> first ( ) ) { //we found an existing user $ user = $ profile -> user ( ) -> first ( ) ; } elseif ( $ adapter_profile -> email ) { //it's a new profile, but it may not be a new user, so check the users by email $ user_builder = call_user_func_array ( "$UserModel::where" , array ( 'email' , $ adapter_profile -> email ) ) ; $ user = $ user_builder -> first ( ) ; } //if we haven't found a user, we need to create a new one if ( ! $ user ) { $ user = new $ UserModel ( ) ; //map in anything from the profile that we want in the User $ map = $ this -> config [ 'db' ] [ 'profiletousermap' ] ; foreach ( $ map as $ apkey => $ ukey ) { $ user -> $ ukey = $ adapter_profile -> $ apkey ; } $ values = $ this -> config [ 'db' ] [ 'uservalues' ] ; foreach ( $ values as $ key => $ value ) { if ( is_callable ( $ value ) ) { $ user -> $ key = $ value ( $ user , $ adapter_profile ) ; } else { $ user -> $ key = $ value ; } } //$user->username = $adapter_profile->email; $ user -> email = $ adapter_profile -> email ; if ( ! $ user -> save ( $ this -> config [ 'db' ] [ 'userrules' ] ) ) { return NULL ; } } //if we didn't find the profile, we need to create a new one if ( ! $ profile ) { $ profile = $ this -> createProfileFromAdapterProfile ( $ adapter_profile , $ user ) ; } //if we did find a profile, make sure we update any changes to the source else { $ profile = $ this -> applyAdapterProfileToExistingProfile ( $ adapter_profile , $ profile ) ; } if ( ! $ profile -> save ( ) ) { return NULL ; } return $ profile ; }
Finds a user's adapter profile

@return mixed
Finds a user s adapter profile