def register(): """ Register a new user for the SO platform. Allowed GET and POST methods. :return: rendering of the corresponding html page """ # enter in the page by the GET method, only render the register.html page if request.method == 'GET': return render_template('register.html') # enter in the page by a POST method (filled the register page) else: username = request.form['username'] password = request.form['password'] password_confirmed = request.form['password_confirmed'] if password != password_confirmed: logger.debug("Confirmed password is not the same!") flash('Confirmed password is not the same!', 'danger') return render_template("register.html") # hashing the password with md5 user = user_db.get_specific_user({"username": username}) # check if the entered 'user' is already in the db if user: log_queue.put(["DEBUG", "Username already in database".format(username)]) flash('Username already registered', 'danger') return render_template("register.html") else: hash_object = hashlib.md5(password.encode()) # insert the new user (and hashed password) in the db user_db.insert_user({"username": username, "password": hash_object.hexdigest(), "role": "Admin"}) log_queue.put(["INFO", 'User "{}" successfully registered'.format(username)]) flash('User "{}" successfully registered'.format(username), 'success') return render_template("login.html")
def main(): # empty database empty_user_collection() # insert the the admin user (password 'admin' and role 'Admin') default_user = '******' default_password = '******' default_role = 'Admin' user_record = { "username": default_user, "password": hashlib.md5(default_password.encode()).hexdigest(), "role": default_role } insert_user(user_record) log_process.terminate()