Skip to content

Commit

Permalink
feat: restructure static and template directory
Browse files Browse the repository at this point in the history
  • Loading branch information
datlt4 committed Apr 18, 2024
1 parent 948eec3 commit c4bb51b
Show file tree
Hide file tree
Showing 41 changed files with 132 additions and 139 deletions.
39 changes: 24 additions & 15 deletions fhost.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def activate_required(func):
def decorated_function(*args, **kwargs):
if (current_user is not None) and (current_user.is_authenticated) and (not current_user.is_confirmed):
flash("Your account has not activated yet", "not-activated")
return render_template("activate-account.html")
return render_template("auth/activate-account.html")
return func(*args, **kwargs)
return decorated_function

Expand Down Expand Up @@ -668,7 +668,7 @@ def request_activate_account():
send_email(subject="Activate your ZXZ account",
sender=app.config["MAIL_USERNAME"],
recipients=[current_user.email], text_body="HELLO",
html_body=render_template("email-activate-account.html", token=token, expires_in=app.config["ACTIVATE_EMAIL_TOKEN_EXPIRES_IN"]))
html_body=render_template("auth/email-activate-account.html", token=token, expires_in=app.config["ACTIVATE_EMAIL_TOKEN_EXPIRES_IN"]))
return {"status": "OK"}
except Exception as e:
print(e)
Expand All @@ -682,12 +682,12 @@ def activate_account(token):
return redirect(url_for("fhost"))
elif user.is_confirmed:
flash('ACCOUNT WAS ACTIVATED SUCCESSFULLY.', 'account-activated')
return render_template("activate-account-success.html")
return render_template("auth/activate-account-success.html")
else:
user.confirm_email()
db.session.commit()
flash('ACCOUNT WAS ACTIVATED SUCCESSFULLY.', 'account-activated')
return render_template("activate-account-success.html")
return render_template("auth/activate-account-success.html")

@app.route('/forgot-password', methods=["GET", "POST"])
@logout_required
Expand All @@ -700,19 +700,19 @@ def forgot_password():
flash('Email address has not unregistered yet.', 'unregistered')
return redirect(url_for("signup"))
token = user.get_reset_password_token(app.config["RESET_PASSWORD_TOKEN_EXPIRES_IN"]*60, type_token="reset-password")
# return render_template("email-reset-password.html", token=token, expires_in=app.config["RESET_PASSWORD_TOKEN_EXPIRES_IN"])
# return render_template("auth/email-reset-password.html", token=token, expires_in=app.config["RESET_PASSWORD_TOKEN_EXPIRES_IN"])
try:
send_email(subject="Reset your ZXZ account password",
sender=app.config["MAIL_USERNAME"],
recipients=[email], text_body="HELLO",
html_body=render_template("email-reset-password.html", token=token, expires_in=app.config["RESET_PASSWORD_TOKEN_EXPIRES_IN"]))
html_body=render_template("auth/email-reset-password.html", token=token, expires_in=app.config["RESET_PASSWORD_TOKEN_EXPIRES_IN"]))
flash('Reset password request sent. Check your email.', 'mail-sent')
flash(email, 'fill-email')
return redirect(url_for("login"))
except Exception as e:
abort(HTTPStatus.INTERNAL_SERVER_ERROR)
else:
return render_template("forgot-password.html")
return render_template("auth/forgot-password.html")

@app.route('/reset-password/<token>', methods=["GET", "POST"])
@logout_required
Expand All @@ -739,7 +739,7 @@ def reset_password(token:str):
else:
flash(user.email, 'email')
flash(user.username, 'username')
return render_template("reset-password.html", token=token)
return render_template("auth/reset-password.html", token=token)

@app.route('/login', methods=["GET", "POST"])
@logout_required
Expand Down Expand Up @@ -778,7 +778,7 @@ def login():
flash("", 'first-user')
return redirect(url_for('signup'))
else:
return render_template("login.html")
return render_template("auth/login.html")

@app.route('/signup', methods=["GET", "POST"])
@logout_required
Expand Down Expand Up @@ -820,7 +820,7 @@ def signup():
send_email(subject="Activate your ZXZ account",
sender=app.config["MAIL_USERNAME"],
recipients=[email], text_body="HELLO",
html_body=render_template("email-activate-account.html", token=token, expires_in=app.config["ACTIVATE_EMAIL_TOKEN_EXPIRES_IN"]))
html_body=render_template("auth/email-activate-account.html", token=token, expires_in=app.config["ACTIVATE_EMAIL_TOKEN_EXPIRES_IN"]))
flash('Activate account request sent. Check your email.', 'mail-sent')
except Exception as e:
print(e)
Expand All @@ -833,7 +833,7 @@ def signup():
else:
if db.session.query(User).count() <= 1:
flash("", 'first-user')
return render_template('signup.html')
return render_template('auth/signup.html')

