Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Client/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

17 changes: 15 additions & 2 deletions Client/app.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
from Client.tcp_client import TCPClient

from flask import Flask, render_template, request, jsonify, redirect, url_for, session, flash
from tcp_client import TCPClient

import time
import base64
import os

from datetime import datetime
from database import Database
from Client.database import Database

app = Flask(__name__)
app.secret_key = os.urandom(24)
app.secret_key = os.urandom(24)

tcp_client = TCPClient(server_host='localhost', server_port=5001)


# comment_manager = CommentManager()
# image_manager = ImageManager()

upload_images = []
db = Database()


@app.route('/')
def login():
# Check if user is already logged in
if 'user_id' in session:
return redirect(url_for('index'))
# Check if user is already logged in
if 'user_id' in session:
return redirect(url_for('index'))
return render_template('login.html')
Expand Down
15 changes: 14 additions & 1 deletion Client/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,20 @@ def _insert_default_data(self):
(8, "/static/images/8.jpg", "Clothes that Guarantee Survival", "Clothes", 1, 1),
(9, "/static/images/9.jpg", "If you don'T have these in your pantry, uh oh", "Meal Prep", 1, 1),
(10, "/static/images/10.jpg", "Rebuild after the apocalypse is over with these plants", "Gardening", 1, 1),
(11, "/static/images/11.jpg", "Flowers will be worth millions soon, enjoy them now", "Gardening", 1, 1)
(11, "/static/images/11.jpg", "Flowers will be worth millions soon, enjoy them now", "Gardening", 1, 1),
(12, "/static/images/12.jpg", "Are you ready? Are you sure?", "Tips", 1, 1),
(13, "/static/images/13.jpg", "Read this to help!", "Hacks", 1, 1),
(14, "/static/images/14.jpg", "All natural weapons", "Tools", 1, 1),
(15, "/static/images/15.jpg", "Delicious bread for when the world ends ", "Food", 1, 1),
(16, "/static/images/16.jpg", "The end is near..", "Tips", 1, 1),
(17, "/static/images/17.jpg", "15 Reasons you need to prep NOW", "Tips", 1, 1),
(18, "/static/images/18.jpg", "Stockpile = Survival", "Tips", 1, 1),
(19, "/static/images/19.jpg", "18 Best foods you NEED to prep", "Meal Prep", 1, 1),
(20, "/static/images/20.jpg", "Number 27 is shocking..", "Tips", 1, 1),
(21, "/static/images/21.jpg", "THESE IDEAS WILL SAVE YOUR LIFE", "Tips", 1, 1),
(22, "/static/images/22.jpg", "This is our future world.. get ready", "Tips", 1, 1),
(23, "/static/images/23.jpg", "You NEED to know about this..", "Tips", 1, 1),
(24, "/static/images/24.jpg", "Which prepper type are you??", "Tips", 1, 1)
]

self.cursor.executemany(
Expand Down
3 changes: 1 addition & 2 deletions Client/image_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def upload_image(self, image_file, caption, tags):
'id': len(self.uploaded_images) + 1,
'url': f"/static/uploads/{image_filename}",
'caption': caption,
'category': tags,
'image': base64_image
'category': tags
}

#store in file (while db not up)
Expand Down
7 changes: 0 additions & 7 deletions Client/images.json

Large diffs are not rendered by default.

Binary file modified Client/preppersdb.sqlite
Binary file not shown.
6 changes: 6 additions & 0 deletions Client/saved_images.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
"url": "./static/images/3.jpg",
"caption": "Amazing Survival Recipes",
"category": "Meal Prep"
},
{
"id": 6,
"url": "./static/images/6.jpg",
"caption": "World War 3 is Coming, are you Prepared??",
"category": "Tips"
}
]
}
133 changes: 132 additions & 1 deletion Client/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,44 @@ body {
}



body {
background-color: #f5f1e8;
}

/* Container styling */
.container.mt-4 {
background-color: #f9f7f3;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.03);
}


.navbar {
background-color: #e8ded1 !important;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
margin-bottom: 20px;
}


.card {
margin-bottom: 20px;
border-radius: 16px;
overflow: hidden;
transition: transform 0.3s ease;
max-width: 300px;
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}


.card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}


