Im trying to build a website where users will be able to login via Steam OpenID and do some stuff on the website.
But i would also like to implement some features that steam doesn't offer so:
If user come first time to the website and try to login he use steam OpenID feature to retrieve his user informations (the id is only passed on openID and the rest of informations i can take via API) but now i need to verify user first before i enable other site features, to verify user i need to check if he have more than 20 games on his account. If he have more than 20 games he is ok to continue to use website, if he don't have enough games post a notice that once he have enough game he can continue with login.
When the user is logedin and verified i need to insert his data into database to be able to connect him with features on my website, like counting comments, points,and other activity.
And finally once he is loged in remember him via cookie (there are sessions but as i know they are only valid until browser is closed) so cookie would be solution next time he come to website he don't need to login again.
I know how to do some stuff but in messy way i would be very grateful if someone could point me out and help me a bit how to achieve at least half of this.
So far the code i have is this one.
function login() {
$openid = new LightOpenID(SITEURL);
if(!$openid->mode) {
if(isset($_GET['go']) && $_GET['go'] == 'login' ) {
$openid->identity = 'http://steamcommunity.com/openid';
header('Location: ' . $openid->authUrl());
}
if(!isset($_SESSION['RaffleSteamAuth'])) {
echo '<li><a href="?go=login"><img border="0" src="http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_small.png" /></a></li>';
}
}
elseif($openid->mode == 'cancel') {
echo 'User has canceled Authentication.';
}
elseif(!isset($_SESSION['RaffleSteamAuth'])) {
$_SESSION['RaffleSteamAuth'] = $openid->validate() ? $openid->identity : null;
$_SESSION['RaffleSteamID64'] = str_replace('http://steamcommunity.com/openid/id/', '',$_SESSION['RaffleSteamAuth']);
if($_SESSION['RaffleSteamAuth'] != null) {
$steam64 = str_replace('http://steamcommunity.com/openid/id/', '', $_SESSION['RaffleSteamAuth']);
$profile = file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . APIKEY . '&steamids=' . $steam64);
$buffer = fopen('cache/' . $steam64 . '.json', 'w+');
fwrite($buffer, $profile);
fclose($buffer);
}
header('Location: ' . SITEURL);
}
if(isset($_SESSION['RaffleSteamAuth'])) {
$steam = json_decode(file_get_contents('cache/' . $_SESSION['RaffleSteamID64'] . '.json'));
echo '<li class="dropdown">';
echo '<a href="#" class="dropdown-toggle" data-toggle="dropdown"><img src="' . $steam->response->players[0]->avatar . '"/> ' . $steam->response->players[0]->personaname .'<b class="caret"></b></a>';
echo '<ul class="dropdown-menu">';
echo '<li><a href="?go=logout">Logout</a></li>';
echo '</ul>';
echo '</li>';
}
if(isset($_GET['go']) && $_GET['go'] == 'logout' ){
unset($_SESSION['RaffleSteamAuth']);
unset($_SESSION['RaffleSteamID64']);
header('Location: ' . SITEURL);
}
}