Skip to content

Commit

Permalink
vdvf
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammedHamioui committed May 30, 2022
2 parents 916dab2 + ff42413 commit 7ef5258
Show file tree
Hide file tree
Showing 8 changed files with 576 additions and 30 deletions.
8 changes: 8 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 19 additions & 13 deletions flask_app.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import secrets
import sqlite3
import string
from pathlib import Path

import requests
import os
from flask import Flask, jsonify, request, render_template

app = Flask(__name__)


def generate_uid(db_id):
alphabet = string.ascii_lowercase + string.digits
return f"{db_id}-" + ''.join(secrets.choice(alphabet) for _ in range(4))
return f"{db_id}-" + ''.join(secrets.choice(alphabet) for _ in range(8))


def dict_factory(cursor, row):
Expand All @@ -27,7 +27,6 @@ def db_connect():
cursor = connection.cursor()
return cursor, connection


@app.route('/')
def home():
cur, conn = db_connect()
Expand All @@ -52,19 +51,25 @@ def list_cards():
@app.route('/wish/<card_id>')
def wish_form(card_id):
cur, conn = db_connect()
card = cur.execute(f'SELECT * FROM card WHERE cardid={card_id};').fetchone()
card = cur.execute("SELECT * FROM card WHERE cardid=?", (card_id,)).fetchone()
conn.close()
return render_template("send_wish.html", card=card)


def send_mail(email, sender, cardid, uid):
def send_mail(email, sender,receiver, cardid, uid):
card_img = f"http://zappsters.pythonanywhere.com/static/{cardid}.jpg"
banner_img = f"http://zappsters.pythonanywhere.com/static/mail_banner.jpeg"
logo_img = f"http://zappsters.pythonanywhere.com/static/logo_mail.png"
git_img = f"http://zappsters.pythonanywhere.com/static/git.png"

x = requests.post("https://api.mailgun.net/v3/sandboxa39931aba4ea43a885c240d815b0a2c2.mailgun.org/messages",
auth=("api", "9374b99615d0f43ff1e12995ef3c3317-8d821f0c-6df1ae28"),
files=[('inline[0]', ('card.jpg', open(f'{os.getcwd()}/static/{cardid}.jpg', mode='rb').read()))],
files=[('inline[0]', ('card.jpg', open(Path.cwd() / f'static/{cardid}.jpg', mode='rb').read()))],
data={"from": "[email protected]",
"to": [f"{email}"],
"subject": "Greeting card",
"text": f"You have been sent an AR greeting card from {sender}! The unique code for your personnel message i: " + uid})
"html": render_template("mail.html", sender=sender, code=uid, receiver=receiver,
card=card_img, banner=banner_img, logo=logo_img, git=git_img)})
return x.text


Expand All @@ -89,11 +94,12 @@ def wish_insert():
uid = generate_uid(db_id)

if send_method == "email":
send_mail(send_destination,sender,card_id, uid)
send_mail(send_destination, sender,receiver, card_id, uid)

card = cur.execute('SELECT * FROM card WHERE cardid' + '=' + str(card_id) + ';').fetchone()
card = cur.execute("SELECT * FROM card WHERE cardid=?", (card_id,)).fetchone()
print(card)
conn.execute(
f"INSERT INTO wish (uid, sender, message, cardid) VALUES (\'{uid}\', \'{sender}\', \'{message}\', {card_id})")
"INSERT INTO wish (uid, sender, message, cardid) VALUES (?,?,?,?)", (uid, sender, message, card_id))
conn.commit()
conn.close()
return render_template("confirm_wish.html", card=card)
Expand All @@ -108,7 +114,7 @@ def get_wish():
def result_wish():
uid = request.form.get("uuid")
cur, conn = db_connect()
personal_card = cur.execute(f"SELECT * FROM wish WHERE uid=\'{uid}\';").fetchone()
personal_card = cur.execute("SELECT * FROM wish WHERE uid=?", (uid,)).fetchone()
conn.close()
return render_template("show_wish.html", card=personal_card)

Expand All @@ -124,11 +130,11 @@ def get_personal_wish():
# connect and open the database file database.db
cur, conn = db_connect()
# read the associated personal wish, you will need an extra integer field code in your wish table!
wish = cur.execute(f"SELECT * FROM wish WHERE code={code}").fetchall()
wish = cur.execute("SELECT * FROM wish WHERE code=?", (code,)).fetchall()
conn.close()
# there's only one wish because the code is unique
response = jsonify(wish[0])

