Skip to content

Commit

Permalink
OMG So Cool 2023
Browse files Browse the repository at this point in the history
  • Loading branch information
0944-tw committed May 17, 2023
1 parent 7c82984 commit b878201
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 39 deletions.
31 changes: 29 additions & 2 deletions api/createWebsite.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@
header("Location: ../index.php");
return;
}
// Check Free Account Hit Limit
$stmt = $connect->prepare("SELECT * FROM da_website WHERE client_email = ?");
$stmt->bind_param("s", $_SESSION['email']);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows >= 1) {
$_SESSION["message"] = array(
"type" => "danger",
"title" => "Website Creation Error",
"message" => "You have reached the limit of free website"
);
header("Location: ../index.php");
return;
}
$ch = curl_init();
$params = array(
"action" => "create",
Expand All @@ -59,18 +73,31 @@
parse_str($result, $parsed);
if (curl_error($ch)) {

$_SESSION["message"] = "Something went wrong while creating account";
$_SESSION["message"] = array(
"type" => "danger",
"title" => "Website Creation Error",
"message" => "Something Went Wrong"
);
header("Location: ../index.php");
return;
}
if ($parsed["error"]) {

$_SESSION["message"] = "Something went wrong while create website - " . $parsed["details"];
$_SESSION["message"] = array(
"type" => "danger",
"title" => "Website Creation Error",
"message" => $parsed["details"]
);
header("Location: ../index.php");
return;
}
$nt = date("Y-m-d H:i:s");
$stmt = $connect->prepare("INSERT INTO da_website (username, password, suspended,date_created, client_email,uid) VALUES (?, ?, '0', \" " . date("Y-m-d H:i:s") . "\", ?," . rand(1, 2147483647) . ")");
$stmt->bind_param("sss", $_POST["username"], $_POST["password"], $_SESSION["email"],);
$stmt->execute();
$_SESSION["message"] = array(
"type" => "success",
"title" => "Website Created",
"message" => "Congratulations! Your website has been created."
);
header("Location: ../index.php");
22 changes: 18 additions & 4 deletions api/githubOauth2sign.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
session_start();
$code = $_GET["code"];
if (!$code) {
$_SESSION["message"] = "Invalid Login";
$_SESSION["message"] = array(
"type" => "danger",
"title" => "Something Went Wrong.",
"message" => "Invalid Login."

);
header("Location: ../login.php");
return;
}
Expand Down Expand Up @@ -44,7 +49,12 @@
}
}
if (!isset($primaryEmail)) {
$_SESSION["message"] = "No Primary Email Selected";
$_SESSION["message"] = array(
"type" => "danger",
"title" => "Something Went Wrong.",
"message" => "No Primary Email Exists"

);
header("Location: ../login.php");
}
// connect mysql
Expand All @@ -60,14 +70,18 @@
$_SESSION["username"] = $row["username"];
$_SESSION["email"] = $row["email"];
$_SESSION["password"] = $row["password"];
//header("Location: ../index.php");
header("Location: ../index.php");
} else {
include "../components/githubAuthRegister.php";
}
$stmt->close();

} else {
$_SESSION["message"] = "Access Token Not Found";
$_SESSION["message"] = array(
"type" => "danger",
"message" => "GitHub OAuth2 Error",
"title" => "Something Went Wrong."
);
header("Location: ../login.php");
}

