Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2125af1743 | ||
|
|
60d113fdc6 | ||
|
|
849fb71a36 |
No files matched your search
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,12 @@
|
||||
import sqlite3
|
||||
|
||||
DATABASE
|
||||
|
||||
def getdb():
|
||||
conn = sqlite3.connect(Sqlite3.db)
|
||||
conn.row_factory = sqlite3.Row
|
||||
try:
|
||||
yield conn
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
@@ -0,0 +1,54 @@
|
||||
from database.db_connection import get_db
|
||||
import random.randint
|
||||
|
||||
|
||||
def createID():
|
||||
randomint = random.randint(10000000,99999999)
|
||||
with getdb as conn:
|
||||
row = conn.execute("SELECT * FROM persons WHERE person_id = ?", (randomint))
|
||||
while(row != "")
|
||||
row = conn.execute("SELECT * FROM persons WHERE person_id = ?", (randomint))
|
||||
|
||||
return randomint
|
||||
|
||||
|
||||
|
||||
def add_user(E-mail, password, Fname, Lname, age)
|
||||
with getdb as conn:
|
||||
row = conn.execute("SELECT * FROM contacts WHERE email_address = ?", (E-mail,))
|
||||
if row:
|
||||
print("user with this E-mail already exists")
|
||||
elif:
|
||||
for i in E-mail:
|
||||
if i != "@":
|
||||
return "invalid E-mail"
|
||||
|
||||
else:
|
||||
ID = createID()
|
||||
conn.execute("""
|
||||
INSERT INTO persons
|
||||
person_id,
|
||||
first_name,
|
||||
Lname,
|
||||
age,
|
||||
)
|
||||
VALUES(?, ?, ?, ?)
|
||||
""") (ID, Fname, Lname, age)
|
||||
|
||||
conn.execute("""
|
||||
INSERT INTO contacts(
|
||||
person_id,
|
||||
email_address,
|
||||
)
|
||||
VALUES(?, ?)
|
||||
""") (ID, E-mail)
|
||||
|
||||
conn.execute("""
|
||||
INSERT INTO passwords(
|
||||
person_id,
|
||||
hashed_password,
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,110 @@
|
||||
from flask import render_template, Blueprint
|
||||
import os
|
||||
import random
|
||||
import sqlite3
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
db_path = os.path.join(BASE_DIR, "Sqlite3.db")
|
||||
|
||||
def getdb():
|
||||
conn = sqlite3.connect(Sqlite3.db)
|
||||
conn.row_factory = sqlite3.Row
|
||||
try:
|
||||
yield conn
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
return conn
|
||||
"""
|
||||
def createID():
|
||||
randomint = random.randint(10000000,99999999)
|
||||
a = getdb()
|
||||
with a as conn:
|
||||
row = conn.execute("SELECT * FROM persons WHERE person_id = ?", (randomint))
|
||||
while(row != ""):
|
||||
row = conn.execute("SELECT * FROM persons WHERE person_id = ?", (randomint))
|
||||
|
||||
return randomint
|
||||
"""
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def add_user(Email, password, Fname, Lname, age):
|
||||
conn = sqlite3.connect(db_path)
|
||||
conn.row_factory = sqlite3.Row
|
||||
|
||||
with conn as conn:
|
||||
row = conn.execute("SELECT * FROM person_contacts WHERE email_address = ?", (Email,))
|
||||
if not row:
|
||||
print("user with this Email already exists")
|
||||
elif not "@" in Email:
|
||||
return "invalid Email"
|
||||
|
||||
else:
|
||||
ID = 1
|
||||
conn.execute("""
|
||||
INSERT INTO persons(
|
||||
person_id,
|
||||
first_name,
|
||||
last_name,
|
||||
age
|
||||
)
|
||||
VALUES(?, ?, ?, ?)
|
||||
""", (ID, Fname, Lname, age))
|
||||
|
||||
conn.execute("""
|
||||
INSERT INTO person_contacts(
|
||||
person_id,
|
||||
email_address
|
||||
)
|
||||
VALUES(?, ?)
|
||||
""", (ID, Email))
|
||||
|
||||
|
||||
conn.execute("""
|
||||
INSERT INTO passwords(
|
||||
person_id,
|
||||
password_hash
|
||||
)
|
||||
VALUES(?, ?)
|
||||
""", (ID, password))
|
||||
|
||||
return 0
|
||||
|
||||
page = Blueprint('register', __name__, url_prefix='/register')
|
||||
|
||||
|
||||
@page.route('/')
|
||||
def register():
|
||||
return render_template('register/register.jinja', user=None)
|
||||
|
||||
|
||||
@page.route("/", methods=["POST"])
|
||||
def add_user_to_DB():
|
||||
try:
|
||||
Email = request.form["Email"]
|
||||
Fname = request.form["First_name"].capitalize()
|
||||
Lname = request.form["Last_name"].capitalize()
|
||||
password = request.form["password"]
|
||||
age = request.form["age"]
|
||||
|
||||
result = add_user(Email, password, Fname, Lname, age)
|
||||
|
||||
if result == 0:
|
||||
#succesfull
|
||||
flash("Registration successful! Please log in.", "success")
|
||||
return render_template(
|
||||
"home/home.jinja")
|
||||
else:
|
||||
print("error")
|
||||
|
||||
except Exception as e:
|
||||
print("somthing went wrong")
|
||||
|
||||
# return 0
|
||||
|
||||
#print(createID())
|
||||
#print(add_user("a@", "a", "a", "a", 1))
|
||||
@@ -0,0 +1,59 @@
|
||||
{% extends "base.jinja" %}
|
||||
{% block title %} register {% endblock %}
|
||||
{% block head %}
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
{% from 'button.jinja' import button %}
|
||||
|
||||
#<section id="register" class="form">
|
||||
|
||||
<form action="{{ url_for('register.add_user_to_DB') }}" class="container" method="POST"
|
||||
|
||||
|
||||
<div class>
|
||||
<button type="login" href="/login")>
|
||||
already have an account?
|
||||
</button>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label for="">E-mail:</label>
|
||||
<input type="text" id="Email" name="Email" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="">First_name:</label>
|
||||
<input type="text" id="First_name" name="First_name" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="">Last_name:</label>
|
||||
<input type="text" id="Last_name" name="Last_name" required>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label for="">password:</label>
|
||||
<input type="text" id="password" name="password" required>
|
||||
</div>
|
||||
|
||||
# <div type=Submit class="buttoncontainer"">
|
||||
# <span class="popuptext" id="myPopup"></span>
|
||||
# </div>
|
||||
|
||||
<input type="checkbox" id="terms-conditions" name="agree" checked=false />
|
||||
<t> by ticking you agree to our terms and conditions </t> <a href=/terms&conditions> terms & condtions</a>
|
||||
|
||||
|
||||
|
||||
|
||||
<button type ="submit" class="submit-button">
|
||||
CONFIRM
|
||||
</button>
|
||||
|
||||
<\form>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
{% endblock %}
|
||||
Reference in new issue
Block a user