diff --git a/.env.example b/.env.example index 3d26df2..b729570 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,9 @@ DISCORD_CLIENT= DISCORD_SECRET= DISCORD_REDIRECT= -DISCORD_OAUTH= \ No newline at end of file +DISCORD_OAUTH= + +MYSQL_HOST= +MYSQL_DB= +MYSQL_USER= +MYSQL_PASS= \ No newline at end of file diff --git a/_config.php b/_config.php index 4f67157..f0e32c0 100644 --- a/_config.php +++ b/_config.php @@ -4,6 +4,7 @@ error_reporting(E_ALL); require __DIR__ . '/vendor/autoload.php'; + require __DIR__ . '/util/Database.php'; require __DIR__ . '/util/Discord.php'; use Twig\Loader\FilesystemLoader; @@ -20,4 +21,11 @@ $_ENV['DISCORD_CLIENT'], $_ENV['DISCORD_SECRET'], $_ENV['DISCORD_REDIRECT'] + ); + + $mysql = new Database( + $_ENV['MYSQL_HOST'], + $_ENV['MYSQL_USER'], + $_ENV['MYSQL_PASS'], + $_ENV['MYSQL_DB'] ); \ No newline at end of file diff --git a/auth.php b/auth.php index 7c54919..c5f70a9 100644 --- a/auth.php +++ b/auth.php @@ -1,5 +1,5 @@ getUser($res['access_token']); + $mysql->createUserRecord($_SESSION['user']); + header('Location: /'); } } else { diff --git a/css/src/style.scss b/css/src/style.scss index f69d1e9..e777162 100644 --- a/css/src/style.scss +++ b/css/src/style.scss @@ -105,4 +105,27 @@ ul, ol { display: flex; flex-direction: column; } + + > .right { + list-style: none; + + display: flex; + + > li { + padding: 8px; + + > a { + display: block; + + width: 24px; + height: 24px; + + color: rgba(0, 0, 0, 0.7); + + &:hover { + color: rgba(0, 0, 0, 1); + } + } + } + } } \ No newline at end of file diff --git a/css/style.css b/css/style.css index 3a8f9da..460ac5b 100644 --- a/css/style.css +++ b/css/style.css @@ -90,5 +90,21 @@ ul, ol { display: flex; flex-direction: column; } +.pageFooter > .right { + list-style: none; + display: flex; +} +.pageFooter > .right > li { + padding: 8px; +} +.pageFooter > .right > li > a { + display: block; + width: 24px; + height: 24px; + color: rgba(0, 0, 0, 0.7); +} +.pageFooter > .right > li > a:hover { + color: rgb(0, 0, 0); +} /*# sourceMappingURL=style.css.map */ diff --git a/css/style.css.map b/css/style.css.map index b541938..9afae3d 100644 --- a/css/style.css.map +++ b/css/style.css.map @@ -1 +1 @@ -{"version":3,"sourceRoot":"","sources":["src/_fonts.scss","src/_reset.scss","src/style.scss"],"names":[],"mappings":"AAAQ;ACAR;EACE;EACA;;;ADAF;EACE;;;AAGF;EACE;EAEA;;;AENF;EACE;;;AAGF;EACE;EAEA;EAEA;;;AAGF;EACE;;;AAGF;EACE;EAEA;EAEA;EAEA;;AAEA;EACE;EAEA;EAEA;;AAEA;EACE;EAEA;EACA;EAEA;EACA;;;AAKN;EACE;EAEA;;AAEA;EACE;EAEA;EACA;EAEA;EACA;;AAEA;EACE;EAEA;EAEA;;AAGE;EACE;EAEA;EAEA;EAEA;;AAEA;EACE;;AAGF;EACE;EACA;;;AAQZ;EACE;;;AAGF;EACE;EACA;EAEA;EACA;;AAEA;EACE;EACA","file":"style.css"} \ No newline at end of file +{"version":3,"sourceRoot":"","sources":["src/_fonts.scss","src/_reset.scss","src/style.scss"],"names":[],"mappings":"AAAQ;ACAR;EACE;EACA;;;ADAF;EACE;;;AAGF;EACE;EAEA;;;AENF;EACE;;;AAGF;EACE;EAEA;EAEA;;;AAGF;EACE;;;AAGF;EACE;EAEA;EAEA;EAEA;;AAEA;EACE;EAEA;EAEA;;AAEA;EACE;EAEA;EACA;EAEA;EACA;;;AAKN;EACE;EAEA;;AAEA;EACE;EAEA;EACA;EAEA;EACA;;AAEA;EACE;EAEA;EAEA;;AAGE;EACE;EAEA;EAEA;EAEA;;AAEA;EACE;;AAGF;EACE;EACA;;;AAQZ;EACE;;;AAGF;EACE;EACA;EAEA;EACA;;AAEA;EACE;EACA;;AAGF;EACE;EAEA;;AAEA;EACE;;AAEA;EACE;EAEA;EACA;EAEA;;AAEA;EACE","file":"style.css"} \ No newline at end of file diff --git a/css/style.min.css b/css/style.min.css index 5f48649..1e75a14 100644 --- a/css/style.min.css +++ b/css/style.min.css @@ -1 +1 @@ -@import"https://fonts.googleapis.com/css2?family=Noto+Color+Emoji&family=Noto+Sans:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=Outfit:wght@100;200;300;400;500;600;700;800;900&display=swap";*{padding:0;margin:0}*{font-family:"Noto Sans","Noto Color Emoji",sans-serif}h1,h2,h3,h4,h5,h6{font-family:"Outfit","Noto Color Emoji",sans-serif;margin-bottom:6px}body{background:#f8fafc}.container{max-width:1100px;width:100%;margin:0 auto}ul,ol{list-style-position:inside}.pageHero{background-image:url("/img/spawn/2023-09-15_17.51.17.png");background-position:center;color:#fff;height:240px}.pageHero>.blurFiler{backdrop-filter:blur(2px);padding:8px 0;height:calc(100% - 16px)}.pageHero>.blurFiler>.container{height:100%;display:flex;flex-direction:row;align-items:center;justify-content:space-between}.pageNav{width:100svw;background:#f1f5f9}.pageNav>.container{padding:16px 0;display:flex;flex-direction:row;align-items:center;justify-content:space-between}.pageNav>.container>ul{list-style:none;display:flex;gap:8px}.pageNav>.container>ul>li>a{color:#0f172a;text-decoration:none;padding:8px 16px;border-radius:32px}.pageNav>.container>ul>li>a:hover,.pageNav>.container>ul>li>a.active{background:rgba(15,23,42,.1)}.pageNav>.container>ul>li>a.buttonPrimary{background:#6366f1;color:#fff}.pageContent{margin:16px 0}.pageFooter{display:flex;flex-direction:row;align-items:center;justify-content:space-between}.pageFooter>.left{display:flex;flex-direction:column}/*# sourceMappingURL=style.min.css.map */ +@import"https://fonts.googleapis.com/css2?family=Noto+Color+Emoji&family=Noto+Sans:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=Outfit:wght@100;200;300;400;500;600;700;800;900&display=swap";*{padding:0;margin:0}*{font-family:"Noto Sans","Noto Color Emoji",sans-serif}h1,h2,h3,h4,h5,h6{font-family:"Outfit","Noto Color Emoji",sans-serif;margin-bottom:6px}body{background:#f8fafc}.container{max-width:1100px;width:100%;margin:0 auto}ul,ol{list-style-position:inside}.pageHero{background-image:url("/img/spawn/2023-09-15_17.51.17.png");background-position:center;color:#fff;height:240px}.pageHero>.blurFiler{backdrop-filter:blur(2px);padding:8px 0;height:calc(100% - 16px)}.pageHero>.blurFiler>.container{height:100%;display:flex;flex-direction:row;align-items:center;justify-content:space-between}.pageNav{width:100svw;background:#f1f5f9}.pageNav>.container{padding:16px 0;display:flex;flex-direction:row;align-items:center;justify-content:space-between}.pageNav>.container>ul{list-style:none;display:flex;gap:8px}.pageNav>.container>ul>li>a{color:#0f172a;text-decoration:none;padding:8px 16px;border-radius:32px}.pageNav>.container>ul>li>a:hover,.pageNav>.container>ul>li>a.active{background:rgba(15,23,42,.1)}.pageNav>.container>ul>li>a.buttonPrimary{background:#6366f1;color:#fff}.pageContent{margin:16px 0}.pageFooter{display:flex;flex-direction:row;align-items:center;justify-content:space-between}.pageFooter>.left{display:flex;flex-direction:column}.pageFooter>.right{list-style:none;display:flex}.pageFooter>.right>li{padding:8px}.pageFooter>.right>li>a{display:block;width:24px;height:24px;color:rgba(0,0,0,.7)}.pageFooter>.right>li>a:hover{color:#000}/*# sourceMappingURL=style.min.css.map */ diff --git a/css/style.min.css.map b/css/style.min.css.map index 627a06d..284f354 100644 --- a/css/style.min.css.map +++ b/css/style.min.css.map @@ -1 +1 @@ -{"version":3,"sourceRoot":"","sources":["src/_fonts.scss","src/_reset.scss","src/style.scss"],"names":[],"mappings":"AAAQ,gRCCN,UACA,WDCA,sDAGF,kBACE,mDAEA,kBENF,KACE,mBAGF,WACE,iBAEA,WAEA,cAGF,MACE,2BAGF,UACE,2DAEA,2BAEA,WAEA,aAEA,qBACE,0BAEA,cAEA,yBAEA,gCACE,YAEA,aACA,mBAEA,mBACA,8BAKN,SACE,aAEA,mBAEA,oBACE,eAEA,aACA,mBAEA,mBACA,8BAEA,uBACE,gBAEA,aAEA,QAGE,4BACE,cAEA,qBAEA,iBAEA,mBAEA,qEACE,6BAGF,0CACE,mBACA,WAQZ,aACE,cAGF,YACE,aACA,mBAEA,mBACA,8BAEA,kBACE,aACA","file":"style.min.css"} \ No newline at end of file +{"version":3,"sourceRoot":"","sources":["src/_fonts.scss","src/_reset.scss","src/style.scss"],"names":[],"mappings":"AAAQ,gRCCN,UACA,WDCA,sDAGF,kBACE,mDAEA,kBENF,KACE,mBAGF,WACE,iBAEA,WAEA,cAGF,MACE,2BAGF,UACE,2DAEA,2BAEA,WAEA,aAEA,qBACE,0BAEA,cAEA,yBAEA,gCACE,YAEA,aACA,mBAEA,mBACA,8BAKN,SACE,aAEA,mBAEA,oBACE,eAEA,aACA,mBAEA,mBACA,8BAEA,uBACE,gBAEA,aAEA,QAGE,4BACE,cAEA,qBAEA,iBAEA,mBAEA,qEACE,6BAGF,0CACE,mBACA,WAQZ,aACE,cAGF,YACE,aACA,mBAEA,mBACA,8BAEA,kBACE,aACA,sBAGF,mBACE,gBAEA,aAEA,sBACE,YAEA,wBACE,cAEA,WACA,YAEA,qBAEA,8BACE","file":"style.min.css"} \ No newline at end of file diff --git a/index.php b/index.php index 72626aa..3d439d5 100644 --- a/index.php +++ b/index.php @@ -8,14 +8,18 @@ $router = new Router(); session_start(); + + $nations = array( + 'rop' => array( + 'name' => 'Republic of Panorama', + 'flag' => 'https://git.theclashfruit.me/CRSS/CRSS/raw/branch/main/Nations/Republic%20of%20Panorama/Flag.svg', + 'short' => 'rop', + ) + ); if(isset($_SESSION['user'])) $twig->addGlobal('user', $_SESSION['user']); - $router->get('/u/([a-z0-9_\.]+)', function($name) { - echo 'Hello ' . htmlentities($name); - }); - $router->get('/', function() { global $twig; @@ -40,6 +44,34 @@ echo $twig->render('map.twig'); }); + $router->get('/profile', function() { + global $twig, $mysql; + + $user = $mysql->getUserRecordFromId($_SESSION['user']['id']); + + if($user == null) { + http_response_code(404); + + echo $twig->render('404.twig'); + } else { + echo $twig->render('profile.twig', array('db_data' => $user)); + } + }); + + $router->get('/u/([a-z0-9_\.]+)', function($name) { + global $twig, $mysql, $discord; + + $user = $mysql->getUserRecordFromUsername($name); + + if($user == null) { + http_response_code(404); + + echo $twig->render('404.twig'); + } else { + echo $twig->render('user.twig', array('db_user' => $user)); + } + }); + $router->set404(function() { global $twig; diff --git a/template/includes/footer.twig b/template/includes/footer.twig index af91b67..c10a10d 100644 --- a/template/includes/footer.twig +++ b/template/includes/footer.twig @@ -7,7 +7,27 @@ Brought to by PrideCraft, TheClashFruit's Real Hosting Company.

-
- -
+ \ No newline at end of file diff --git a/template/includes/nav.twig b/template/includes/nav.twig index 8116969..b476a68 100644 --- a/template/includes/nav.twig +++ b/template/includes/nav.twig @@ -24,17 +24,17 @@ diff --git a/template/nations.twig b/template/nations.twig index 21255d1..518e3ac 100644 --- a/template/nations.twig +++ b/template/nations.twig @@ -12,11 +12,16 @@ -{% include 'includes/nav.twig' with {'page': 'nations',} %} +{% include 'includes/nav.twig' with {'page': 'nations'} %}
- this is the home page +

Nations

+
diff --git a/template/profile.twig b/template/profile.twig new file mode 100644 index 0000000..018908f --- /dev/null +++ b/template/profile.twig @@ -0,0 +1,46 @@ +{% include 'includes/head.twig' with {'pageTitle': 'Profile'} %} + +
+
+
+

Clyde's Real Survival SMP

+ +
+ Online: / +
+
+
+
+ +{% include 'includes/nav.twig' with {'page': 'profile',} %} + +
+
+ +
+
+ +{% include 'includes/footer.twig' %} +{% include 'includes/foot.twig' %} \ No newline at end of file diff --git a/template/user.twig b/template/user.twig new file mode 100644 index 0000000..087d053 --- /dev/null +++ b/template/user.twig @@ -0,0 +1,24 @@ +{% include 'includes/head.twig' with {'pageTitle': username} %} + +
+
+
+

Clyde's Real Survival SMP

+ +
+ Online: / +
+
+
+
+ +{% include 'includes/nav.twig' with {'page': 'user',} %} + +
+
+ {{ db_user.display_name }} is {% if db_user.is_admin == 1 %} an admin! {% else %} not an admin! {% endif %} +
+
+ +{% include 'includes/footer.twig' %} +{% include 'includes/foot.twig' %} \ No newline at end of file diff --git a/util/Database.php b/util/Database.php new file mode 100644 index 0000000..6378aa6 --- /dev/null +++ b/util/Database.php @@ -0,0 +1,60 @@ +host = $host; + $this->user = $user; + $this->pass = $pass; + $this->db = $db; + + $this->conn = new mysqli($this->host, $this->user, $this->pass, $this->db); + } + + function createUserRecord($user): void { + $sql = 'INSERT IGNORE INTO users (id, username, display_name) VALUES (?, ?, ?)'; + + $stmt = $this->conn->prepare($sql); + $stmt->bind_param('iss', $user['id'], $user['username'], $user['global_name']); + + $stmt->execute(); + } + + function getUserRecordFromUsername($username): bool|array|null { + $sql = 'SELECT * FROM users WHERE username = ?'; + + $stmt = $this->conn->prepare($sql); + $stmt->bind_param('s', $username); + + $stmt->execute(); + + $res = $stmt->get_result(); + + if($res->num_rows > 0) { + return $res->fetch_assoc(); + } else { + return null; + } + } + + function getUserRecordFromId($id): bool|array|null { + $sql = 'SELECT * FROM users WHERE id = ?'; + + $stmt = $this->conn->prepare($sql); + $stmt->bind_param('i', $id); + + $stmt->execute(); + + $res = $stmt->get_result(); + + if($res->num_rows > 0) { + return $res->fetch_assoc(); + } else { + return null; + } + } + } \ No newline at end of file diff --git a/util/Discord.php b/util/Discord.php index 9076d69..871a657 100644 --- a/util/Discord.php +++ b/util/Discord.php @@ -67,7 +67,9 @@ } function getUser($token): array { - $res = $this->curl->newRequest('get', 'https://discord.com/api/v10/users/@me') + $res = $this + ->curl + ->newRequest('get', 'https://discord.com/api/v10/users/@me') ->setHeader('Authorization', 'Bearer ' . $token) ->send(); @@ -75,7 +77,9 @@ } function getGuilds($token): array { - $res = $this->curl->newRequest('get', 'https://discord.com/api/v10/users/@me/guilds') + $res = $this + ->curl + ->newRequest('get', 'https://discord.com/api/v10/users/@me/guilds') ->setHeader('Authorization', 'Bearer ' . $token) ->send();