Skip to content
This repository was archived by the owner on Jul 11, 2024. It is now read-only.

Commit d3063a4

Browse files
authored
v2.0 - Accounts Update!
1 parent 2f981b4 commit d3063a4

File tree

14 files changed

+991
-0
lines changed

14 files changed

+991
-0
lines changed

account.php

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
// Initialize the session
3+
session_start();
4+
5+
// Check if the user is logged in, if not then redirect him to login page
6+
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
7+
header("location: login.php");
8+
exit;
9+
}
10+
11+
$userName = $_SESSION["username"];
12+
13+
// Include config file
14+
require_once "config.php";
15+
16+
// Define variables and initialize with empty values
17+
$new_password = $confirm_password = "";
18+
$new_password_err = $confirm_password_err = "";
19+
20+
// Processing form data when form is submitted
21+
if($_SERVER["REQUEST_METHOD"] == "POST"){
22+
23+
// Validate new password
24+
if(empty(trim($_POST["new_password"]))){
25+
$new_password_err = "Please enter the new password.";
26+
} elseif(strlen(trim($_POST["new_password"])) < 6){
27+
$new_password_err = "Password must have atleast 6 characters.";
28+
} else{
29+
$new_password = trim($_POST["new_password"]);
30+
}
31+
32+
// Validate confirm password
33+
if(empty(trim($_POST["confirm_password"]))){
34+
$confirm_password_err = "Please confirm the password.";
35+
} else{
36+
$confirm_password = trim($_POST["confirm_password"]);
37+
if(empty($new_password_err) && ($new_password != $confirm_password)){
38+
$confirm_password_err = "Password did not match.";
39+
}
40+
}
41+
42+
// Check input errors before updating the database
43+
if(empty($new_password_err) && empty($confirm_password_err)){
44+
// Prepare an update statement
45+
$sql = "UPDATE users SET password = ? WHERE id = ?";
46+
47+
if($stmt = mysqli_prepare($link, $sql)){
48+
// Bind variables to the prepared statement as parameters
49+
mysqli_stmt_bind_param($stmt, "si", $param_password, $param_id);
50+
51+
// Set parameters
52+
$param_password = password_hash($new_password, PASSWORD_DEFAULT);
53+
$param_id = $_SESSION["id"];
54+
55+
// Attempt to execute the prepared statement
56+
if(mysqli_stmt_execute($stmt)){
57+
// Password updated successfully. Destroy the session, and redirect to login page
58+
session_destroy();
59+
header("location: login.php");
60+
exit();
61+
} else{
62+
echo "Oops! Something went wrong. Please try again later.";
63+
}
64+
65+
// Close statement
66+
mysqli_stmt_close($stmt);
67+
}
68+
}
69+
70+
// Close connection
71+
mysqli_close($link);
72+
}
73+
?>
74+
<!DOCTYPE html>
75+
<html lang="en">
76+
<head>
77+
<meta charset="UTF-8">
78+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
79+
<title>Welcome</title>
80+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
81+
<style>
82+
body{ font: 14px sans-serif; text-align: center; background-color: #404040; color: white; }
83+
.my-5{ color: white; }
84+
.form-control{ width: 350px; margin: auto; }
85+
</style>
86+
</head>
87+
<body>
88+
<img src="userdata/<?=$userName?>/avatar.jpg" style="width: 250px; height: 250px; border-radius: 50%; margin-top: 50px;"/>
89+
<h1 class="my-5"><b><?php echo htmlspecialchars($_SESSION["username"]); ?></b></h1>
90+
<h2 class="my-5">Account Settings</h2>
91+
<a href="logout.php" class="btn btn-danger ml-3" style="margin-left: 0rem!important;">Sign Out of Your Account</a>
92+
<br><br><br>
93+
<h5 style="color: white;">Change Your Password:</h5>
94+
<div class="wrapper">
95+
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
96+
<div class="form-group">
97+
<label>New Password</label>
98+
<input type="password" name="new_password" class="form-control <?php echo (!empty($new_password_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $new_password; ?>">
99+
<span class="invalid-feedback"><?php echo $new_password_err; ?></span>
100+
</div>
101+
<div class="form-group">
102+
<label>Confirm Password</label>
103+
<input type="password" name="confirm_password" class="form-control <?php echo (!empty($confirm_password_err)) ? 'is-invalid' : ''; ?>">
104+
<span class="invalid-feedback"><?php echo $confirm_password_err; ?></span>
105+
</div>
106+
<div class="form-group">
107+
<input type="submit" class="btn btn-primary" value="Submit">
108+
</div>
109+
</form>
110+
</div>
111+
</body>
112+
</html>

config.php.example.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/* Database credentials. Assuming you are running MySQL
3+
server with default setting (user 'root' with no password) */
4+
define('DB_SERVER', 'localhost');
5+
define('DB_USERNAME', 'root');
6+
define('DB_PASSWORD', '');
7+
define('DB_NAME', '');
8+
9+
/* Attempt to connect to MySQL database */
10+
$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
11+
12+
// Check connection
13+
if($link === false){
14+
die("ERROR: Could not connect. " . mysqli_connect_error());
15+
}
16+
?>

img-upload.php

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?php
2+
// Initialize the session
3+
session_start();
4+
5+
// Check if the user is logged in, if not then redirect him to login page
6+
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
7+
header("location: login.php");
8+
exit;
9+
}
10+
?>
11+
<!DOCTYPE html>
12+
<html prefix="og: https://ogp.me/ns#">
13+
<head>
14+
<title>Upload Your Files!</title>
15+
<meta name="viewport" content="width=device-width, initial-scale=1">
16+
<meta property="og:image" content="https://cdn.sappy.ga/img/saplogo.png" />
17+
18+
<meta property="og:description" content="Upload your images to the web." />
19+
20+
<meta property="og:url"content="http://cdn.sappy.ga/" />
21+
22+
<meta property="og:title" content="Sappy's CDN Upload " />
23+
<style>
24+
body {
25+
background-color: #404040;
26+
color: white;
27+
text-align: center;
28+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
29+
}
30+
.mainContent {
31+
padding: 170px 0px;
32+
}
33+
input[type=button],input[type=submit],input[type=reset] {
34+
background-color: #FF0000;
35+
border: none;
36+
color: white;
37+
padding: 16px 32px;
38+
text-decoration: none;
39+
margin: 4px 2px;
40+
cursor: pointer;
41+
42+
transition: 250ms;
43+
}
44+
input[type=file] {
45+
display: none;
46+
}
47+
.uploadButton:hover {
48+
background-color: #333;
49+
}
50+
.uploadButton {
51+
background-color: #555;
52+
border: none;
53+
color: white;
54+
padding: 16px 32px;
55+
text-decoration: none;
56+
margin: 10px 2px;
57+
cursor: pointer;
58+
min-width: %100;
59+
60+
transition: 250ms;
61+
}
62+
.inputButton:hover {
63+
background-color: brown;
64+
}
65+
.loginButton{
66+
padding: 5px 10px;
67+
background-color: #007bff;
68+
border-radius: 2px;
69+
color: white;
70+
text-decoration: none;
71+
transition: 500ms;
72+
}
73+
.loginButton:hover{
74+
background-color: #0069d9;
75+
}
76+
</style>
77+
</head>
78+
<body>
79+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
80+
<div class="mainContent">
81+
<h1>Sappy's Premium CDN Image Upload</h1>
82+
<h2>Accepted Formats: png, jpg, jpeg, gif</h2>
83+
<br><br>
84+
<form action="iupload.php" method="post" enctype="multipart/form-data">
85+
<label for="fileToUpload" class="uploadButton">Select Your Image To Upload!</label>
86+
<input type="file" name="fileToUpload" id="fileToUpload"><br><br>Your Image:<br><br>
87+
<img id="blah" src="#" alt="" style="max-width: 200px; max-height: 200px;"/>
88+
<br><br>
89+
<input class="inputButton" type="submit" value="Upload Image" name="submit">
90+
</form>
91+
</div>
92+
<script>function readURL(input) {
93+
if (input.files && input.files[0]) {
94+
var reader = new FileReader();
95+
96+
reader.onload = function(e) {
97+
$('#blah').attr('src', e.target.result);
98+
}
99+
100+
reader.readAsDataURL(input.files[0]); // convert to base64 string
101+
}
102+
}
103+
104+
$("#fileToUpload").change(function() {
105+
readURL(this);
106+
});</script>
107+
</body>
108+
</html>

