Skip to content

Commit

Permalink
Merge pull request #20 from Brendan-Lawton/master
Browse files Browse the repository at this point in the history
Voting should be fixed - only cookie will be checked.
  • Loading branch information
Brendan-Lawton authored Jun 21, 2024
2 parents 05c45dc + fb0a07f commit bec3fa1
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 72 deletions.
21 changes: 9 additions & 12 deletions api-server/RunServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def convertTuple(tup):

if votes_exist == None:
print("no votes")
cur.execute("CREATE TABLE votes(oepnv, kiezbloecke, fahrrad, parkraum, fahrenderAutoVerkehr, drt, ipAddr, cookie, sessionID, timeStamp)")
cur.execute("CREATE TABLE votes(oepnv, kiezbloecke, fahrrad, parkraum, fahrenderAutoVerkehr, drt, cookie, sessionID, timeStamp)")

if sessions_exist == None:
cur.execute("CREATE TABLE sessions(sessionActive, sessionID, startTime, EndTime)")
Expand All @@ -87,7 +87,7 @@ def convertTuple(tup):
# cur = con.cursor()
# cur.execute("DROP TABLE votes")
# cur.execute("DROP TABLE sessions")
# cur.execute("CREATE TABLE votes(oepnv, kiezbloecke, fahrrad, parkraum, fahrenderAutoVerkehr, drt, ipAddr, cookie, sessionID, timestamp)")
# cur.execute("CREATE TABLE votes(oepnv, kiezbloecke, fahrrad, parkraum, fahrenderAutoVerkehr, drt, cookie, sessionID, timestamp)")
# cur.execute("CREATE TABLE sessions(sessionActive, sessionID, startTime, EndTime)")

# cur.execute("DROP TABLE votes")
Expand Down Expand Up @@ -174,14 +174,14 @@ def post_vote_to_db():
sessionID = int(convertTuple(cur.fetchone()))
print(sessionID)

