Skip to content

Commit

Permalink
blocking double emails
Browse files Browse the repository at this point in the history
  • Loading branch information
vieiraeduardos committed May 21, 2018
1 parent 00b4167 commit d1fca0d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
38 changes: 24 additions & 14 deletions classroom/controllers/UserController.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,19 @@ def signup():
email = request.form.get("email")
password = generate_password_hash(request.form.get("password"))

db.users.insert_one(
{
"name": name,
"email": email,
"password": password
})
user = db.users.find_one({"email": email})

return redirect("/classroom/")
if user:
return render_template("signup/signup.html", error="E-mail já está sendo usado por outro usuário!")
else:
db.users.insert_one(
{
"name": name,
"email": email,
"password": password
})

return redirect("/classroom/")

#Cadastrando um novo usuário
@app.route("/quiz/signup/", methods=["POST"])
Expand All @@ -143,14 +148,19 @@ def signup_quiz():
email = request.form.get("email")
password = generate_password_hash(request.form.get("password"))

db.users.insert_one(
{
"name": name,
"email": email,
"password": password
})
user = db.users.find_one({"email": email})

return redirect("/classroom/quiz/")
if user:
return render_template("quiz/signup/signup.html", error="E-mail já está sendo usado por outro usuário!")
else:
db.users.insert_one(
{
"name": name,
"email": email,
"password": password
})

return redirect("/classroom/quiz/")



Expand Down
6 changes: 6 additions & 0 deletions classroom/templates/quiz/signup/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ <h5>Cadastro</h5>
<input type="email" name="email">
</div>

{% if error %}
<div class="row">
<span style="color: red; font-weight: bold;">{{error}}</span>
</div>
{% endif %}

<div class="row">
<label>Senha</label>
<input id="newPassword" type="password" name="password" required>
Expand Down
6 changes: 6 additions & 0 deletions classroom/templates/signup/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ <h5>Cadastro</h5>
<input type="email" name="email" required>
</div>

{% if error %}
<div class="row">
<span style="color: red; font-weight: bold;">{{error}}</span>
</div>
{% endif %}

<div class="row">
<label>Senha</label>
<input id="newPassword" type="password" name="password" required>
Expand Down

0 comments on commit d1fca0d

Please sign in to comment.