index.html

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<!DOCTYPE html>
2+
<html prefix="og: https://ogp.me/ns#">
3+
<head>
4+
<!--File Uploader by Slddev. Repository: github.com/Slddev/php-fileuploader-->
5+
<title>Upload Your Files!</title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<meta property="og:image" content="https://cdn.sappy.ga/img/saplogo.png" />
8+
9+
<meta property="og:description" content="Upload your images to the web." />
10+
11+
<meta property="og:url"content="http://github.com/Slddev/php-fileuploader/" />
12+
13+
<meta property="og:title" content="CDN Upload " />
14+
<style>
15+
body {
16+
background-color: #404040;
17+
color: white;
18+
text-align: center;
19+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
20+
}
21+
.mainContent {
22+
padding: 170px 0px;
23+
}
24+
input[type=button],input[type=submit],input[type=reset] {
25+
background-color: #FF0000;
26+
border: none;
27+
color: white;
28+
padding: 16px 32px;
29+
text-decoration: none;
30+
margin: 4px 2px;
31+
cursor: pointer;
32+
33+
transition: 250ms;
34+
}
35+
input[type=file] {
36+
display: none;
37+
}
38+
.uploadButton:hover {
39+
background-color: #333;
40+
}
41+
.uploadButton {
42+
background-color: #555;
43+
border: none;
44+
color: white;
45+
padding: 16px 32px;
46+
text-decoration: none;
47+
margin: 10px 2px;
48+
cursor: pointer;
49+
min-width: %100;
50+
51+
transition: 250ms;
52+
}
53+
.inputButton:hover {
54+
background-color: brown;
55+
}
56+
.loginButton{
57+
padding: 5px 10px;
58+
background-color: #007bff;
59+
border-radius: 2px;
60+
color: white;
61+
text-decoration: none;
62+
transition: 500ms;
63+
}
64+
.loginButton:hover{
65+
background-color: #0069d9;
66+
}
67+
</style>
68+
</head>
69+
<body>
70+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
71+
<div class="mainContent">
72+
<a href="login.php" class="loginButton">Login</a>
73+
<h1>CDN Upload</h1>
74+
<form action="upload.php" method="post" enctype="multipart/form-data">
75+
<label for="fileToUpload" class="uploadButton">Select Your Image To Upload!</label>
76+
<input type="file" name="fileToUpload" id="fileToUpload"><br><br>Your Image:<br><br>
77+
<img id="blah" src="#" alt="" style="max-width: 200px; max-height: 200px;"/>
78+
<br><br>
79+
<input class="inputButton" type="submit" value="Upload Image" name="submit">
80+
<a href="">View me on GitHub!</a>
81+
</form>
82+
</div>
83+
<script>function readURL(input) {
84+
if (input.files && input.files[0]) {
85+
var reader = new FileReader();
86+
87+
reader.onload = function(e) {
88+
$('#blah').attr('src', e.target.result);
89+
}
90+
91+
reader.readAsDataURL(input.files[0]); // convert to base64 string
92+
}
93+
}
94+
95+
$("#fileToUpload").change(function() {
96+
readURL(this);
97+
});</script>
98+
</body>
99+
</html>

0 commit comments

Comments
 (0)