64 lines
3.1 KiB
Python
64 lines
3.1 KiB
Python
from flask import Blueprint, Flask, request, flash, render_template, url_for, session, redirect, abort, make_response, send_file, escape
|
|
from flask_bcrypt import Bcrypt
|
|
import sqlite3
|
|
import glob, os, sys, time
|
|
|
|
|
|
app = Flask( 'pywallter' )
|
|
bcrypt = Bcrypt(app)
|
|
|
|
DOSSIER_PERSO='users/'
|
|
|
|
inscription = Blueprint('inscription', __name__, template_folder='templates')
|
|
|
|
@inscription.route( '/inscription/', methods=['GET','POST'] )
|
|
def signin() :
|
|
if 'username' in session :
|
|
return redirect(url_for('filesupload'))
|
|
else :
|
|
if request.method == 'POST' :
|
|
conn = sqlite3.connect('base.db') # Connexion à la base de donnée
|
|
cursor = conn.cursor() # Création de l'objet "curseur"
|
|
user = request.form['user']
|
|
mail = request.form['mail']
|
|
passwd = bcrypt.generate_password_hash(request.form['passwd'])
|
|
passwdconfirm = request.form['passwdconfirm']
|
|
cursor.execute("""SELECT name FROM users WHERE name=?""", (user,))
|
|
testuser=cursor.fetchone()
|
|
cursor.execute("""SELECT mail FROM users WHERE mail=?""", (mail,))
|
|
testmail=cursor.fetchone()
|
|
conn.close()
|
|
if testuser or testmail:
|
|
flash(u'Non d\'utilisateur ou email déjà utilisé, merci d\'en choisir un autre', 'error')
|
|
return render_template('inscription.html')
|
|
else:
|
|
confirmation = bcrypt.check_password_hash(passwd, passwdconfirm)
|
|
if confirmation is True:
|
|
conn = sqlite3.connect('base.db') # Connexion à la base de donnée
|
|
cursor = conn.cursor() # Création de l'objet "curseur"
|
|
cursor.execute("""INSERT INTO users(name, mail, passwd) VALUES(?, ?, ?)""", (user, mail, passwd)) # Insérer des valeurs
|
|
conn.commit() # Sauvegarder valeurs dans la bdd
|
|
cursor.execute("""SELECT name, mail, passwd FROM users""")
|
|
users = cursor.fetchall()
|
|
for i in users:
|
|
i = print('{0} - {1} - {2}'.format(i[0], i[1], i[2]))
|
|
conn.close()
|
|
userracine = DOSSIER_PERSO + user
|
|
userfiles = userracine + '/files'
|
|
userimages = userracine + '/images'
|
|
userthumbnails = userracine + '/images/thumbnails'
|
|
userprofile = userracine + '/profile'
|
|
if not os.path.exists(userracine):
|
|
os.makedirs(userracine)
|
|
os.makedirs(userfiles)
|
|
os.makedirs(userimages)
|
|
os.makedirs(userthumbnails)
|
|
os.makedirs(userprofile)
|
|
flash(u'Inscription réalisée avec succés !', 'succes')
|
|
return render_template('login.html')
|
|
else:
|
|
flash(u'Les mots de passe ne sont pas identiques !', 'error')
|
|
return render_template('inscription.html')
|
|
else :
|
|
return render_template('inscription.html')
|