2020-11-29 02:05:19 +01:00
|
|
|
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
|
2022-08-06 18:22:24 +02:00
|
|
|
from tools.utils import email_disp, valid_token_register
|
|
|
|
from socket import gethostname
|
2020-11-29 02:05:19 +01:00
|
|
|
|
|
|
|
app = Flask( 'pywallter' )
|
2022-07-11 00:36:31 +02:00
|
|
|
app.config.from_pyfile('config.py')
|
2020-11-29 02:05:19 +01:00
|
|
|
bcrypt = Bcrypt(app)
|
|
|
|
|
2022-08-06 18:22:24 +02:00
|
|
|
#### Variables ##################################################################################
|
2022-07-11 00:36:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
DOSSIER_PERSO= app.config['DOSSIER_APP']
|
|
|
|
extensionimg = app.config['EXT_IMG']
|
2022-08-06 18:22:24 +02:00
|
|
|
DATABASE = app.config['DATABASE']
|
|
|
|
MAIL_SERVER = app.config['MAIL_SERVER']
|
|
|
|
XMMP_SERVER = app.config['XMPP_SERVER']
|
|
|
|
SETUID = app.config['SETUID']
|
2022-08-06 23:49:16 +02:00
|
|
|
BASE_URL = app.config['BASE_URL']
|
|
|
|
|
2022-08-06 18:22:24 +02:00
|
|
|
#################################################################################################
|
2022-07-11 00:36:31 +02:00
|
|
|
|
|
|
|
|
2020-11-29 02:05:19 +01:00
|
|
|
|
|
|
|
inscription = Blueprint('inscription', __name__, template_folder='templates')
|
|
|
|
|
2022-08-06 18:22:24 +02:00
|
|
|
@inscription.route( '/inscription/<token>', methods=['GET','POST'] )
|
|
|
|
def signin(token) :
|
|
|
|
hostname = gethostname()
|
|
|
|
if app.config['SIGNIN_ENABLE'] and valid_token_register(token):
|
|
|
|
if 'username' in session :
|
|
|
|
resp = redirect(url_for('profil.profile', _external=True))
|
2020-11-29 02:05:19 +01:00
|
|
|
else :
|
2022-08-06 18:22:24 +02:00
|
|
|
if request.method == 'POST':
|
|
|
|
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
|
|
|
cursor = conn.cursor() # Création de l'objet "curseur"
|
|
|
|
user = request.form['user']
|
|
|
|
mail = request.form['mail']+'@'+hostname
|
|
|
|
passwd = bcrypt.generate_password_hash(request.form['passwd'])
|
|
|
|
passwdconfirm = request.form['passwdconfirm']
|
|
|
|
cursor.execute("""SELECT name FROM users WHERE name=?""", (user,))
|
|
|
|
testuser = cursor.fetchone()
|
|
|
|
conn.close()
|
|
|
|
|
|
|
|
if MAIL_SERVER:
|
|
|
|
p = run( [ SETUID, 'set_mail_passwd', "'"+mailbox['Mail']+"'", "'"+passwd+"'" ] )
|
|
|
|
|
|
|
|
|
|
|
|
if testuser:
|
|
|
|
flash(u'Non d\'utilisateur déjà utilisé, merci d\'en choisir un autre', 'error')
|
|
|
|
resp = render_template('inscription.html',
|
|
|
|
signin_enable=app.config['SIGNIN_ENABLE'],
|
|
|
|
hostname=hostname)
|
|
|
|
|
|
|
|
elif not(email_disp(mail)) or p.returncode != 0 :
|
|
|
|
flash(u'Adresse email déjà utilisé, merci d\'en choisir un autre', 'error')
|
|
|
|
resp = render_template('inscription.html',
|
|
|
|
signin_enable=app.config['SIGNIN_ENABLE'],
|
|
|
|
hostname=hostname)
|
|
|
|
else:
|
|
|
|
confirmation = bcrypt.check_password_hash(passwd, passwdconfirm)
|
|
|
|
if confirmation is True:
|
|
|
|
conn = sqlite3.connect(DATABASE) # 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
|
|
|
|
|
|
|
|
|
|
|
|
if XMMP_SERVER:
|
|
|
|
tmp = mailbox['mail'].split('@')
|
|
|
|
p = run( [ SETUID, 'prosodyctl register ', "'"+tmp[0]+"'",
|
|
|
|
"'"+tmp[1]+"'", "'"+passwd+"'" ])
|
|
|
|
if p.returncode != 0:
|
|
|
|
flash(u'Il y a eu un problème lors de la création du compte XMPP !', 'error')
|
|
|
|
|
|
|
|
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)
|
|
|
|
fp = open('log.txt', 'x')
|
|
|
|
fp.close()
|
|
|
|
|
|
|
|
|
|
|
|
# Une fois que tout c'est bien passé pour l'inscription on détruit le jeton.
|
|
|
|
cursor.execute("""SELECT name, invitations FROM users where Token=?""", (token,))
|
|
|
|
tmp = cursor.fetchone()
|
|
|
|
username =tmp[0]
|
|
|
|
invitations_count=tmp[1] - 1
|
|
|
|
cursor.execute("""UPDATE users set invitations=?, Token='' where name=?""", (invitations_count, username,))
|
|
|
|
conn.commit()
|
|
|
|
|
|
|
|
flash(u'Inscription réalisée avec succés !', 'succes')
|
2022-08-06 23:49:16 +02:00
|
|
|
resp = redirect(url_for('loginlogout.login'))
|
2022-08-06 18:22:24 +02:00
|
|
|
else:
|
|
|
|
flash(u'Les mots de passe ne sont pas identiques !', 'error')
|
|
|
|
resp = render_template('inscription.html',
|
|
|
|
signin_enable=app.config['SIGNIN_ENABLE'],
|
|
|
|
hostname=hostname)
|
|
|
|
else :
|
2022-08-06 23:49:16 +02:00
|
|
|
url_inscription = BASE_URL+'invitation/'+token
|
2022-08-06 18:22:24 +02:00
|
|
|
resp = render_template('inscription.html',
|
|
|
|
signin_enable=app.config['SIGNIN_ENABLE'],
|
2022-08-06 23:49:16 +02:00
|
|
|
token=token, hostname=hostname, url_inscription=url_inscription)
|
2022-08-06 18:22:24 +02:00
|
|
|
else:
|
2022-08-06 23:49:16 +02:00
|
|
|
resp = redirect(BASE_URL, code=401)
|
2022-08-06 18:22:24 +02:00
|
|
|
|
|
|
|
return resp
|