Repository
https://github.com/jrswab/archivatory
New Features
- What feature(s) did you add?
- Now using Bootstrap CSS styling
- User accounts
- User Upload List
How did you implement it/them?
Account Creation:
Apache uses PHP to send MySQL commands to the server as an authorized (but limited) user.
// Check input errors before inserting in database
if(empty($username_err) && empty($password_err) && empty($confirm_password_err)){
// Prepare an insert statement
$sql = "INSERT INTO users (username, password) VALUES (?, ?)";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "ss", $param_username, $param_password);
// Set parameters
$param_username = $username;
$param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Redirect to login page
header("location: login.php");
} else{
echo "Something went wrong. Please try again later.";
}
}
// Close statement
mysqli_stmt_close($stmt);
See register.php on GitHub for the full code used
User Login
Again used PHP to look up the hashed and salted string in the database for the user's password.
// Validate credentials
if(empty($username_err) && empty($password_err)){
// Prepare a select statement
$sql = "SELECT username, password FROM users WHERE username = ?";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_username);
// Set parameters
$param_username = $username;
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Store result
mysqli_stmt_store_result($stmt);
// Check if username exists, if yes then verify password
if(mysqli_stmt_num_rows($stmt) == 1){
// Bind result variables
mysqli_stmt_bind_result($stmt, $username, $hashed_password);
if(mysqli_stmt_fetch($stmt)){
if(password_verify($password, $hashed_password)){
/* Password is correct, so start a new session and
save the username to the session */
session_start();
$_SESSION['username'] = $username;
header("location: welcome.php");
} else{
// Display an error message if password is not valid
$password_err = 'The password you entered was not valid.';
}
}
} else{
// Display an error message if username doesn't exist
$username_err = 'No account found with that username.';
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
mysqli_stmt_close($stmt);
See login.php on GitHub for the full code used
To make sure I did not get this wrong I used this guide when setting up account creation and sign in pages.
Create User table for storing upload information:
First make sure the user is logged in:
<?php
// Initialize the session
session_start();
// If session variable is not set it will redirect to login page
if(!isset($_SESSION['username']) || empty($_SESSION['username'])){
header("location: login.php");
exit;
}
?>
Then create the users' table if if it does not already exist.
// Loging info for database contianing user tables.
include_once 'config/uploadDBconfig.php';
// Check if a table call 'username' exists
if ($tableCheck = $link->query("SHOW TABLES LIKE '".$_SESSION['username']."'")) {
if($tableCheck->num_rows == 1) {
echo "Table Exists";
} else {
$sql = "CREATE TABLE " . $_SESSION['username'] . " (
date TIMESTAMP NOT NULL,
file_name VARCHAR(256) NOT NULL,
hash VARCHAR(256) NOT NULL,
file_size VARCHAR(256) NOT NULL,
id VARCHAR(256) NOT NULL)";
$link->query($sql);
}
}
See memUp.php on GitHub for the full code used
User Upload List
First make sure the user is logged in:
<?php
// Initialize the session
session_start();
// If session variable is not set it will redirect to login page
if(!isset($_SESSION['username']) || empty($_SESSION['username'])){
header("location: login.php");
exit;
}
?>
Then build the list of uploads from the user created table on the user upload page.
<?php
include_once 'config/uploadDBconfig.php';
// query user data
$sql = "SELECT * FROM ".$_SESSION['username']." ORDER BY date DESC;";
$result = mysqli_query($link, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
// Set up the html table
echo "";
echo ""
;
echo "Upload Date File Name IPFS Hash File Size (in bytes) ";
echo "";
// loop through users' table and output into html table body
while ($row = mysqli_fetch_assoc($result)) {
echo "" .$row['date']."" .$row['file_name']."<a href='https://ipfs.io/ipfs/"</span><span class="ll-pct">.</span><span class="ll-nam">$row</span><span class="ll-pct">[</span><span class="ll-str">'hash' ]."' target='_blank'>".$row['hash']."" .$row['file_size']."";
}
// end html table
echo "";
echo "";
echo "";
}
?>
See hashtable.php on GitHub for the full code used
Future Developments
- Allow users to create an RSS feed of their IPFS content
- Allow users to create playlists of their IPFS content
- Allow the user to delete their upload from Archivatorys' server
- Allow users to pin content from other sources (eg. Dtube, Dsound, Dlive)
- User account settings
GitHub Account
or my witness please feel free to message
jrswab#3134 on Discord.Click here to vote with SteemConnect!
Or go to https://steemit.com/~witnesses
You can see all active witnesses on ' steemian.info
Click here to join the mailing list and get exclusive SDB/STEEM giveaways!
Looking to support my content creation efforts outside of the Steem Blockchain?
Check out jrswab.com/support
Mastodon | Keybase | Twitter | Gitlab | Hacker Culture Podcast