Ajout fonction première connexion et correction base de donnée
This commit is contained in:
@@ -29,39 +29,58 @@ inscription = Blueprint('inscription', __name__, template_folder='templates')
|
||||
@inscription.route( '/inscription/<token>', methods=['GET','POST'] )
|
||||
def signin(token) :
|
||||
hostname = gethostname()
|
||||
url_inscription = BASE_URL+'inscription/'+token
|
||||
resp = None
|
||||
if app.config['SIGNIN_ENABLE'] and valid_token_register(token):
|
||||
if 'username' in session :
|
||||
resp = redirect(url_for('profil.profile', _external=True))
|
||||
else :
|
||||
if request.method == 'POST':
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||
if not(request.form['user']) or not(request.form['passwd']) or not(request.form['mail']):
|
||||
flash(u'Il faut remplir le formulaire en entier, les champs ne peuvent pas etre vide ', 'error')
|
||||
return render_template('inscription.html',
|
||||
signin_enable=app.config['SIGNIN_ENABLE'],
|
||||
token=token, hostname=hostname,
|
||||
url_inscription=url_inscription,
|
||||
MAIL_SERVER=MAIL_SERVER)
|
||||
|
||||
user = request.form['user']
|
||||
mail = request.form['mail']+'@'+hostname
|
||||
passwd = request.form['passwd']
|
||||
|
||||
mail = ""
|
||||
passwdconfirm = request.form['passwdconfirm']
|
||||
bcrypt_passwd = bcrypt.generate_password_hash(request.form['passwd'])
|
||||
mail_passwd_change = 0
|
||||
|
||||
conn = sqlite3.connect(DATABASE) # Connexion à la base de donnée
|
||||
cursor = conn.cursor() # Création de l'objet "curseur"
|
||||
|
||||
cursor.execute("""SELECT name FROM users WHERE name=?""", (user,))
|
||||
testuser = cursor.fetchone()
|
||||
conn.close()
|
||||
|
||||
|
||||
if MAIL_SERVER:
|
||||
cmd = SETUID + " set_mail_passwd " + "'"+mail+"' " + "'"+passwd+"'"
|
||||
mail_passwd_change = os.system(cmd)
|
||||
mail = request.form['mail']+'@'+hostname
|
||||
if not(email_disp(mail)) :
|
||||
flash(u'Adresse email déjà utilisé ou invalide, merci d\'en choisir une autre', 'error')
|
||||
resp = render_template('inscription.html',
|
||||
signin_enable=app.config['SIGNIN_ENABLE'],
|
||||
token=token, hostname=hostname,
|
||||
url_inscription=url_inscription,
|
||||
MAIL_SERVER=MAIL_SERVER)
|
||||
else:
|
||||
cmd = SETUID + " set_mail_passwd " + "'"+mail+"' " + "'"+passwd+"'"
|
||||
mail_passwd_change = os.system(cmd)
|
||||
|
||||
|
||||
if testuser:
|
||||
if testuser or mail_passwd_change != 0 or resp:
|
||||
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)
|
||||
token=token, hostname=hostname,
|
||||
url_inscription=url_inscription,
|
||||
MAIL_SERVER=MAIL_SERVER)
|
||||
|
||||
elif not(email_disp(mail)) or mail_passwd_change != 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(bcrypt_passwd, passwdconfirm)
|
||||
if confirmation is True:
|
||||
@@ -83,7 +102,7 @@ def signin(token) :
|
||||
users = cursor.fetchall()
|
||||
for i in users:
|
||||
i = print('{0} - {1} - {2}'.format(i[0], i[1], i[2]))
|
||||
|
||||
|
||||
userracine = DOSSIER_PERSO + user
|
||||
userfiles = userracine + '/files'
|
||||
userimages = userracine + '/images'
|
||||
@@ -114,12 +133,16 @@ def signin(token) :
|
||||
flash(u'Les mots de passe ne sont pas identiques !', 'error')
|
||||
resp = render_template('inscription.html',
|
||||
signin_enable=app.config['SIGNIN_ENABLE'],
|
||||
hostname=hostname)
|
||||
token=token, hostname=hostname,
|
||||
url_inscription=url_inscription,
|
||||
MAIL_SERVER=MAIL_SERVER)
|
||||
else :
|
||||
url_inscription = BASE_URL+'inscription/'+token
|
||||
|
||||
resp = render_template('inscription.html',
|
||||
signin_enable=app.config['SIGNIN_ENABLE'],
|
||||
token=token, hostname=hostname, url_inscription=url_inscription)
|
||||
token=token, hostname=hostname,
|
||||
url_inscription=url_inscription,
|
||||
MAIL_SERVER=MAIL_SERVER)
|
||||
else:
|
||||
resp = redirect(BASE_URL, code=401)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user