# allow cross-domain Ajax requests, more info in later years
response.headers.add("Access-Control-Allow-Origin", "*")
return response
return response
Binary file added static/git.png
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 static/logo_mail.png
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 static/mail_banner.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 48 additions & 17 deletions templates/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,32 @@
{% block content %}
<h1 class="HeadTitle">Over ons</h1>
<div class="row">
<div class="col-6 col-sm-4 mx-auto text-center">
<figure>
<img class="rounded-circle mt-3 img-fluid" src="/static/foto%20matthias.png" alt="matthias" width="200" height="200" />
<figcaption class="pt-3">
<span class="fw-bold">Matthias Theys</span><br />Ik ben Matthias, 19 jaar en vindt het leuk om mij bezig te houden met auto's en en Netwerken.
</figcaption>
</figure>
</div>
<div class="col-6 col-sm-4 mx-auto text-center">
<figure>
<img class="rounded-circle mt-3 img-fluid" src="/static/Mo.png" alt="Mohammed" width="200" height="200" />
<figcaption class="pt-3">
<span class="fw-bold">Mohammed Hamioui</span><br />Ik ben Mohammed, 19 jaar en heb passie voor technologie en cyber security. Verantwoordelijk voor de business kaart layout en het front-end gedeelte van de website.<br />
</figcaption>
</figure>
</div>
<div class="col-6 col-sm-4 mx-auto text-center">
<figure>
<img class="rounded-circle mt-3 img-fluid" src="/static/foto%20matthias.png" alt="matthias" width="200"
height="200"/>
<figcaption class="pt-3">
<span class="fw-bold">Matthias Theys</span><br/>Ik ben Matthias, 19 jaar en vindt het leuk om mij
bezig te houden met auto's en en Netwerken.
</figcaption>
</figure>
</div>
<div class="col-6 col-sm-4 mx-auto text-center">
<figure>
<img class="rounded-circle mt-3 img-fluid" src="/static/Mo.png" alt="Mohammed" width="200"
height="200"/>
<figcaption class="pt-3">
<span class="fw-bold">Mohammed Hamioui</span><br/>Ik ben Mohammed, 19 jaar en heb passie voor
technologie en cyber security. Verantwoordelijk voor de business kaart layout en het front-end
gedeelte van de website<br/>
</figcaption>
</figure>
</div>
>>>>>>> ff4241330bf771777f8c00ae0d86802851513bd8

<div class="w-100 d-none d-md-block"></div>
<div class="w-100 d-none d-md-block"></div>

<<<<<<< HEAD
<div class="col-6 col-sm-4 mx-auto text-center">
<figure>
<img class="rounded-circle mt-3 img-fluid" src="/static/foto%20laurens.png" alt="Laurens" width="200" height="200" />
Expand All @@ -42,4 +49,28 @@ <h1 class="HeadTitle">Over ons</h1>
</figure>
</div>
</div>
=======
<div class="col-6 col-sm-4 mx-auto text-center">
<figure>
<img class="rounded-circle mt-3 img-fluid" src="/static/foto%20laurens.png" alt="Laurens" width="200"
height="200"/>
<figcaption class="pt-3 pb-2">
<span class="fw-bold">Laurens Karakolev</span> <br/>
Ik ben Laurens, 19 jaar oud en ga volgend jaar waarschijnlijk App & AI verderstuderen.
</figcaption>
</figure>
</div>
<div class="col-6 col-sm-4 mx-auto text-center">
<figure>
<img class="rounded-circle mt-3 img-fluid" src="/static/kais.png" alt="kaïs" width="200" height="200"/>
<figcaption class="pt-3 pb-2">
<span class="fw-bold">kaïs Boutaleb</span><br/>
Ik ben kaïs, 21 jaar en fan van alles waar technologie in zit. Ik ben zeer geïnteresseerd in
cybersecurity en AI. maar ook andere zaken buiten IT zoals talen en muziek. Hier ben ik
verantwoordelijk voor de backend van de website
</figcaption>
</figure>
</div>
</div>
>>>>>>> ff4241330bf771777f8c00ae0d86802851513bd8
{% endblock %}
Loading

0 comments on commit 7ef5258

Please sign in to comment.