@app.route('/logout', methods=["GET", "POST"])
@login_required
Expand All @@ -845,7 +845,7 @@ def logout():
@login_required
@activate_required
def profile():
return render_template("profile.html")
return render_template("auth/profile.html")

@app.route('/change-password', methods=["POST"])
@login_required
Expand Down Expand Up @@ -1014,10 +1014,19 @@ def fhost():
else:
f.write(chunk)
os.system(f"ls -lht {file_path}")

# get expires and handle if if expires fields is NaN
expires = None
try:
if "expires" in request.form:
expires = int(request.form["expires"])
except Exception as e:
print(e)

# Store the file with the requested expiration date
return store_file(
request.files["file"],
int(request.form["expires"]) if ("expires" in request.form) else None,
expires,
request.remote_addr,
request.user_agent.string,
slugify(request.form["secret"]) if ("secret" in request.form) else None,
Expand All @@ -1041,7 +1050,7 @@ def fhost():

abort(400)
else:
return render_template("index.html")
return render_template("pages/index.html")

@app.route('/fetch-content', methods=["POST"])
@activate_required
Expand Down Expand Up @@ -1117,7 +1126,7 @@ def robots():
@app.errorhandler(500)
def ehandler(e):
try:
return render_template(f"{e.code}.html", id=id, request=request), e.code
return render_template(f"errors/{e.code}.html", id=id, request=request), e.code
except TemplateNotFound:
return "Segmentation fault\n", e.code

Expand Down
114 changes: 78 additions & 36 deletions static/app.css → static/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@
}

#content-wrap {
padding-bottom: 2.5rem; /* Footer height */
padding-bottom: 2.5rem;
/* Footer height */
}

.footer {
background-color: #343a40; /* Dark color similar to the header */
background-color: #343a40;
/* Dark color similar to the header */
padding: 20px 0;
text-align: center;
color: #fff; /* White text color */
color: #fff;
/* White text color */
/* position: absolute; */
bottom: 0;
width: 100%;
}

.footer p {
margin-bottom: 5px; /* Add some spacing between paragraphs */
margin-bottom: 5px;
/* Add some spacing between paragraphs */
}

/* Ensure content is pushed down when header and footer are fixed */
Expand All @@ -38,15 +42,16 @@ body {
display: flex;
flex-direction: column;
margin: 0;
min-height: 100vh; /* Ensure the body takes up at least the full viewport height */
min-height: 100vh;
/* Ensure the body takes up at least the full viewport height */
}

input:disabled {
background-color: #f8f9fa !important;
}

input:hover {
border-color: #0250b7 !important;
border-color: #0250b7 !important;
}

