Example #1
0
def new_user():
    """ Create a new user.
    """
    form = forms.NewUserForm()
    if form.validate_on_submit():

        username = form.user_name.data
        if mirrormanager2.lib.get_user_by_username(SESSION, username):
            flask.flash('Username already taken.', 'error')
            return flask.redirect(flask.request.url)

        email = form.email_address.data
        if mirrormanager2.lib.get_user_by_email(SESSION, email):
            flask.flash('Email address already taken.', 'error')
            return flask.redirect(flask.request.url)

        password = '******' % (form.password.data,
                             APP.config.get('PASSWORD_SEED', None))
        form.password.data = hashlib.sha512(password).hexdigest()

        token = mirrormanager2.lib.id_generator(40)

        user = model.User()
        user.token = token
        form.populate_obj(obj=user)
        SESSION.add(user)

        try:
            SESSION.flush()
            send_confirmation_email(user)
            flask.flash(
                'User created, please check your email to activate the '
                'account')
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not create user.')
            APP.logger.debug('Could not create user.')
            APP.logger.exception(err)

        SESSION.commit()

        return flask.redirect(flask.url_for('auth_login'))

    return flask.render_template(
        'user_new.html',
        form=form,
    )
Example #2
0
def create_base_items(session):
    ''' Insert some base information in the database.
    '''
    # Insert some Arch
    item = model.Arch(
        name='source',
        publiclist=False,
        primary_arch=False,
    )
    session.add(item)
    item = model.Arch(
        name='i386',
        publiclist=True,
        primary_arch=True,
    )
    session.add(item)
    item = model.Arch(
        name='x86_64',
        publiclist=True,
        primary_arch=True,
    )
    session.add(item)
    item = model.Arch(
        name='ppc',
        publiclist=True,
        primary_arch=False,
    )
    session.add(item)

    # Insert some Country
    item = model.Country(code='FR', )
    session.add(item)
    item = model.Country(code='US', )
    session.add(item)

    # Insert some Product
    item = model.Product(
        name='EPEL',
        publiclist=True,
    )
    session.add(item)
    item = model.Product(
        name='Fedora',
        publiclist=True,
    )
    session.add(item)

    # Insert some CountryContinentRedirect
    item = model.CountryContinentRedirect(
        country='IL',
        continent='EU',
    )
    session.add(item)
    item = model.CountryContinentRedirect(
        country='AM',
        continent='EU',
    )
    session.add(item)
    item = model.CountryContinentRedirect(
        country='JO',
        continent='EU',
    )
    session.add(item)

    # Insert some User
    item = model.User(
        user_name='pingou',
        email_address='[email protected]',
        display_name='pingou',
        password='******',
    )
    session.add(item)
    item = model.User(
        user_name='kevin',
        email_address='[email protected]',
        display_name='kevin',
        password='******',
    )
    session.add(item)
    item = model.User(
        user_name='ralph',
        email_address='[email protected]',
        display_name='ralph',
        password='******',
    )
    session.add(item)
    item = model.User(
        user_name='shaiton',
        email_address='[email protected]',
        display_name='shaiton',
        password='******',
        token='bar',
    )
    session.add(item)

    # Insert some UserVisit
    item = model.UserVisit(user_id=1,
                           visit_key='foo',
                           user_ip='127.0.0.1',
                           expiry=datetime.datetime.utcnow() +
                           datetime.timedelta(days=1))
    session.add(item)

    session.commit()