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
14 changes: 12 additions & 2 deletions app/routes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask import render_template, flash, redirect, request, url_for
from urllib.parse import urlparse
from werkzeug.urls import url_parse
from app import app
from app.forms import *
Expand All @@ -24,7 +25,11 @@ def login():
return redirect(url_for('login'))
login_user(user, remember=form.remember_me.data)
next_page=request.args.get('next')
if not next_page or url_parse(next_page).netloc!='':
if next_page:
parsed = urlparse(next_page)
if parsed.netloc or parsed.scheme or not next_page.startswith('/'):
next_page = None
if not next_page:
next_page=url_for('index')
return redirect(next_page)
return render_template('login.html', title='Sign In', form=form)
Expand Down Expand Up @@ -230,7 +235,12 @@ def cancelbooking():

form=CancelbookingForm()
if form.validate_on_submit():
meeting=Meeting.query.filter_by(id=form.ids.data).first()
meeting=Meeting.query.filter_by(
id=form.ids.data, bookerId=current_user.id
).first()
if meeting is None:
flash('Meeting not found or you are not authorized to cancel it')
return redirect(url_for('cancelbooking'))

if meeting.date<=datetime.now():
flash(f'Past booking cannot be canceled')
Expand Down
7 changes: 6 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import os
basedir = os.path.abspath(os.path.dirname(__file__))
class Config(object):
SECRET_KEY = os.environ.get('SECRET_KEY') or 'you-will-never-guess'
SECRET_KEY = os.environ.get('SECRET_KEY')
if not SECRET_KEY:
raise RuntimeError(
"SECRET_KEY environment variable must be set. "
"Generate one with: python -c 'import secrets; print(secrets.token_hex(32))'"
)
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
'sqlite:///' + os.path.join(basedir, 'lab2.db')
SQLALCHEMY_TRACK_MODIFICATIONS = False