I forgot what's in this

This commit is contained in:
bye 2024-06-28 22:41:35 +01:00
parent fed68541f8
commit 85fff100ae
9 changed files with 158 additions and 6 deletions

45
common/account_utils.php Normal file
View file

@ -0,0 +1,45 @@
<?php
function generate_bcid($duplicate_check=false): string
{
$CHARS = str_split("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");
$bcid = $CHARS[array_rand($CHARS)].$CHARS[array_rand($CHARS)].$CHARS[array_rand($CHARS)].$CHARS[array_rand($CHARS)].$CHARS[array_rand($CHARS)].$CHARS[array_rand($CHARS)].$CHARS[array_rand($CHARS)];
if ($duplicate_check) {
$same_accounts = db_execute('SELECT id FROM accounts WHERE id = ? LIMIT 1', [$bcid]);
if ($same_accounts) {
$bcid = generate_bcid(true);
}
}
return $bcid;
}
function validate_bcid($bcid): bool
{
$stripped_bcid = str_replace([" ", "-"], "", $bcid);
$stripped_bcid = strtoupper($stripped_bcid);
if (!preg_match('/^[^A-Z^0-9]^/', $stripped_bcid) && strlen($stripped_bcid) == 7) {
return true;
}
return false; // fail condition
}
function format_bcid ($bcid): string
{ // Formats to XXX-XXXX
$stripped_bcid = str_replace([' ','-'], '', $bcid);
$stripped_bcid = strtoupper($stripped_bcid);
if (!validate_bcid($stripped_bcid)) {
throw new Exception('Invalid BCID.');
}
return substr($stripped_bcid, 0, 3).'-'.substr($stripped_bcid, -4, 4);
}
function get_user_by_id($bcid) {
$user = db_execute('SELECT * FROM accounts WHERE id = ? LIMIT 1', [$bcid]);
return $user;
}

27
common/database.php Normal file
View file

@ -0,0 +1,27 @@
<?php
function db_execute($sql, $variables=[]) {
global $pdo;
$stmt = $pdo->prepare($sql);
$stmt->execute($variables);
return $stmt->fetch();
}
function db_execute_all($sql, $variables=[]): bool|array
{
global $pdo;
$stmt = $pdo->prepare($sql);
$stmt->execute($variables);
return $stmt->fetchAll();
}
function db_query($sql): bool|PDOStatement
{
global $pdo;
return $pdo->query($sql);
}

View file

@ -8,6 +8,11 @@
body { body {
margin: 0; margin: 0;
display: flex;
flex-direction: column;
min-height: 100vh;
} }
header { header {
@ -17,6 +22,8 @@ header {
gap: 1rem; gap: 1rem;
flex: 0;
justify-content: space-between; justify-content: space-between;
background: var(--flax); background: var(--flax);
@ -25,6 +32,12 @@ header {
main { main {
flex: 1; flex: 1;
margin: 16px;
}
footer {
flex: 0;
} }
#content { #content {
@ -38,6 +51,29 @@ main {
} }
} }
/* Error box */
.errorbox {
display: block;
text-align: center;
}
body > .errorbox {
flex: 1;
margin: auto;
align-content: center;
}
.errorbox > * {
margin: 5px;
}
.errorbox > .icon {
color: var(--error-fg, red);
font-size: 4em;
}
/* Font things */ /* Font things */
.bc-1 { .bc-1 {
font-weight: 700; font-weight: 700;

View file

@ -7,11 +7,10 @@
<body> <body>
<?php include 'partials/header.php'; ?> <?php include 'partials/header.php'; ?>
<h1>ByeCorps ID</h1> <main>
<h1><span class="bc-1">Bye</span><span class="bc-2">Corps</span><span class="bc-3"> ID</span></h1>
</main>
<?php include 'partials/footer.php'; ?> <?php include 'partials/footer.php'; ?>
</body> </body>
</html> </html>

13
views/partials/error.php Normal file
View file

@ -0,0 +1,13 @@
<?php
$error_body = $error_body ?? "No message provided.";
?>
<div class="errorbox">
<div class="icon">
<span class="fa-solid fa-fw fa-circle-xmark"></span>
</div>
<h2>An error occurred.</h2>
<p><?= htmlspecialchars($error_body) ?></p>
</div>

View file

@ -2,7 +2,7 @@
<meta name="viewport" <meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge"> <meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://cdn.byecorps.com/global/fonts/fontawesome/js/all.min.js" defer></script>
<link rel="stylesheet" href="/styles/base.css"> <link rel="stylesheet" href="/styles/base.css">
<?php <?php

View file

@ -7,6 +7,6 @@
</div> </div>
<div> <div>
Login disabled. <a href="/auth/signup"><?= get_string("auth.signup") ?></a>
</div> </div>
</header> </header>

31
views/profile.php Normal file
View file

@ -0,0 +1,31 @@
<?php
//global $user;
if (is_null($user)) {
$error = true;
$error_body = "Not logged in.";
}
?>
<!doctype html>
<html lang="en">
<head>
<?php include "partials/head.php" ?>
</head>
<body>
<?php include "partials/header.php" ?>
<?php
if ($error) {
include 'partials/error.php';
include 'partials/footer.php';
exit();
}
?>
<p><?= $profile_owner['id'] ?></p>
<?php include 'partials/footer.php' ?>
</body>
</html>

1
views/signup.php Normal file
View file

@ -0,0 +1 @@
<?php