.card-img-top {
width: 100%;
object-fit: cover;
Expand Down Expand Up @@ -64,10 +88,21 @@ body.login-page {

.form-group {
color: white;

background-color: transparent;
}

.formbg {
body.login-page {

background-color: transparent;
}

.form-group {
color: white;
}

.formbg {

width: 75%;
}

Expand All @@ -76,6 +111,13 @@ body.login-page {
background-color: rgba(14, 13, 13, 0.5);
}

.login-container {
background-color: rgba(14, 13, 13, 0.7);
border-radius: 8px;
padding: 30px;
color: white;
}
/* upload */
.login-container {
background-color: rgba(14, 13, 13, 0.7);
border-radius: 8px;
Expand Down Expand Up @@ -112,10 +154,13 @@ body.login-page {
max-height: 250px;
border-radius: 4px;
}

/* comment */
/* comment */
#modalImage {
max-height: 600px;
width: 100%;
width: 100%;
object-fit: contain;
}

Expand Down Expand Up @@ -214,3 +259,89 @@ body.login-page {
padding: 8px 20px;
}



/* Button */
.btn-sm {
border-radius: 20px;
padding: 0.25rem 0.8rem;
}

.btn-outline-success:hover {
background-color: #28a745;
border-color: #28a745;
}

/* Profile Page*/
.profile-image {
width: 200px;
height: 200px;
object-fit: cover;
border-radius: 50%;
border: 5px solid #fff;
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
margin-bottom: 20px;
transition: transform 0.3s;
}

.profile-image:hover {
transform: scale(1.05);
}

.profile-card {
text-align: center;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0,0,0,0.1);
background-color: #fff;
margin-bottom: 20px;
}

.stat-card {
border-radius: 10px;
padding: 15px;
margin-bottom: 15px;
background-color: #f8f9fa;
transition: transform 0.3s, box-shadow 0.3s;
}

.stat-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}

.stat-number {
font-size: 2.5rem;
font-weight: bold;
color: #198754;
}

.stat-label {
color: #6c757d;
font-size: 1rem;
}

.user-info {
margin: 20px 0;
}

.user-info-item {
display: flex;
margin-bottom: 15px;
padding-bottom: 15px;
border-bottom: 1px solid #eee;
}

.user-info-label {
font-weight: bold;
min-width: 120px;
}

.action-buttons {
margin-top: 20px;
}

.action-buttons .btn {
margin: 0 5px;
padding: 8px 20px;
}
Binary file added Client/static/images/13.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Client/static/images/14.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Client/static/images/15.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Client/static/images/16.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Client/static/images/17.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Client/static/images/18.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Client/static/images/19.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Client/static/images/20.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Client/static/images/21.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Client/static/images/22.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Client/static/images/23.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Client/static/images/24.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions Client/static/js/image-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,55 @@ document.addEventListener('DOMContentLoaded', function () {
});
});

//when clicking the save image button on a specific image
document.addEventListener("DOMContentLoaded", function() {
const saveButtons = document.querySelectorAll(".save-btn");

saveButtons.forEach(button => {
button.addEventListener("click", function() {
const imageId = this.getAttribute("data-id");

fetch('/save_image', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ image_id: imageId })
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert('Image saved to your vault!!');
} else {
alert('Couldnt save the image, please try again later.' + data.message);
}
})
.catch(error => {
console.error('Error:', error);
alert('Couldnt save the image, please try again later.');
});
});
});
});

document.addEventListener('DOMContentLoaded', function () {
//masonry info: https://masonry.desandro.com/
//to make a grid, pinterest style
var grid = document.querySelector('#masonry-grid');
var masonry = new Masonry(grid, {
itemSelector: '.card',
columnWidth: '.card',
percentPosition: true,
gutter: 15
});

//layout after loading images
var imgLoad = imagesLoaded(grid);
imgLoad.on('progress', function () {
masonry.layout();
});
});

//when clicking the save image button on a specific image
document.addEventListener("DOMContentLoaded", function() {
// Handle Save to Vault buttons
Expand Down
11 changes: 9 additions & 2 deletions Client/tcp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import hashlib
import time

logging.basicConfig(

# Logging structure for btoh clent and server
logging.basicConfig(
filename='client_log.txt',
filemode='w',
level=logging.INFO,
Expand Down Expand Up @@ -47,7 +49,8 @@ def connect(self):
self.connected = False
return False

def disconnect(self):
def disconnect(self): # pragma: no cover
"""Disconnect from the server"""
if self.socket:
self.socket.close()
self.socket = None
Expand All @@ -59,6 +62,7 @@ def send_request(self, command, data):
if not self.connect():
return False, "Failed to connect to server"

# Create request packet
packet = self.create_packet(command, data)
#ALL NAMING FUNCTIONS THAT SERVER SHOULD CALL
try:
Expand Down Expand Up @@ -148,12 +152,15 @@ def receive_response(self, timeout=10):
logger.warning("Received empty response from server")
return None


response = json.loads(data)

# Validate header
if 'header' not in response:
logger.warning("Invalid response format - missing header")
return None

# Validate checksum
if 'footer' in response and 'checksum' in response['footer']:
if not self.validate_checksum(json.dumps(response['body']), response['footer']['checksum']):
logger.warning("Response checksum validation failed")
Expand Down
2 changes: 2 additions & 0 deletions Client/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
{% else %}
<a href="{{ url_for('login') }}" class="btn btn-primary">Login</a>
{% endif %}

</div>
</div>
</nav>
Expand All @@ -68,6 +69,7 @@
<!--masonry-->
<script src="https://cdn.jsdelivr.net/npm/masonry-layout@4.2.2/dist/masonry.pkgd.min.js"></script>


<!-- Common JavaScript -->
<script src="{{ url_for('static', filename='js/app.js') }}"></script>

Expand Down
2 changes: 1 addition & 1 deletion Client/templates/image-grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ <h5 class="card-title">{{ image.caption }}</h5>
</div>
{% include "comments.html" %}

<script src="{{ url_for('static', filename='js/image-grid.js') }}"></script>

<script src="{{ url_for('static', filename='js/image-grid.js') }}"></script>
Loading