check_if_voter_exists = "SELECT * FROM votes WHERE cookie = ? AND ipAddr = ?"
cur.execute(check_if_voter_exists, (1, data['ipAddr']))
check_if_voter_exists = "SELECT * FROM votes WHERE cookie = ?"
cur.execute(check_if_voter_exists, (data['cookie'],))
voter_exists = cur.fetchone()
if (voter_exists != None):
update_vote = """Update votes
SET oepnv = ?, kiezBloecke = ?, fahrrad = ?,
parkraum = ?, fahrenderAutoVerkehr = ?, drt= ?, sessionID = ?, timeStamp = ?
WHERE cookie = ? AND ipAddr = ?"""
WHERE cookie = ?"""
cur.execute(update_vote, (
data['oepnv'],
data['kiezBloecke'],
Expand All @@ -191,8 +191,7 @@ def post_vote_to_db():
data['drt'],
sessionID,
data['timeStamp'],
1,
data['ipAddr']))
data['cookie']))

table_list = [a for a in cur.execute("SELECT * FROM votes ORDER BY ROWID ASC LIMIT 200")]
print(table_list)
Expand All @@ -203,9 +202,8 @@ def post_vote_to_db():
return jsonify({"message": "Vote received successfully"}), 200, {"Access-Control-Allow-Origin": "*"}

else:
db_vote_insert = """INSERT INTO votes (oepnv, kiezBloecke, fahrrad, parkraum, fahrenderAutoVerkehr, drt, ipAddr, cookie, sessionID, timeStamp)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"""
db_vote_insert = """INSERT INTO votes (oepnv, kiezBloecke, fahrrad, parkraum, fahrenderAutoVerkehr, drt, cookie, sessionID, timeStamp)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"""

cur.execute(db_vote_insert, (
data['oepnv'],
Expand All @@ -214,7 +212,6 @@ def post_vote_to_db():
data['parkraum'],
data['fahrenderAutoVerkehr'],
data['drt'],
data['ipAddr'],
data['cookie'],
sessionID,
data['timeStamp']
Expand Down Expand Up @@ -242,7 +239,7 @@ def get_votes_from_db(session_id):
# find_votes = "SELECT * FROM votes WHERE sessionID = ?"
# cur.execute(find_votes, (session_id,))
# results = cur.fetchall()
votes = [{'oepnv': row[0], 'kiezBloecke': row[1], 'fahrrad': row[2], 'parkraum': row[3], 'fahrenderAutoVerkehr': row[4], 'drt': row[5], 'ipAddr': row[6], 'cookie': row[7], 'session_id': row[8], 'timeStamp': row[9]} for row in results]
votes = [{'oepnv': row[0], 'kiezBloecke': row[1], 'fahrrad': row[2], 'parkraum': row[3], 'fahrenderAutoVerkehr': row[4], 'drt': row[5], 'cookie': row[6], 'session_id': row[7], 'timeStamp': row[8]} for row in results]
print(votes)
# print(type(session_id))
# cur.execute("PRAGMA table_info(votes)")
Expand Down
139 changes: 79 additions & 60 deletions sounding-board/src/views/SoundingBoard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
.submit-vote-div
.button.submit-button(@click="saveConditions") ✅ Stimme abgeben
.voted-text(v-if="showVotedText") <span style="color:#77b255">Sie haben abgestimmt.</span> Wenn Sie nochmal abstimmen möchten, wird Ihre erste Stimme ersetzt.
.buttons
.button.reveal-button(@click="showResults") Ergebnisse anzeigen
.button.hide-button(@click="hideResults") Ergebnisse ausblenden
.error-text(v-if="!voted && resultsRequested") Sie müssen erstmal abstimmen
.vote-disclaimer *Wenn die Seite aktualisiert wird, bevor Sie Ihre Stimme abgeben, wählen Sie bitte Ihre Bedingungen erneut aus (auch wenn sie bereits gewählt sind)
//- .button.reveal-button(@click="showResults") Ergebnisse anzeigen
//- .button.hide-button(@click="hideResults") Ergebnisse ausblenden
//- .error-text(v-if="!voted && resultsRequested") Sie müssen erstmal abstimmen
Expand Down Expand Up @@ -204,6 +204,8 @@ export default class VueComponent extends Vue {
private serverURL = "https://vsp-lndw-sounding-board.fly.dev/"
// private serverURL = "http://127.0.0.1:5000/"
private badPage = false
private lang = 'en'
private mdParser = new MarkdownIt()
Expand Down Expand Up @@ -234,8 +236,7 @@ export default class VueComponent extends Vue {
parkraum: 'base',
fahrenderAutoVerkehr: 'base',
drt: 'base',
ipAddr: '',
cookie: false,
cookie: '',
timeStamp: null,
}
Expand Down Expand Up @@ -675,52 +676,52 @@ export default class VueComponent extends Vue {
return ''
}
private showResults() {
this.resultsRequested = true
if (localStorage.getItem('LSvoted') == 'true' && this.resultsRequested == true) {
this.voted = true;
let results = Array.from(
document.getElementsByClassName('results') as HTMLCollectionOf<HTMLElement>
)
results[0].style.display = 'flex'
if (window.innerWidth < 621) {
window.scrollTo({
top: 2300,
behavior: 'smooth',
})
} else if (window.innerWidth < 1200 && window.innerWidth > 620) {
window.scrollTo({
top: 1300,
behavior: 'smooth',
})
} else {
window.scrollTo({
top: 1000,
behavior: 'smooth',
})
}
}
}
// private showResults() {
// this.resultsRequested = true
// if (localStorage.getItem('LSvoted') == 'true' && this.resultsRequested == true) {
// this.voted = true;
// let results = Array.from(
// document.getElementsByClassName('results') as HTMLCollectionOf<HTMLElement>
// )
// results[0].style.display = 'flex'
// if (window.innerWidth < 621) {
// window.scrollTo({
// top: 2300,
// behavior: 'smooth',
// })
// } else if (window.innerWidth < 1200 && window.innerWidth > 620) {
// window.scrollTo({
// top: 1300,
// behavior: 'smooth',
// })
// } else {
// window.scrollTo({
// top: 1000,
// behavior: 'smooth',
// })
// }
// }
// }
private hideResults() {
let results = Array.from(
document.getElementsByClassName('results') as HTMLCollectionOf<HTMLElement>
)
results[0].style.display = 'none'
this.setPreset('base')
if (window.innerWidth < 621) {
window.scrollTo({
top: 1800,
behavior: 'smooth',
})
} else{
window.scrollTo({
top: 600,
behavior: 'smooth',
})
}
// private hideResults() {
// let results = Array.from(
// document.getElementsByClassName('results') as HTMLCollectionOf<HTMLElement>
// )
// results[0].style.display = 'none'
// this.setPreset('base')
// if (window.innerWidth < 621) {
// window.scrollTo({
// top: 1800,
// behavior: 'smooth',
// })
// } else{
// window.scrollTo({
// top: 600,
// behavior: 'smooth',
// })
// }
}
// }
private updateVoteConditions(factor: string, option: any) {
if (factor == 'OePNV') this.voteConditions.oepnv = option
Expand All @@ -743,14 +744,14 @@ export default class VueComponent extends Vue {
}
this.voteConditions.cookie = this.setCookie('hasVoted', true, 365)
fetch('https://api.ipify.org?format=json')
.then(x => x.json())
.then(({ ip }) => {
this.voteConditions.ipAddr = ip
})
.then(() => {
const vote = JSON.stringify(this.voteConditions)
})
// fetch('https://api.ipify.org?format=json')
// .then(x => x.json())
// .then(({ ip }) => {
// this.voteConditions.ipAddr = ip
// })
// .then(() => {
// const vote = JSON.stringify(this.voteConditions)
// })
this.voteConditions.timeStamp = new Date().toLocaleString('de-DE');
Expand Down Expand Up @@ -791,7 +792,7 @@ export default class VueComponent extends Vue {
expires = '; expires=' + date.toUTCString()
}
document.cookie = name + '=' + (value || '') + expires + '; path=/'
return value
return document.cookie
}
private addDescriptionToggle() {
Expand Down Expand Up @@ -1030,7 +1031,7 @@ li.notes-item {
.results {
padding: 1rem 2rem 1rem 2rem;
display: none;
display: flex;
width: 100%;
}
Expand Down Expand Up @@ -1196,6 +1197,24 @@ li.notes-item {
white-space: normal;
}
.vote-disclaimer
{
font-weight: bold;
text-wrap: wrap;
max-width: 280px;
font-size: 11px;
line-height: 1.3;
margin-top: 10px;
margin-left: 10px;
word-wrap: break-word;
overflow-wrap: break-word;
word-break: break-word;
-webkit-hyphens: auto;
-ms-hyphens: auto;
hyphens: auto;
white-space: normal;
}
.submit-vote-div {
display: flex;
}
Expand Down

0 comments on commit bec3fa1

Please sign in to comment.