예제 #1
0
def sign_up():
    db_session.global_init(app.config["SQLALCHEMY_DATABASE_URI"])
    session = db_session.create_session()

    form = SignUpForm()
    params = base_params("Sign up", -1)
    params["form"] = form
    if form.validate_on_submit():
        if form.password.data != form.password_repeat.data:
            params["password_error_message"] = "Password mismatch"
            return render_template('sign_up.html', **params)
        if session.query(User).filter(User.login == form.login.data).first():
            params["login_error_message"] = "This username already exists"
            return render_template('sign_up.html', **params)
        if session.query(User).filter(User.email == form.email.data).first():
            params["email_error_message"] = "This email already exists"
            return render_template('sign_up.html', **params)
        user = User(
            login=form.login.data,
            email=form.email.data,
        )
        icon_data = form.icon.data.read()
        if icon_data == b'':
            icon_id = save_default_user_icon()
        else:
            icon_id = save_custom_user_icon(icon_data)
        user.icon_id = icon_id
        user.set_password(form.password.data)
        session.add(user)
        session.commit()
        return redirect('/home')
    return render_template('sign_up.html', **params)
예제 #2
0
def main():
    """
    conn_string = "host='ec2-52-202-22-140.compute-1.amazonaws.com' dbname='datnhrra0kdml8' user='******' password='******'"
    conn = psycopg2.connect(conn_string)
    c = conn.cursor()
    c.execute("SET SESSION idle_in_transaction_session_timeout = '5s';")
    conn.commit()
    conn.close()
    sleep(.1)
    """
    processes = []
    # db_session.global_init(os.environ("DATABASE_URL"))
    db_session.global_init(app.config["SQLALCHEMY_DATABASE_URI"])
    p = multiprocessing.Process(target=test_forever)
    processes.append(p)
    p.start()
    p = multiprocessing.Process(target=app.run(port=8080, threaded=True))  # host='0.0.0.0'-run on local network with ip
    processes.append(p)
    p.start()
    for process in processes:
        process.join()
예제 #3
0
def test_forever():
    # db_session.global_init("postgres://*****:*****@ec2-52-202-22-140.compute-1.amazonaws.com:5432/datnhrra0kdml8")
    db_session.global_init("sqlite:///data/db/main.sqlite?check_same_thread=False")
    while 1:
        test_all_submissions()
        sleep(1)
예제 #4
0
def create_tables():
    db_session.global_init(app.config["SQLALCHEMY_DATABASE_URI"])
예제 #5
0
def start_page():
    db_session.global_init(app.config["SQLALCHEMY_DATABASE_URI"])
    return redirect('/home')