Skip to content
Snippets Groups Projects
Commit 77975300 authored by Kacper Polczynski's avatar Kacper Polczynski
Browse files

references

parent f3997117
No related branches found
No related tags found
No related merge requests found
...@@ -18,7 +18,10 @@ db = SQLAlchemy(app) ...@@ -18,7 +18,10 @@ db = SQLAlchemy(app)
login_manager = LoginManager() login_manager = LoginManager()
login_manager.init_app(app) login_manager.init_app(app)
#End of models definition
#Code snippets from:https://www.geeksforgeeks.org/how-to-add-authentication-to-your-app-with-flask-login/
#accessed on 22nd decemeber
#Used base login and register feature to add authentication to the app to allow other features
@login_manager.user_loader @login_manager.user_loader
def loader_user(user_id): def loader_user(user_id):
return Users.query.get(user_id) return Users.query.get(user_id)
...@@ -52,8 +55,7 @@ class Comments(db.Model): ...@@ -52,8 +55,7 @@ class Comments(db.Model):
with app.app_context(): with app.app_context():
db.create_all() db.create_all()
#End of models definition
#https://www.geeksforgeeks.org/how-to-add-authentication-to-your-app-with-flask-login/
UPLOAD_FOLDER = os.path.join(basedir, 'static/uploads') UPLOAD_FOLDER = os.path.join(basedir, 'static/uploads')
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'} ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
...@@ -105,6 +107,9 @@ def projects(): ...@@ -105,6 +107,9 @@ def projects():
return render_template('projects.html' , projects=projects,comments=comments_dict) return render_template('projects.html' , projects=projects,comments=comments_dict)
#Section for uploading photo #Section for uploading photo
#Code adapted from: https://openjavascript.info/2022/06/08/how-to-upload-a-file-using-the-fetch-api/
# Accessed on 12/12/2024
# This code allowed me to upload a photo file to the server which has been adapted to link to other projects
@app.route('/upload', methods=['POST']) #Photo upload @app.route('/upload', methods=['POST']) #Photo upload
def upload_photo(): def upload_photo():
if request.method =='POST': if request.method =='POST':
...@@ -188,7 +193,10 @@ def register(): ...@@ -188,7 +193,10 @@ def register():
flash('User registered successfully!', 'success') flash('User registered successfully!', 'success')
return redirect(url_for('login')) return redirect(url_for('login'))
return render_template('register.html') return render_template('register.html')
#End of models definition
#Code snippets from:https://www.geeksforgeeks.org/how-to-add-authentication-to-your-app-with-flask-login/
#accessed on 22nd decemeber
#Used base login and register feature to add authentication to the app to allow other features
@app.route('/login', methods=["GET", "POST"]) @app.route('/login', methods=["GET", "POST"])
def login(): def login():
if request.method == "POST": if request.method == "POST":
......
/*code adapted from: https://www.w3schools.com/howto/howto_css_modals.asp*/
/*Accessed on 12/12/2024*/
/*modal pop up allowed me to implement a form to add a project*/
var modal = document.getElementById("myModal"); var modal = document.getElementById("myModal");
var btn = document.getElementById("add-proj-btn"); var btn = document.getElementById("add-proj-btn");
var span = document.getElementsByClassName("close")[0]; var span = document.getElementsByClassName("close")[0];
...@@ -37,7 +39,9 @@ form.addEventListener('submit', async (e) => { ...@@ -37,7 +39,9 @@ form.addEventListener('submit', async (e) => {
const payload = new FormData(); const payload = new FormData();
payload.append("photo_url", file); payload.append("photo_url", file);
/*https://openjavascript.info/2022/06/08/how-to-upload-a-file-using-the-fetch-api/*/ /* Code adapted from: https://openjavascript.info/2022/06/08/how-to-upload-a-file-using-the-fetch-api/ */
/*Accessed on 12/12/2024*/
/*This code allowed me to upload a file to the server*/
try { try {
const photoupload = await fetch('/upload', { const photoupload = await fetch('/upload', {
method : 'POST', method : 'POST',
......
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
</div> </div>
{% endif %} {% endif %}
<!-- Pop Up to Add Projects--> <!-- Pop Up to Add Projects-->
<!--code adapted from: https://www.w3schools.com/howto/howto_css_modals.asp*/
Accessed on 12/12/2024*/
modal pop up allowed me to implement a form to add a project-->
<div id ="myModal" class="modal"> <div id ="myModal" class="modal">
<div class = "modal-content"> <div class = "modal-content">
<span class="close">&times;</span> <span class="close">&times;</span>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment