Exemplo n.º 1
0
def handle_register():
    reg_email = clean_text(request.form["reg-email"])
    reg_username = clean_text(request.form["reg-username"])
    reg_password = clean_text(request.form["reg-password"])
    reg_password_confirm = clean_text(request.form["reg-password-confirm"])

    # If the e-mail format was incorrect.
    if not check_email(reg_email):
        return render_template("register_failed.html",
                               message="Please enter a valid E-Mail address.")

    # If the username format was incorrect.
    if not check_text(reg_username):
        return render_template("register_failed.html",
                               message="Please enter a valid username.")

    # If the passwords did not match
    if not reg_password == reg_password_confirm:
        return render_template(
            "register_failed.html",
            message="The passwords did not match. Please try again.")

    # If the password format (i.e. strength) was incorrect.
    if not check_password(reg_password) or not check_password(
            reg_password_confirm):
        return render_template(
            "register_failed.html",
            message=
            "Please enter a valid password. You password must at least contain of 6 characters."
        )

    db_handler = DB_Handler()

    user_data = {}
    user_data["username"] = reg_username
    user_data["email"] = reg_email
    user_data["password"] = generate_password_hash(reg_password)

    user_added, e = db_handler.add_new_user(mysql, user_data)

    # Catch internal error
    if user_added is False:
        logger.error("Error at registering new user " + str(reg_email) +
                     " with exception:\n" + str(e))
        return render_template(
            "register_failed.html",
            message=
            "The new user could not be added due to a internal error. Please try again. If the problem continues to exists, please get in touch with a support member."
        )

    # If the user is already registered
    if user_added is None:
        return render_template(
            "register_failed.html",
            message="The user already exists. You can login <a href=\"" +
            url_for("login") + "\">here</a>.")

    logger.success("New registration: " + str(reg_email))
    return render_template(
        "register_success.html",
        message=
        "Your registration has been successful. You can login <b><a href=\"" +
        url_for("login") + "\">here</a></b>.")
Exemplo n.º 2
0
def register_new_account(mysql, email, pw_hash, verification_token):
    db_handler = DB_Handler()
    success = db_handler.add_new_user(mysql, email, pw_hash,
                                      verification_token)

    return success