Ajout fonction première connexion et correction base de donnée
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
from flask import Flask
|
||||
import sqlite3
|
||||
import os
|
||||
from tools.utils import gen_token
|
||||
from flask_bcrypt import Bcrypt
|
||||
|
||||
app = Flask( 'pywallter' )
|
||||
app.config.from_pyfile('config.py')
|
||||
|
||||
bcrypt = Bcrypt(app)
|
||||
|
||||
DATABASE = app.config['DATABASE']
|
||||
DOSSIER_PERSO = app.config['DOSSIER_APP']
|
||||
@@ -17,8 +19,8 @@ def init_db():
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS users(
|
||||
Mail CHAR(80) PRIMARY KEY UNIQUE NOT NULL,
|
||||
name TEXT,
|
||||
Mail TEXT UNIQUE,
|
||||
name TEXT primary KEY UNIQUE NOT NULL,
|
||||
alias TEXT,
|
||||
xmpp TEXT,
|
||||
passwd TEXT,
|
||||
@@ -46,6 +48,16 @@ def init_db():
|
||||
)
|
||||
""")
|
||||
conn.commit()
|
||||
cursor.execute("""select * from users""")
|
||||
accounts = cursor.fetchall()
|
||||
# Si aucun account n'est crée on créé l'utilisateur
|
||||
# pywallter qui permet la première inscription
|
||||
if not(accounts) :
|
||||
user = "pywallter"
|
||||
token = gen_token()
|
||||
passwd_bcrypt = bcrypt.generate_password_hash(token)
|
||||
cursor.execute("""INSERT INTO users(name, passwd, token) VALUES(?, ?, ?)""", (user, passwd_bcrypt, token))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
print ('table posts OK')
|
||||
|
||||
|
||||
@@ -26,26 +26,33 @@ def append_to_log(log_line, user):
|
||||
|
||||
def email_disp(email):
|
||||
disp = True
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||
unique_at = len(email.split('@'))
|
||||
print (unique_at)
|
||||
if len(email) < 80 and unique_at == 2:
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||
|
||||
|
||||
cursor.execute("""SELECT mail FROM users WHERE mail=?""", (email,))
|
||||
testmail = cursor.fetchall()
|
||||
if testmail:
|
||||
print ("on passe ici")
|
||||
cursor.execute("""SELECT mail FROM users WHERE mail=?""", (email,))
|
||||
testmail = cursor.fetchall()
|
||||
if testmail :
|
||||
disp = False
|
||||
|
||||
if disp:
|
||||
cursor.execute("""SELECT alias FROM users""")
|
||||
aliases = cursor.fetchall()
|
||||
for alist in aliases:
|
||||
for alias in alist:
|
||||
if alias:
|
||||
if email in alias:
|
||||
disp=False
|
||||
|
||||
else:
|
||||
disp = False
|
||||
|
||||
if disp:
|
||||
cursor.execute("""SELECT alias FROM users""")
|
||||
aliases = cursor.fetchall()
|
||||
for alist in aliases:
|
||||
for alias in alist:
|
||||
if alias:
|
||||
if email in alias:
|
||||
disp=False
|
||||
return disp
|
||||
|
||||
|
||||
def valid_token_register(token):
|
||||
valid = True
|
||||
print(token)
|
||||
|
||||
Reference in New Issue
Block a user