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
6 changes: 5 additions & 1 deletion pokedex/app.py
Original file line number Diff line number Diff line change
@@ -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}
Expand Down
6 changes: 3 additions & 3 deletions pokedex/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!")

Expand All @@ -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
1 change: 1 addition & 0 deletions pokedex/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<div class="container p-4">
<section class="">
<form action="{{ url_for('subscribe') }}" method="post">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
<div class="row d-flex justify-content-center">
<div class="col-auto">
<p class="pt-2">
Expand All @@ -24,7 +25,7 @@
</div>
<div class="col-md-5 col-12">
<div class="form-outline form-white mb-4">
<input type="email" class="form-control" id="input_email" name = "email" aria-describedby="emailHelp">

Check warning on line 28 in pokedex/templates/index.html

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Associate a valid label to this input field.

See more on https://sonarcloud.io/project/issues?id=AutoCodeRoverSG_python-flask-demo&issues=AaFtHX3HdA8JAur1Rylb&open=AaFtHX3HdA8JAur1Rylb&pullRequest=4
<div id="emailHelp" class="form-text">We'll never share your email with anyone else.</div>
</div>
</div>
Expand Down