PHP code example of silverstripe / realme
1. Go to this page and download the library: Download silverstripe/realme library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
silverstripe / realme example snippets
use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\RealMe\RealMeService;
class RealMeTestController extends Controller {
/**
* @var RealMeService
*/
public $realMeService;
private static $dependencies = array(
'realMeService' => '%$SilverStripe\RealMe\RealMeService'
);
public function index(HTTPRequest $request) {
// enforceLogin will redirect the user to RealMe if they're not authenticated, or return true if they are
// authenticated with RealMe. It should only ever return 'false' if there was an error initialising config
if($this->realMeService->enforceLogin($request)) {
$userData = $this->realMeService->getUserData();
printf("Congratulations, you're authenticated with a unique ID of '%s'!", $userData->SPNameID);
} else {
echo "There was an error while attempting to authenticate you.";
}
}
}