21 changes: 18 additions & 3 deletions api/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@
require "../config.php";
session_start();
if(empty($_GET["email"]) || empty($_GET["password"])) {
$_SESSION["message"] = "Please fill in all fields";
$_SESSION["message"] = array(
"type" => "danger",
"message" => "Please fill in all fields",
"title" => "Login Failed"

);
header("location: ../login.php");
return;
}
// mysql
$connect = mysqli_connect(mysql_host, mysql_uname, mysql_pwd, mysql_db,mysql_port);
if (mysqli_connect_errno()) {
$_SESSION["message"] = "Failed to connect to MySQL: " . mysqli_connect_error();
$_SESSION["message"] = array(
"type" => "danger",
"message" => "Cannot Connect To Database",
"title" => "Login Failed"

);
header("location: ../login.php");
return;
} else {
Expand All @@ -30,7 +40,12 @@
$_SESSION["password"] = $row["password"];
header("Location: ../index.php");
} else {
$_SESSION["message"] = "Account not found";
$_SESSION["message"] = array(
"type" => "danger",
"message" => "Invalid username or password",
"title" => "Login Failed"

);
header("Location: ../login.php");
return;
}
Expand Down
6 changes: 5 additions & 1 deletion api/logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
$_SESSION["username"] = null;
$_SESSION["password"] = null;
$_SESSION["email"] = null;
$_SESSION["message"] = "You has been logged out.";
$_SESSION["message"] = array(
"type" => "success",
"message" => "Logout Success",
"title" => "Logout Success"
);
header("Location: ../login.php");

56 changes: 48 additions & 8 deletions api/signup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,35 @@
const validator = new emailValidator();
session_start();
if (empty($_GET["email"]) || empty($_GET["password"]) || empty($_GET["username"])) {
$_SESSION["message"] = "Please fill in all fields";
$_SESSION["message"] = array(
"type" => "danger",
"message" => "Please fill in all fields",
"title" => "Sign Up Failed"

);
echo "Field Required";
header("Location: ../signup.php");
return;
}

if (!filter_var($_GET["email"], FILTER_VALIDATE_EMAIL)) {
echo "Invalid Email";
$_SESSION["message"] = "Invalid email format";
$_SESSION["message"] = array(
"type" => "danger",
"message" => "Invalid email format",
"title" => "Please Check your email is valid"

);
header("Location: ../signup.php");
return;
}
if (empty($_GET["h-captcha-response"])) {
$_SESSION["message"] = "Please fill in captcha";
$_SESSION["message"] = array(
"type" => "danger",
"message" => "Captcha is Required.",
"title" => "Register Failed"

);
echo "Captcha Required";
header("Location: ../signup.php");
return;
Expand All @@ -32,14 +47,24 @@
curl_close($CaptchaCurl);
// check captcha
if (!json_decode($CaptchaResult, true)["success"]) {
$_SESSION["message"] = "Captcha Failed";
$_SESSION["message"] = array(
"type" => "danger",
"message" => "Captcha Error.",
"title" => "Incorrect Captcha."

);
echo "Captcha Failed";
header("Location: ../signup.php");
return;
}
$res = validator->validate($_GET["email"]);
if (!$res["result"]) {
$_SESSION["message"] = $res["message"];
$_SESSION["message"] = array(
"type" => "danger",
"message" => $res["message"],
"title" => "Email is not valid"

);
header("Location: ../signup.php");
return;
}
Expand All @@ -61,7 +86,12 @@
}

if ($result->num_rows > 0) {
$_SESSION["message"] = "Email or Username already exists";
$_SESSION["message"] = array(
"type" => "danger",
"message" => "Email or username already exists.",
"title" => "Cannot Register."

);
header("Location: ../signup.php");
return;
}
Expand All @@ -72,10 +102,20 @@
$stmt->execute();
if ($stmt->error) {
echo "Something went wrong";
$_SESSION["message"] = "Something went wrong while creating account";
$_SESSION["message"] = array(
"type" => "danger",
"message" => "Something Went Wrong Please Try Again.",
"title" => "Cannot Register."

);
header("Location: ../signup.php");
return;
}
$_SESSION["message"] = "Account created successfully";
$_SESSION["message"] = array(
"type" => "success",
"message" => "Account Created",
"title" => "Congrats!"

);
header("Location: ../login.php");

17 changes: 8 additions & 9 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@

