Ejemplo n.º 1
0
def migrate_datas():
    from autonomie_base.models.base import DBSESSION
    session = DBSESSION()
    from alembic.context import get_bind
    connection = get_bind()

    from autonomie.models.user.login import Login
    op.execute("update groups set editable=0;")
    op.execute("update groups set `primary`=0;")
    op.execute(
        "update groups set `primary`=1 where name IN ('admin', 'contractor', 'manager')"
    )
    op.execute('update accounts set civilite="Monsieur"')

    for user in connection.execute(user_helper.select()):
        login = Login(
            user_id=user.id,
            login=user.login,
        )
        login.pwd_hash = user.password,
        login.active = user.active == 'Y'
        session.add(login)
        session.flush()
        op.execute(
            'UPDATE user_groups set login_id="%s" where user_id=%s' % (
                login.id, user.id
            )
        )
    op.drop_column("accounts", "login")
    op.drop_column("accounts", "password")
    op.drop_column("accounts", "active")


    from autonomie.models.user.user import User
    for userdatas in connection.execute(userdatas_helper.select()):
        if userdatas.user_id is None:
            user = User(
                lastname=userdatas.coordonnees_lastname,
                firstname=userdatas.coordonnees_firstname,
                email=userdatas.coordonnees_email1,
                civilite=userdatas.coordonnees_civilite or 'Monsieur',
            )
            session.add(user)
            session.flush()
            connection.execute(
                userdatas_helper.update().where(
                    userdatas_helper.c.id == userdatas.id
                ).values(user_id=user.id)
            )
        else:
            user = User.get(userdatas.user_id)
            user.civilite = userdatas.coordonnees_civilite or 'Monsieur'
            session.merge(user)
            session.flush()

    op.execute('update accounts set civilite="Monsieur" where civilite is NULL')
Ejemplo n.º 2
0
def test_auth(dbsession):
    """
    Test user authentication
    """
    a = Login(login="******")
    a.set_password('pwd')
    assert a.auth("pwd") is True
    strange = "#;\'\\\" $25; é ö ô è à ù"
    a.set_password(strange)
    assert not a.auth("pwd")
    assert a.auth(strange) is True

    a.active = False
    assert not a.auth(strange)
Ejemplo n.º 3
0
def test_auth(dbsession):
    """
    Test user authentication
    """
    a = Login(login="******")
    a.set_password('pwd')
    assert a.auth("pwd") is True
    strange = "#;\'\\\" $25; é ö ô è à ù"
    a.set_password(strange)
    assert not a.auth("pwd")
    assert a.auth(strange) is True

    a.active = False
    assert not a.auth(strange)