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')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user