</div>
</div>
<?php if($_SESSION["message"]){ ?>
<div class="alert alert-red">
<h4 class="alert-title">Something Went Wrong</h4>
<div class="text-muted"><?php echo $_SESSION["message"]?></div>
</div>

<?php }
$_SESSION["message"] = null
?>
<?php if (isset($_SESSION["message"])) { ?>
<div class="alert alert-<?php echo $_SESSION["message"]["type"] ?? "danger" ?>" role="alert">

<h4 class="alert-title"><?php echo $_SESSION["message"]["title"]; ?></h4>
<div class="text-muted"><?php echo $_SESSION["message"]["message"]; ?></div>
</div>
<?php }
$_SESSION["message"] = null ?>
</div>


Expand Down
17 changes: 9 additions & 8 deletions login.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@
<div class="card card-md">
<div class="card-body">
<h2 class="h2 text-center mb-4">Login to your account</h2>
<?php if (isset($_SESSION["message"])) { ?>
<div class="alert alert-danger" role="alert">
<h4 class="alert-title">Couldn't login to your account?</h4>
<div class="text-muted"><?php echo $_SESSION["message"]; ?></div>
</div>
<?php }
$_SESSION["message"] = null ?>
<?php if (isset($_SESSION["message"])) { ?>
<div class="alert alert-<?php echo $_SESSION["message"]["type"] ?? "danger" ?>" role="alert">

<h4 class="alert-title"><?php echo $_SESSION["message"]["title"]; ?></h4>
<div class="text-muted"><?php echo $_SESSION["message"]["message"]; ?></div>
</div>
<?php }
$_SESSION["message"] = null ?>
<form action="./api/login.php" method="get" autocomplete="off" novalidate>
<div class="mb-3">
<label class="form-label">Email address</label>
Expand Down Expand Up @@ -95,7 +96,7 @@
<div class="row">
<div class="col"><a href="<?php

echo "https://github.com/login/oauth/authorize?client_id=" . gh_cid."&redirect_uri=" . billingPortalPath . " /api/githubOauth2sign.php&scope=user:email"
echo "https://github.com/login/oauth/authorize?client_id=" . gh_cid."&redirect_uri=" . billingPortalPath . "/api/githubOauth2sign.php&scope=user:email"
?>" class="btn w-100">
<!-- Download SVG icon from http://tabler-icons.io/i/brand-github -->
<svg xmlns="http://www.w3.org/2000/svg" class="icon text-github" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
Expand Down
9 changes: 5 additions & 4 deletions signup.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@
<div class="card-body">
<h2 class="h2 text-center mb-4">Register your account</h2>
<?php if (isset($_SESSION["message"])) { ?>
<div class="alert alert-danger" role="alert">
<h4 class="alert-title">Nah,Can Sign Up?</h4>
<div class="text-muted"><?php echo $_SESSION["message"]; ?></div>
<div class="alert alert-<?php echo $_SESSION["message"]["type"] ?? "error" ?>" role="alert">

<h4 class="alert-title"><?php echo $_SESSION["message"]["title"]; ?></h4>
<div class="text-muted"><?php echo $_SESSION["message"]["message"]; ?></div>
</div>
<?php }
$_SESSION["message"] = null ?>
Expand Down Expand Up @@ -93,7 +94,7 @@
<div class="row">
<div class="col"><a href="<?php

echo "https://github.com/login/oauth/authorize?client_id=" . gh_cid."&redirect_uri=" . billingPortalPath . " /api/githubOauth2sign.php&scope=user:email"
echo "https://github.com/login/oauth/authorize?client_id=" . gh_cid."&redirect_uri=" . billingPortalPath . "/api/githubOauth2sign.php&scope=user:email"
?>" class="btn w-100">
<!-- Download SVG icon from http://tabler-icons.io/i/brand-github -->
<svg xmlns="http://www.w3.org/2000/svg" class="icon text-github" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
Expand Down

0 comments on commit b878201

Please sign in to comment.