hr {
Expand All @@ -64,12 +69,14 @@ hr {

/* Add some margin to the bottom of the body content */
.content {
margin-bottom: 70px; /* Height of the footer */
margin-bottom: 70px;
/* Height of the footer */
}

/* Add some spacing to top of content to account for fixed header */
.content {
padding-top: 80px; /* Height of the fixed header + some extra spacing */
padding-top: 80px;
/* Height of the fixed header + some extra spacing */
}

.container {
Expand Down Expand Up @@ -152,18 +159,24 @@ li:before {
}

.show {
display: block; /* Display the checkmark when it has the 'show' class */
opacity: 1; /* Ensure the checkmark is fully visible */
transition: opacity 0.3s linear; /* Add transition effect for opacity */
display: block;
/* Display the checkmark when it has the 'show' class */
opacity: 1;
/* Ensure the checkmark is fully visible */
transition: opacity 0.3s linear;
/* Add transition effect for opacity */
}

.hide {
opacity: 0; /* Set opacity to 0 when hiding */
transition: opacity 0.2s linear; /* Add transition effect for opacity */
opacity: 0;
/* Set opacity to 0 when hiding */
transition: opacity 0.2s linear;
/* Add transition effect for opacity */
}

.CodeMirror {
font-size: 11px; /* Adjust the font size as needed */
font-size: 11px;
/* Adjust the font size as needed */
}

.nav-btn {
Expand Down Expand Up @@ -217,13 +230,15 @@ li:before {
}

.bi-person {
font-size: 18px; /* Adjust icon size as needed */
font-size: 18px;
/* Adjust icon size as needed */
}

/* Popup container - can be anything you want */
.user-avatar-container {
position: relative;
}

/* The actual popup */
.popup-profile {
visibility: hidden;
Expand Down Expand Up @@ -264,7 +279,8 @@ li:before {

.user-profile-btn {
background-color: #373b3e;
align-items: center; /* Center items vertically */
align-items: center;
/* Center items vertically */
text-align: left;
color: #ffffff;
border-color: transparent;
Expand All @@ -278,13 +294,23 @@ li:before {

/* Add animation (fade in the popup) */
@-webkit-keyframes fadeIn {
from {opacity: 0;}
to {opacity: 1;}
from {
opacity: 0;
}

to {
opacity: 0.5;
}
}

@keyframes fadeIn {
from {opacity: 0;}
to {opacity:1 ;}
from {
opacity: 0;
}

to {
opacity: 0.5;
}
}

.accordion-button {
Expand Down Expand Up @@ -319,43 +345,59 @@ input.form-control {

/* Customize the button styles */
.btn-outline-primary.custom-btn {
color: #3b5482; /* Text color */
border-color: #3b5482; /* Border color */
color: #3b5482;
/* Text color */
border-color: #3b5482;
/* Border color */
}

.btn-outline-primary.custom-btn:hover {
color: #fff; /* Text color on hover */
background-color: #3b5482; /* Background color on hover */
border-color: #3b5482; /* Border color on hover */
color: #fff;
/* Text color on hover */
background-color: #3b5482;
/* Background color on hover */
border-color: #3b5482;
/* Border color on hover */
}

.btn-outline-primary.custom-btn {
color: #3b5482; /* Text color */
border-color: #3b5482; /* Border color */
color: #3b5482;
/* Text color */
border-color: #3b5482;
/* Border color */
}

.btn-outline-primary.custom-btn:hover {
color: #fff; /* Text color on hover */
background-color: #3b5482; /* Background color on hover */
border-color: #3b5482; /* Border color on hover */
color: #fff;
/* Text color on hover */
background-color: #3b5482;
/* Background color on hover */
border-color: #3b5482;
/* Border color on hover */
}

.btn-primary.custom-btn:focus {
box-shadow: 0 0 0 0.25rem rgba(59, 84, 130, 0.5); /* Custom focus shadow */
box-shadow: 0 0 0 0.25rem rgba(59, 84, 130, 0.5);
/* Custom focus shadow */
}

.btn-primary.custom-btn {
background-color: #3b5482; /* Background color */
border-color: #3b5482; /* Border color */
background-color: #3b5482;
/* Background color */
border-color: #3b5482;
/* Border color */
}

.btn-primary.custom-btn:hover {
background-color: #2a3e5f; /* Darker background color on hover */
border-color: #2a3e5f; /* Darker border color on hover */
background-color: #2a3e5f;
/* Darker background color on hover */
border-color: #2a3e5f;
/* Darker border color on hover */
}

.btn-primary.custom-btn:focus {
box-shadow: 0 0 0 0.25rem rgba(59, 84, 130, 0.5); /* Custom focus shadow */
box-shadow: 0 0 0 0.25rem rgba(59, 84, 130, 0.5);
/* Custom focus shadow */
}

.toast-header.danger {
Expand Down
Binary file removed static/favicon.ico
Binary file not shown.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ function requestEmailToActivate() {
fetch("/request-activate-account", { method: "POST" })
.then(response => {
if (response.ok) {
console.log("request-activate-account: OKE");
insertMessageIntoToast("", "Activation email has sent successfully", "success")
} else {
console.log("request-activate-account: FAILED");
insertMessageIntoToast("", "Got error when sent email", "danger")
}
})
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions static/header.js → static/js/header.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
document.addEventListener("DOMContentLoaded", function() {
document.addEventListener("DOMContentLoaded", function () {
// const avatar = document.getElementById('avatar');
const avatar = document.getElementById('avatar');
if (avatar) {
avatar.addEventListener('click', function() {
avatar.addEventListener('click', function () {
avatar.classList.toggle('active');
document.getElementById("popup-user-profile").classList.toggle("show");
});
}
});
});
File renamed without changes.
Loading

0 comments on commit c4bb51b

Please sign in to comment.