Exemplo n.º 1
0
def accounts_create():
    form = AccountForm(request.form)

    if not form.validate():
        return render_template("accounts/account_form.html", form = form)

    account = Account.query.filter_by(username=form.username.data).first()

    if account:
        return render_template("accounts/account_form.html",
            form = form,
            error = "Username is taken, please select another one"
        )

    account = Account(
        form.name.data,
        form.username.data,
        sha256_crypt.encrypt(form.password.data),
        form.email.data
    )

    db.session.add(account)
    db.session.commit()

    return redirect(url_for("login"))
Exemplo n.º 2
0
def accountgroup_new_account(accountgroup_id):

    accountform = AccountForm(request.form)
    print("Yritetään lisätä uutta tiliä ryhmään " +
          str(accountform.accountgroup_id.data))

    if not accountform.validate():
        return render_template(
            "accountgroups/list.html",
            action="FixNewAccount",
            targetgroup=accountgroup_id,
            targetaccount=-1,
            accountgroups=AccountGroup.findAllGroupsAndAccounts(
                current_user.get_entity_id()),
            newaccountgroupform=AccountGroupForm(),
            fixnewaccountform=accountform,
            newaccountform=AccountForm())

    a = Account(accountform.number.data, accountform.name.data,
                accountform.description.data, accountform.inuse.data,
                accountgroup_id, current_user.get_entity_id())
    try:
        db.session().add(a)
        db.session().commit()
    except:
        ## TÄHÄN VIRHETILANTEEN KÄSITTELY
        print("Tapahtui virhe lisätessä uutta tiliä tietokantaan")
        pass

    return redirect(url_for("accountgroups_index"))
Exemplo n.º 3
0
def accounts_single(account_id):
    a = Account.query.get(account_id)

    if not a:
        return render_template("404.html", res_type="account"), 404

    if a.id not in [a.id for a in Account.get_allowed()]:
        return login_manager.unauthorized()

    return render_template("accounts/single.html", account=a)
Exemplo n.º 4
0
def accounts_delete(account_id):
    a = Account.query.get(account_id)

    if not a:
        return render_template("404.html", res_type="account"), 404

    if a.id not in [a.id for a in Account.get_allowed()]:
        return login_manager.unauthorized()

    db.session.delete(a)
    db.session.commit()
    return redirect(url_for("accounts_list"))
Exemplo n.º 5
0
def accounts_create():
    form = AddAccountForm(request.form)
    if not form.validate():
        return render_template("accounts/new.html", form=form)
    a = Account(form.username.data, form.password.data)
    db.session().add(a)
    try:
        db.session().commit()
    except IntegrityError:  # Unique constaint error?
        flash('Username is not unique !')
        db.session.rollback()
        return render_template("accounts/new.html", form=form)
    return redirect(url_for("accounts_index"))
Exemplo n.º 6
0
def accounts_form_update(account_id):
    a = Account.query.get(account_id)

    if not a:
        return render_template("404.html", res_type="account"), 404

    if a.id not in [a.id for a in Account.get_allowed()]:
        return login_manager.unauthorized()

    form = AccountFormUpdate()
    form.community.data = a.community
    form.admin_communities.data = a.admin_communities
    return render_template("accounts/update.html", account=a, form=form)
Exemplo n.º 7
0
def accounts_update(account_id):
    a = Account.query.get(account_id)

    if not a:
        return render_template("404.html", res_type="account"), 404

    if a.id not in [a.id for a in Account.get_allowed()]:
        return login_manager.unauthorized()

    old_a = copy.deepcopy(a)
    form = AccountFormUpdate(request.form)

    if not form.validate():
        clean_pw(form)
        return render_template("accounts/update.html", account=a, form=form)

    if not argon2.verify(form.current_pw.data, a.pw_hash):
        clean_pw(form)
        form.current_pw.errors.append("Wrong current password.")
        return render_template("accounts/update.html", account=a, form=form)

    if form.password.data:
        a.pw_hash = argon2.hash(form.password.data)

    clean_pw(form)

    for field in form:
        if field.data:
            setattr(a, field.name, field.data)
    a.admin_communities = form.admin_communities.data

    try:
        db.session().commit()
    except exc.SQLAlchemyError as e:
        db.session().rollback()
        msg = "This username is already taken, please choose another one."
        form.username.errors.append(msg)
        return render_template("accounts/update.html",
                               account=old_a,
                               form=form)

    return redirect(url_for("accounts_single", account_id=a.id))
Exemplo n.º 8
0
def accounts_create():
    form = AccountFormCreate(request.form)

    if not form.validate():
        clean_pw(form)
        return render_template("accounts/new.html", form=form)

    pw_hash = argon2.hash(form.password.data)
    clean_pw(form)

    a = Account(form.community.data.id, form.username.data, pw_hash,
                form.apartment.data, form.forename.data, form.surname.data,
                form.email.data, form.phone.data, form.admin_communities.data)

    try:
        db.session().add(a)
        db.session().commit()
    except exc.SQLAlchemyError as e:
        db.session().rollback()
        msg = "This username is already taken, please choose another one."
        form.username.errors.append(msg)
        return render_template("accounts/new.html", form=form)

    return redirect(url_for("accounts_single", account_id=a.id))
Exemplo n.º 9
0
def accounts_list():
    return render_template("accounts/list.html",
                           accounts=Account.list_with_debt())