예제 #1
0
def create_user(name, login, email, birthdate, groups, processor, address):
    """Create a new member

    Create a new user with a generated password, finance- and unix account, and make him member
    of the `config.member_group` and `config.network_access_group`.

    :param str name: The full name of the user (e.g. Max Mustermann)
    :param str login: The unix login for the user
    :param str email: E-Mail address of the user
    :param Date birthdate: Date of birth
    :param PropertyGroup groups: The initial groups of the new user
    :param User processor: The processor
    :param Address address: Where the user lives. May or may not come from a room.
    :return:
    """

    now = session.utcnow()
    plain_password = user_helper.generate_password(12)
    # create a new user
    new_user = User(
        login=login,
        name=name,
        email=email,
        registered_at=now,
        account=Account(name="", type="USER_ASSET"),
        password=plain_password,
        birthdate=birthdate,
        address=address
    )

    account = UnixAccount(home_directory="/home/{}".format(login))
    new_user.unix_account = account

    with session.session.begin(subtransactions=True):
        session.session.add(new_user)
        session.session.add(account)
    new_user.account.name = deferred_gettext(u"User {id}").format(
        id=new_user.id).to_json()

    for group in groups:
        make_member_of(new_user, group, processor, closed(now, None))

    log_user_event(author=processor,
                   message=deferred_gettext(u"User created.").to_json(),
                   user=new_user)

    return new_user, plain_password
예제 #2
0
def create_user(name,
                login,
                email,
                birthdate,
                groups,
                processor,
                address,
                passwd_hash=None,
                send_confirm_mail: bool = False):
    """Create a new member

    Create a new user with a generated password, finance- and unix account, and make him member
    of the `config.member_group` and `config.network_access_group`.

    :param str name: The full name of the user (e.g. Max Mustermann)
    :param str login: The unix login for the user
    :param str email: E-Mail address of the user
    :param Date birthdate: Date of birth
    :param PropertyGroup groups: The initial groups of the new user
    :param Optional[User] processor: The processor
    :param Address address: Where the user lives. May or may not come from a room.
    :param passwd_hash: Use password hash instead of generating a new password
    :param send_confirm_mail: If a confirmation mail should be send to the user
    :return:
    """

    now = session.utcnow()
    plain_password = user_helper.generate_password(12)
    # create a new user
    new_user = User(login=login,
                    name=name,
                    email=email,
                    registered_at=now,
                    account=Account(name="", type="USER_ASSET"),
                    password=plain_password,
                    wifi_password=generate_wifi_password(),
                    birthdate=birthdate,
                    address=address)

    processor = processor if processor is not None else new_user

    if passwd_hash:
        new_user.passwd_hash = passwd_hash
        plain_password = None

    account = UnixAccount(home_directory="/home/{}".format(login))
    new_user.unix_account = account

    with session.session.begin(subtransactions=True):
        session.session.add(new_user)
        session.session.add(account)
    new_user.account.name = deferred_gettext(u"User {id}").format(
        id=new_user.id).to_json()

    for group in groups:
        make_member_of(new_user, group, processor, closed(now, None))

    log_user_event(author=processor,
                   message=deferred_gettext(u"User created.").to_json(),
                   user=new_user)

    user_send_mail(new_user, UserCreatedTemplate(), True)

    if email is not None and send_confirm_mail:
        send_confirmation_email(new_user)

    return new_user, plain_password
예제 #3
0
파일: user.py 프로젝트: sgeisler/pycroft
def move_in(name,
            login,
            email,
            dormitory,
            level,
            room_number,
            mac,
            processor,
            host_name=None):
    """
    This function creates a new user, assign him to a room and creates some
    initial groups and transactions.
    :param name: The full name of the user. (Max Mustermann)
    :param login: The unix login for the user.
    :param email: E-Mail address of the user.
    :param dormitory: The dormitory the user moves in.
    :param level: The level the user moves in.
    :param room_number: The room number the user moves in.
    :param mac: The mac address of the users pc.
    :param host_name: An optional Hostname for the users pc.
    :return: The new user object.
    """

    room = Room.q.filter_by(number=room_number,
                            level=level,
                            dormitory=dormitory).one()

    # create a new user
    new_user = User(login=login,
                    name=name,
                    email=email,
                    room=room,
                    registration_date=datetime.now())
    plain_password = user.generate_password(12)

    #TODO: print plain password on paper instead
    print u"new password: "******"move_in"]
    for membership in conf["group_memberships"]:
        group = Group.q.filter(Group.name == membership["name"]).one()
        start_date = datetime.now()
        if membership.get("offset"):
            start_date += timedelta(membership["offset"])
        new_membership = create_membership(start_date=start_date,
                                           end_date=None,
                                           group=group,
                                           user=new_user)
        if membership.get("duration"):
            assert membership["duration"] > 0
            new_membership.end_date = datetime.now() + timedelta(
                membership["duration"])

    setup_user_finance_account(new_user, processor)

    move_in_user_log_entry = create_user_log_entry(author=processor,
                                                   message=conf["log_message"],
                                                   timestamp=datetime.now(),
                                                   user=new_user)

    return new_user