def accounts_create(): form = AccountCreateForm() if form.validate_on_submit(): new_account = Account(name=form.name.data, type=form.type.data) session.add(new_account) session.commit() return redirect(url_for('.accounts_list')) return render_template('finance/accounts_create.html', form=form, page_title=u"Konto erstellen")
def accounts_show_json(account_id): style = request.args.get('style') limit = request.args.get('limit', type=int) offset = request.args.get('offset', type=int) sort_by = request.args.get('sort', default="valid_on") sort_order = request.args.get('order', default="desc") search = request.args.get('search') splitted = request.args.get('splitted', default=False, type=bool) if sort_by.startswith("soll_") or sort_order.startswith("haben_"): sort_by = '_'.join(sort_by.split('_')[1:]) account = Account.get(account_id) or abort(404) total = Split.q.join(Transaction).filter(Split.account == account).count() build_this_query = partial(build_transactions_query, account=account, search=search, sort_by=sort_by, sort_order=sort_order, offset=offset, limit=limit, eagerload=True) def rows_from_query(query): # iterating over `query` executes it return [_format_row(split, style) for split in query] if splitted: rows_pos = rows_from_query(build_this_query(positive=True)) rows_neg = rows_from_query(build_this_query(positive=False)) _keys = ['posted_at', 'valid_on', 'description', 'amount'] _filler = { key: None for key in chain(('soll_' + key for key in _keys), ('haben_' + key for key in _keys)) } rows = [ _prefixed_merge(split_pos, 'soll', split_neg, 'haben') for split_pos, split_neg in zip_longest( rows_pos, rows_neg, fillvalue=_filler) ] else: query = build_this_query() rows = rows_from_query(query) items = {'total': total, 'rows': rows} return jsonify(name=account.name, items=items)
def account_toggle_legacy(account_id): account = Account.get(account_id) if not account: abort(404) account.legacy = not account.legacy session.commit() flash("Der Status des Kontos wurde umgeschaltet.", "success") return redirect(url_for('.accounts_show', account_id=account_id))
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
def test_0010_user_login_validator(self): account = Account(name='', type='ASSET') room = facilities.Room.q.first() u = user.User(name="John Doe", registered_at=session.utcnow(), room=room, address=room.address, account=account) for length in range(1, 30): if 2 <= length < 23: u.login = "******" * length else: with self.assertRaises(IllegalLoginError): u.login = "******" * length valid = ["abcdefg", "a-b", "a3b", "a.2b", "a33", "a-4"] invalid = ["123", "ABC", "3bc", "_ab", "ab_", "3b_", "_b3", "&&", "a_b", "a_2b", "a_4", "-ab", "ab-", ".ab", "ab."] blocked = ["abuse", "admin", "administrator", "autoconfig", "broadcasthost", "root", "daemon", "bin", "sys", "sync", "games", "man", "hostmaster", "imap", "info", "is", "isatap", "it", "localdomain", "localhost", "lp", "mail", "mailer-daemon", "news", "uucp", "proxy", "majordom", "marketing", "mis", "noc", "website", "api" "noreply", "no-reply", "pop", "pop3", "postmaster", "postgres", "sales", "smtp", "ssladmin", "status", "ssladministrator", "sslwebmaster", "support", "sysadmin", "usenet", "webmaster", "wpad", "www", "wwwadmin", "backup", "msql", "operator", "user", "ftp", "ftpadmin", "guest", "bb", "nobody", "www-data", "bacula", "contact", "email", "privacy", "anonymous", "web", "git", "username", "log", "login", "help", "name"] for login in valid: u.login = login for login in invalid: with self.assertRaises(IllegalLoginError): u.login = login for login in blocked: with self.assertRaises(IllegalLoginError): u.login = login u = user.User.q.filter_by(login=UserData.dummy.login).one() with self.assertRaisesRegexp(AssertionError, "user already in the database - cannot change login anymore!"): u.login = "******"
def accounts_show(account_id): account = Account.get(account_id) if account is None: flash(f"Konto mit ID {account_id} existiert nicht!", 'error') abort(404) try: user = User.q.filter_by(account_id=account.id).one() except NoResultFound: user = None except MultipleResultsFound: user = User.q.filter_by(account_id=account.id).first() flash( "Es existieren mehrere Nutzer, die mit diesem Konto" " verbunden sind!", "warning") inverted = account.type == "USER_ASSET" _table_kwargs = { 'data_url': url_for("finance.accounts_show_json", account_id=account_id), 'saldo': account.balance, 'inverted': inverted } balance = -account.balance if inverted else account.balance return render_template( 'finance/accounts_show.html', account=account, user=user, balance=balance, balance_json_url=url_for('.balance_json', account_id=account_id, invert=inverted), finance_table_regular=FinanceTable(**_table_kwargs), finance_table_splitted=FinanceTableSplitted(**_table_kwargs), account_name=localized(account.name, {int: { 'insert_commas': False }}))
def bank_accounts_create(): form = BankAccountCreateForm() if form.validate_on_submit(): new_bank_account = BankAccount( name=form.name.data, bank=form.bank.data, account_number=form.account_number.data, routing_number=form.routing_number.data, iban=form.iban.data, bic=form.bic.data, fints_endpoint=form.fints.data, account=Account(name=form.name.data, type='BANK_ASSET'), ) session.add(new_bank_account) session.commit() return redirect(url_for('.bank_accounts_list')) return render_template('finance/bank_accounts_create.html', form=form, page_title=u"Bankkonto erstellen")
def transactions_create(): form = TransactionCreateForm() if form.validate_on_submit(): splits = [] for split_form in form.splits: splits.append((Account.get(split_form.account_id.data), split_form.amount.data)) transaction = finance.complex_transaction( description=form.description.data, author=current_user, splits=splits, valid_on=form.valid_on.data, confirmed=current_user.member_of(config.treasurer_group), ) end_payment_in_default_memberships(current_user) session.commit() return redirect( url_for('.transactions_show', transaction_id=transaction.id)) return render_template('finance/transactions_create.html', form=form)
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