public function finished(SS_HTTPRequest $request) {

		$opauth = OpauthAuthenticator::opauth(false);

		$response = $this->getOpauthResponse();

		if (!$response) {
			$response = array();
		}
		// Clear the response as it is only to be read once (if Session)
		Session::clear('opauth');

		// Handle all Opauth validation in this handy function
		try {
			$this->validateOpauthResponse($opauth, $response);
		}
		catch(OpauthValidationException $e) {
			return $this->handleOpauthException($e);
		}

		$identity = OpauthIdentity::factory($response);

		$member = $identity->findOrCreateMember();

		// If the member exists, associate it with the identity and log in
		if($member->isInDB() && $member->validate()->valid()) {
			if(!$identity->exists()) {
				$identity->write();
				$flag = self::AUTH_FLAG_LINK;
			}
			else {
				$flag = self::AUTH_FLAG_LOGIN;
			}

			Session::set('OpauthIdentityID', $identity->ID);
		}
		else {

			$flag = self::AUTH_FLAG_REGISTER;

			// Write the identity
			$identity->write();

			// Keep a note of the identity ID
			Session::set('OpauthIdentityID', $identity->ID);

			// Even if written, check validation - we might not have full fields
			$validationResult = $member->validate();
			if(!$validationResult->valid()) {
				// Set up the register form before it's output
				$regForm = $this->RegisterForm();
				$regForm->loadDataFrom($member);
				$regForm->setSessionData($member);
				$regForm->validate();
				return $this->redirect($this->Link('profilecompletion'));
			}
			else {
				$member->extend('onBeforeOpauthRegister');
				$member->write();
				$identity->MemberID = $member->ID;
				$identity->write();
			}
		}
		return $this->loginAndRedirect($member, $identity, $flag);
	}
public function finished(SS_HTTPRequest $request) {

		$opauth = OpauthAuthenticator::opauth(false);

		$response = $this->getOpauthResponse();

		if (!$response) {
			$response = array();
		}
		// Clear the response as it is only to be read once (if Session)
		Session::clear('opauth');

		// Handle all Opauth validation in this handy function
		try {
			$this->validateOpauthResponse($opauth, $response);
		}
		catch(OpauthValidationException $e) {
			return $this->handleOpauthException($e);
		}

		$identity = OpauthIdentity::factory($response);

		$member = $identity->findOrCreateMember();

		// If the member exists, associate it with the identity and log in
		if($member->isInDB() && $member->validate()->valid()) {
			if(!$identity->exists()) {
				$identity->write();
				$flag = self::AUTH_FLAG_LINK;
			}
			else {
				$flag = self::AUTH_FLAG_LOGIN;
			}

			Session::set('OpauthIdentityID', $identity->ID);
		}
		else {

			$flag = self::AUTH_FLAG_REGISTER;

			// Write the identity
			$identity->write();

			// Keep a note of the identity ID
			Session::set('OpauthIdentityID', $identity->ID);

			// Even if written, check validation - we might not have full fields
			$validationResult = $member->validate();
			if(!$validationResult->valid()) {
				// Set up the register form before it's output
				$regForm = $this->RegisterForm();
				$regForm->loadDataFrom($member);
				$regForm->setSessionData($member);
				$regForm->validate();
				return $this->redirect($this->Link('profilecompletion'));
			}
			else {
				$member->extend('onBeforeOpauthRegister');
				$member->write();
				$identity->MemberID = $member->ID;
				$identity->write();
			}
		}
		return $this->loginAndRedirect($member, $identity, $flag);
	}
public function finished ( SS_HTTPRequest $ request ) { $ opauth = OpauthAuthenticator :: opauth ( false ) ; $ response = $ this -> getOpauthResponse ( ) ; if ( ! $ response ) { $ response = array ( ) ; } // Clear the response as it is only to be read once (if Session) Session :: clear ( 'opauth' ) ; // Handle all Opauth validation in this handy function try { $ this -> validateOpauthResponse ( $ opauth , $ response ) ; } catch ( OpauthValidationException $ e ) { return $ this -> handleOpauthException ( $ e ) ; } $ identity = OpauthIdentity :: factory ( $ response ) ; $ member = $ identity -> findOrCreateMember ( ) ; // If the member exists, associate it with the identity and log in if ( $ member -> isInDB ( ) && $ member -> validate ( ) -> valid ( ) ) { if ( ! $ identity -> exists ( ) ) { $ identity -> write ( ) ; $ flag = self :: AUTH_FLAG_LINK ; } else { $ flag = self :: AUTH_FLAG_LOGIN ; } Session :: set ( 'OpauthIdentityID' , $ identity -> ID ) ; } else { $ flag = self :: AUTH_FLAG_REGISTER ; // Write the identity $ identity -> write ( ) ; // Keep a note of the identity ID Session :: set ( 'OpauthIdentityID' , $ identity -> ID ) ; // Even if written, check validation - we might not have full fields $ validationResult = $ member -> validate ( ) ; if ( ! $ validationResult -> valid ( ) ) { // Set up the register form before it's output $ regForm = $ this -> RegisterForm ( ) ; $ regForm -> loadDataFrom ( $ member ) ; $ regForm -> setSessionData ( $ member ) ; $ regForm -> validate ( ) ; return $ this -> redirect ( $ this -> Link ( 'profilecompletion' ) ) ; } else { $ member -> extend ( 'onBeforeOpauthRegister' ) ; $ member -> write ( ) ; $ identity -> MemberID = $ member -> ID ; $ identity -> write ( ) ; } } return $ this -> loginAndRedirect ( $ member , $ identity , $ flag ) ; }
Equivalent to "callback.php" in the Opauth package.
If there is a problem with the response, we throw an HTTP error.
When done validating, we return back to the Authenticator continue auth.
@throws SS_HTTPResponse_Exception if any validation errors
Equivalent to callback . php in the Opauth package . If there is a problem with the response we throw an HTTP error . When done validating we return back to the Authenticator continue auth .