diff --git a/pokedex/app.py b/pokedex/app.py index bddc552..ff85b06 100644 --- a/pokedex/app.py +++ b/pokedex/app.py @@ -1,12 +1,16 @@ import os from flask import Flask, render_template, redirect, url_for, request, g +from flask_wtf.csrf import CSRFProtect from pokedex import helper app = Flask(__name__) app.config["DATABASE"] = "../database.db" +app.config["SECRET_KEY"] = os.environ.get("SECRET_KEY") or os.urandom(32) +csrf = CSRFProtect() +csrf.init_app(app) -@app.route("/") +@app.route("/", methods=["GET"]) def index(): pokemon = [ {"id": id, "pokemon_name": pokemon_name, "image_url": image_url} diff --git a/pokedex/helper.py b/pokedex/helper.py index 4db91b3..191487d 100644 --- a/pokedex/helper.py +++ b/pokedex/helper.py @@ -17,7 +17,7 @@ def register_subscriber(self, email): self.__conn.execute("INSERT into SUBSCRIBERS(email) values (?)", (email,)) self.__conn.commit() except sqlite3.DatabaseError: - raise Exception("Problem with the database!") + raise RuntimeError("Problem with the database!") except sqlite3.IntegrityError: raise ValueError("Email already exists!") @@ -31,8 +31,8 @@ def fetch_all_pokemons(wrapper: ConnectionWrapper): def register_subscriber(wrapper: ConnectionWrapper, email): - pattern = re.compile(r"(.*)@(.*\..*)") + pattern = re.compile(r"([^@]*)@([^.]*\..*)") if not pattern.match(email): - ValueError("Invalid email!") + raise ValueError("Invalid email!") wrapper.register_subscriber(email) pass diff --git a/pokedex/templates/index.html b/pokedex/templates/index.html index 4d0f219..01dc448 100644 --- a/pokedex/templates/index.html +++ b/pokedex/templates/index.html @@ -16,6 +16,7 @@

Pokedex

+