コード例 #1
0
def do_login():
    """ Lo the user in user.
    """
    form = forms.LoginForm()
    next_url = flask.request.args.get('next_url')
    if not next_url or next_url == 'None':
        next_url = flask.url_for('index')

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

        user_obj = mirrormanager2.lib.get_user_by_username(SESSION, username)
        if not user_obj or user_obj.password != password:
            flask.flash('Username or password invalid.', 'error')
            return flask.redirect(flask.url_for('auth_login'))
        elif user_obj.token:
            flask.flash(
                'Invalid user, did you confirm the creation with the url '
                'provided by email?', 'error')
            return flask.redirect(flask.url_for('auth_login'))
        else:
            visit_key = mirrormanager2.lib.id_generator(40)
            expiry = datetime.datetime.now() + APP.config.get(
                'PERMANENT_SESSION_LIFETIME')
            session = model.UserVisit(
                user_id=user_obj.id,
                user_ip=flask.request.remote_addr,
                visit_key=visit_key,
                expiry=expiry,
            )
            SESSION.add(session)
            try:
                SESSION.commit()
                flask.g.fas_user = user_obj
                flask.g.fas_session_id = visit_key
                flask.flash('Welcome %s' % user_obj.username)
            except SQLAlchemyError as err:  # pragma: no cover
                flask.flash(
                    'Could not set the session in the db, '
                    'please report this error to an admin', 'error')
                APP.logger.exception(err)

        return flask.redirect(next_url)
    else:
        flask.flash('Insufficient information provided', 'error')
    return flask.redirect(flask.url_for('auth_login'))
コード例 #2
0
ファイル: __init__.py プロジェクト: nphilipp/mirrormanager2
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()