First look
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
.gitignore
|
||||
/.idea/
|
||||
testing.py
|
||||
/databases/
|
||||
15
main.py
15
main.py
@@ -1,5 +1,14 @@
|
||||
import sqlite3
|
||||
db_type = "sqlite"
|
||||
import sqlLite
|
||||
sqlLite.set_db_name("databases/test.db")
|
||||
|
||||
DB_CON = sqlite3.connect("database.db")
|
||||
DB_CUR = DB_CON.cursor()
|
||||
if db_type == "sqlite":
|
||||
import sqlLite.get as getter
|
||||
import sqlLite.create as create
|
||||
import sqlLite.set as setter
|
||||
import testing as testing
|
||||
create.create_table_t_user()
|
||||
setter.set_login("test@test.test", "password")
|
||||
getter.get_user()
|
||||
#testing.sqllite_reset(sqlitename)
|
||||
|
||||
|
||||
5
sqlLite/__init__.py
Normal file
5
sqlLite/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
db_name = "databases/test.db"
|
||||
|
||||
def set_db_name(name):
|
||||
global db_name
|
||||
db_name = name
|
||||
15
sqlLite/create.py
Normal file
15
sqlLite/create.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import sqlite3
|
||||
from . import db_name
|
||||
|
||||
## Create Tables
|
||||
def create_table_t_user():
|
||||
db_con = sqlite3.connect(db_name)
|
||||
db_cur = db_con.cursor()
|
||||
db_cur.execute("""
|
||||
CREATE TABLE IF NOT EXISTS T_USERS (
|
||||
ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
USERNAME TEXT NOT NULL UNIQUE,
|
||||
EMAIL TEXT NOT NULL UNIQUE,
|
||||
PASSWORD TEXT NOT NULL
|
||||
);""")
|
||||
db_con.commit()
|
||||
10
sqlLite/get.py
Normal file
10
sqlLite/get.py
Normal file
@@ -0,0 +1,10 @@
|
||||
import sqlite3
|
||||
from . import db_name
|
||||
|
||||
def get_user():
|
||||
conn = sqlite3.connect(db_name)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('select * from T_USERS')
|
||||
rows = cursor.fetchall()
|
||||
for row in rows:
|
||||
print(row)
|
||||
19
sqlLite/set.py
Normal file
19
sqlLite/set.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from hashlib import sha512
|
||||
import sqlite3
|
||||
import useful.check as check
|
||||
from . import db_name
|
||||
|
||||
def set_password_hash(password):
|
||||
return sha512(password.encode('utf-8')).hexdigest()
|
||||
|
||||
def set_login(email, password):
|
||||
db_con = sqlite3.connect(db_name)
|
||||
db_cur = db_con.cursor()
|
||||
try:
|
||||
if check.check_email(email):
|
||||
db_cur.execute("INSERT INTO T_USERS (USERNAME, EMAIL, PASSWORD) VALUES (?,?,?)", ('test',email, set_password_hash(password)))
|
||||
db_con.commit()
|
||||
else:
|
||||
print("Email entered is not valid")
|
||||
except sqlite3.IntegrityError:
|
||||
print("Username or Email entered is not unique")
|
||||
10
useful/check.py
Normal file
10
useful/check.py
Normal file
@@ -0,0 +1,10 @@
|
||||
import re
|
||||
|
||||
def check_email(email):
|
||||
# Click on Edit and place your email ID to validate
|
||||
#email = "my.ownsite@our-earth.de"
|
||||
valid = re.match(r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$', email)
|
||||
if valid:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
0
useful/hash.py
Normal file
0
useful/hash.py
Normal file
Reference in New Issue
Block a user