web - added login via steam

This commit is contained in:
Nereziel
2023-11-07 18:09:14 +01:00
parent 5debad9711
commit 5f4cf1dfc3
7 changed files with 1247 additions and 16 deletions

View File

@@ -1,14 +1,10 @@
<?php
class DataBase {
private $DB_HOST = "localhost";
private $DB_NAME = "";
private $DB_USER = "";
private $DB_PASS = "";
private $PDO;
public function __construct() {
$this->PDO = new PDO("mysql:host=".$this->DB_HOST."; dbname=".$this->DB_NAME, $this->DB_USER, $this->DB_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$this->PDO = new PDO("mysql:host=".DB_HOST."; dbname=".DB_NAME, DB_USER, DB_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
}
public function select($query, $bindings = []) {
$STH = $this->PDO->prepare($query);

11
website/class/config.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
define('DB_HOST', 'localhost');
define('DB_NAME', 'cs2server');
define('DB_USER', 'cs2server');
define('DB_PASS', 'SupRCupRH35l0p1c0+*');
define('STEAM_API_KEY', '37D90C2FFAC89E178B0D53DB42A4981C');
define('STEAM_DOMAIN_NAME', '');
define('STEAM_LOGOUT_PAGE', '');
define('STEAM_LOGIN_PAGE', '');

View File

@@ -1,13 +1,19 @@
<?php
include 'class/DataBase.php';
require_once 'class/config.php';
require_once 'class/database.php';
require_once 'steamauth/steamauth.php';
# You would uncomment the line beneath to make it refresh the data every time the page is loaded
// unset($_SESSION['steam_uptodate']);
$db = new DataBase();
if(!isset($_GET['steamid'])) {
die("ERROR - Player is not found! Please add steam id to view this page! :)");
//$steamid = $_GET['steamid'];
if(isset($_SESSION['steamid']))
{
include ('steamauth/userInfo.php');
$steamid = $steamprofile['steamid'];
}
$steamid = $_GET['steamid'];
if(isset($_POST['forma'])) {
$ex = explode("-", $_POST['forma']);
@@ -37,11 +43,20 @@ if(isset($_POST['forma'])) {
</head>
<body>
<div class="bg-primary">Your current weapon skin loadout.</div>
<div class="card-group">
<?php
$query = $db->select("SELECT * FROM wp_weapons_paints GROUP BY weapon_defindex ORDER BY weapon_defindex");
foreach($query as $key) { ?>
if(!isset($_SESSION['steamid']))
{
echo "<div class='bg-primary'><h2>To choose weapon paints loadout, you need to ";
loginbutton("rectangle");
echo "</h2></div>";
}
else
{
echo "<div class='bg-primary'>Your current weapon skin loadout<form action='' method='get'><button class='btn btn-secondary' name='logout' type='submit'>Logout</button></form></div>";
echo "<div class='card-group'>";
$query = $db->select("SELECT * FROM wp_weapons_paints GROUP BY weapon_defindex ORDER BY weapon_defindex");
foreach($query as $key) { ?>
<div class="col-sm-2">
<div class="card text-center mb-3">
<div class="card-body">
@@ -77,8 +92,10 @@ foreach($query as $key) { ?>
</div>
</div>
</div>
<?php } ?>
</div>
<?php } ?>
</div>
</body>
</html>

View File

@@ -0,0 +1,13 @@
<?php
//Version 3.2
$steamauth['apikey'] = STEAM_API_KEY; // Your Steam WebAPI-Key found at https://steamcommunity.com/dev/apikey
$steamauth['domainname'] = STEAM_DOMAIN_NAME; // The main URL of your website displayed in the login page
$steamauth['logoutpage'] = STEAM_LOGOUT_PAGE; // Page to redirect to after a successfull logout (from the directory the SteamAuth-folder is located in) - NO slash at the beginning!
$steamauth['loginpage'] = STEAM_LOGIN_PAGE; // Page to redirect to after a successfull login (from the directory the SteamAuth-folder is located in) - NO slash at the beginning!
// System stuff
if (empty($steamauth['apikey'])) {die("<div style='display: block; width: 100%; background-color: red; text-align: center;'>SteamAuth:<br>Please supply an API-Key!<br>Find this in steamauth/SteamConfig.php, Find the '<b>\$steamauth['apikey']</b>' Array. </div>");}
if (empty($steamauth['domainname'])) {$steamauth['domainname'] = $_SERVER['SERVER_NAME'];}
if (empty($steamauth['logoutpage'])) {$steamauth['logoutpage'] = $_SERVER['PHP_SELF'];}
if (empty($steamauth['loginpage'])) {$steamauth['loginpage'] = $_SERVER['PHP_SELF'];}
?>

1076
website/steamauth/openid.php Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,75 @@
<?php
ob_start();
session_start();
function logoutbutton() {
echo "<form action='' method='get'><button class='btn btn-secondary' name='logout' type='submit'>Logout</button></form>"; //logout button
}
function loginbutton($buttonstyle = "square") {
$button['rectangle'] = "01";
$button['square'] = "02";
$button = "<a href='?login'><img src='https://steamcommunity-a.akamaihd.net/public/images/signinthroughsteam/sits_".$button[$buttonstyle].".png'></a>";
echo $button;
}
if (isset($_GET['login'])){
require 'openid.php';
try {
require 'SteamConfig.php';
$openid = new LightOpenID($steamauth['domainname']);
if(!$openid->mode) {
$openid->identity = 'https://steamcommunity.com/openid';
header('Location: ' . $openid->authUrl());
} elseif ($openid->mode == 'cancel') {
echo 'User has canceled authentication!';
} else {
if($openid->validate()) {
$id = $openid->identity;
$ptn = "/^https?:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
preg_match($ptn, $id, $matches);
$_SESSION['steamid'] = $matches[1];
if (!headers_sent()) {
header('Location: '.$steamauth['loginpage']);
exit;
} else {
?>
<script type="text/javascript">
window.location.href="<?=$steamauth['loginpage']?>";
</script>
<noscript>
<meta http-equiv="refresh" content="0;url=<?=$steamauth['loginpage']?>" />
</noscript>
<?php
exit;
}
} else {
echo "User is not logged in.\n";
}
}
} catch(ErrorException $e) {
echo $e->getMessage();
}
}
if (isset($_GET['logout'])){
require 'SteamConfig.php';
session_unset();
session_destroy();
header('Location: '.$steamauth['logoutpage']);
exit;
}
if (isset($_GET['update'])){
unset($_SESSION['steam_uptodate']);
require 'userInfo.php';
header('Location: '.$_SERVER['PHP_SELF']);
exit;
}
// Version 3.2
?>

View File

@@ -0,0 +1,43 @@
<?php
if (empty($_SESSION['steam_uptodate']) or empty($_SESSION['steam_personaname'])) {
require 'SteamConfig.php';
$url = file_get_contents("https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".$steamauth['apikey']."&steamids=".$_SESSION['steamid']);
$content = json_decode($url, true);
$_SESSION['steam_steamid'] = $content['response']['players'][0]['steamid'];
$_SESSION['steam_communityvisibilitystate'] = $content['response']['players'][0]['communityvisibilitystate'];
$_SESSION['steam_profilestate'] = $content['response']['players'][0]['profilestate'];
$_SESSION['steam_personaname'] = $content['response']['players'][0]['personaname'];
$_SESSION['steam_lastlogoff'] = $content['response']['players'][0]['lastlogoff'];
$_SESSION['steam_profileurl'] = $content['response']['players'][0]['profileurl'];
$_SESSION['steam_avatar'] = $content['response']['players'][0]['avatar'];
$_SESSION['steam_avatarmedium'] = $content['response']['players'][0]['avatarmedium'];
$_SESSION['steam_avatarfull'] = $content['response']['players'][0]['avatarfull'];
$_SESSION['steam_personastate'] = $content['response']['players'][0]['personastate'];
if (isset($content['response']['players'][0]['realname'])) {
$_SESSION['steam_realname'] = $content['response']['players'][0]['realname'];
} else {
$_SESSION['steam_realname'] = "Real name not given";
}
$_SESSION['steam_primaryclanid'] = $content['response']['players'][0]['primaryclanid'];
$_SESSION['steam_timecreated'] = $content['response']['players'][0]['timecreated'];
$_SESSION['steam_uptodate'] = time();
}
$steamprofile['steamid'] = $_SESSION['steam_steamid'];
$steamprofile['communityvisibilitystate'] = $_SESSION['steam_communityvisibilitystate'];
$steamprofile['profilestate'] = $_SESSION['steam_profilestate'];
$steamprofile['personaname'] = $_SESSION['steam_personaname'];
$steamprofile['lastlogoff'] = $_SESSION['steam_lastlogoff'];
$steamprofile['profileurl'] = $_SESSION['steam_profileurl'];
$steamprofile['avatar'] = $_SESSION['steam_avatar'];
$steamprofile['avatarmedium'] = $_SESSION['steam_avatarmedium'];
$steamprofile['avatarfull'] = $_SESSION['steam_avatarfull'];
$steamprofile['personastate'] = $_SESSION['steam_personastate'];
$steamprofile['realname'] = $_SESSION['steam_realname'];
$steamprofile['primaryclanid'] = $_SESSION['steam_primaryclanid'];
$steamprofile['timecreated'] = $_SESSION['steam_timecreated'];
$steamprofile['uptodate'] = $_SESSION['steam_uptodate'];
// Version 3.2
?>