Exemplo n.º 1
0
def load_fixtures():
    """ Create the database and load the fixtures """
    db_uri = current_app.config['SQLALCHEMY_DATABASE_URI']
    if not database_exists(db_uri):
        create_database(db_uri)
    else:
        db.drop_all()

    db.create_all()

    # Fixtures
    user = User()
    user.email = '*****@*****.**'
    user.password = '******'
    user.active = True
    db.session.add(user)
    db.session.commit()

    print('Initialized the database.')
Exemplo n.º 2
0
def init_db():
    """ Initialize db """
    db_uri = current_app.config['SQLALCHEMY_DATABASE_URI']
    if not database_exists(db_uri):
        create_database(db_uri)
    else:
        db.drop_all()

    db.create_all()

    # Fixtures
    user = User()
    user.email = '*****@*****.**'
    user.password = '******'
    user.active = True
    db.session.add(user)
    db.session.commit()

    print('Initialized the database.')
Exemplo n.º 3
0
def register():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        email = request.form['email']
        is_form_valid = True

        if username.strip() == '':
            is_form_valid = False
            flash('username should be filled!', 'error')
        if password.strip() == '':
            is_form_valid = False
            flash('password should be filled!', 'error')
        if email.strip() == '':
            is_form_valid = False
            flash('email should be filled!', 'error')

        if not is_form_valid:
            return render_template('register.html')

        # check username if already register
        # get user
        users = User.query.filter_by(username=username).all()
        if is_form_valid and len(users) > 0:
            flash('username already registered!', 'error')
            print('username already registered')
            return render_template('register.html')

        user = User()
        user.username = username
        user.password = User.generate_hash(password)
        user.email = email
        user.role = 'user'
        user.is_active = False
        db.session.add(user)
        db.session.commit()
        flash(
            'successfully registered, please wait for admin to activate your account!'
        )
    return render_template('register.html')