Example #1
0
def edit_account(account_id):
    account = Account.query.get_or_404(account_id)
    form = AccountForm(obj=account)
    completion_msg = ""
    if form.validate_on_submit():
        if form.save.data:
            account.name = form.name.data
            account.pnumber = form.pnumber.data
            account.email = form.email.data
            account.street = form.street.data
            account.city = form.city.data
            account.state = form.state.data
            account.postal = form.postal.data
            account.country = form.country.data
            account.notes = form.notes.data
            try:
                db.session.commit()
            except:
                completion_msg = "Failed to update account. Please try again."
            if completion_msg == "":
                completion_msg = "Success! The account has been saved."
                return redirect(url_for('view_account'))
        else:
            completion_msg = "Failed to update account. Please try again."
    return render_template("edit_account.html",
                           form=form,
                           completion_msg=completion_msg)
Example #2
0
def account_settings():
    form = AccountForm()
    formpass = ChangePasswordForm()
    error = ''
    sel_tab = 1
    user = UserAccount.query.filter(UserAccount.id==g.user.id).one()
    if form.validate_on_submit():
        user.username = form.username.data
        user.email = form.email.data
        db.session.add(user)
        db.session.commit()
        flash ('Changes saved.')
    form.username.data = user.username
    form.email.data = user.email

    if request.method == 'POST' and formpass.submit_pass:
        sel_tab = 2
    if formpass.validate_on_submit():

        password = md5.md5(formpass.password.data).hexdigest()
        user1 = UserAccount.query.filter(and_(UserAccount.id==g.user.id, UserAccount.password==password)).first()
        if not user1:
            error = 'Invalid  password.'
        else:
            newpassword = md5.md5(formpass.newpassword.data).hexdigest()
            user1.password = newpassword
            db.session.add(user1)
            db.session.commit()
            flash ('New password saved.')
    return render_template('account.html', form=form, formpass=formpass, site_data=site_data(), navigation=return_navigation(), error=error, sel_tab=sel_tab)
Example #3
0
def create_account():
    form = AccountForm()
    completion_msg = ""
    if form.validate_on_submit():
        if form.save.data:
            new_account = Account(name=form.name.data,
                                  pnumber=form.pnumber.data,
                                  email=form.email.data,
                                  street=form.street.data,
                                  city=form.city.data,
                                  state=form.state.data,
                                  postal=form.postal.data,
                                  country=form.country.data,
                                  notes=form.notes.data)
            db.session.add(new_account)
            try:
                db.session.commit()
            except:
                completion_msg = "Failed to create account. Please try again."
            if completion_msg == "":
                completion_msg = "Success! The account has been saved."
                return redirect(url_for('view_account'))
        else:
            completion_msg = "Failed to create account. Please try again."
    return render_template("create_account.html",
                           form=form,
                           completion_msg=completion_msg)
Example #4
0
def add_account():
    """
    Add a account to the database
    """
    check_admin()

    add_account = True

    form = AccountForm()
    if form.validate_on_submit():
        account = Account(AccNum=form.AccNum.data,
                          name=form.name.data,
                          AccCategory=form.AccCategory.data,
                          SaccCategory=form.SaccCategory.data,
                          balance=form.balance.data,
                          Comment=form.Comment.data)
        try:
            # add department to the database
            db.session.add(account)
            db.session.commit()
            flash('You have successfully added a new entry.')
        except:
            # in case department name already exists
            flash('Error: entry name already exists.')

        # redirect to departments page
        return redirect(url_for('admin.list_account'))

    # load department template
    return render_template('admin/accounts/account.html',
                           action="Add",
                           add_account=add_account,
                           form=form,
                           title="Add Account")
Example #5
0
def do_create_account():
    form = AccountForm(request.form)
    account = Account()
    form.populate_obj(account)

    if form.validate_on_submit():
        account.save()
        return redirect(url_for("app_blueprint.show_accounts"))

    return render_template("account.html", form=form), 400
Example #6
0
def account_add():
    form = AccountForm()
    if current_user.is_manager:
        form.role.choices = [(current_user.MANAGER, 'Manager'),(current_user.ADMIN, 'Admin')]
    if form.validate_on_submit():
        account = User(form.username.data, form.password.data,
                    form.email.data, form.displayname.data, form.role.data)
        account.language = form.language.data
        account.organisations = form.organisations.data
        db.session.add(account)
        db.session.commit()
        flash(_('Account added'))
        return redirect(url_for("profil.accounts"))
    return render_template('account_add.html', form=form)
def account():
    img = url_for('static', filename='profile_pics/' + current_user.image)
    form = AccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            random_hex = secrets.token_hex(8)
            _, p_ext = os.path.splitext(form.picture.data.filename)
            p_fn = random_hex + p_ext
            picture_path = os.path.join(app.root_path, 'static/profile_pics',
                                        p_fn)
            form.picture.data.save(picture_path)
            db.update_picture(p_fn, current_user.username)
            current_user.image = p_fn
            flash('Picture Successfully Updated', 'success')
            return redirect(url_for('account'))
    return render_template('account.html',
                           title='Account',
                           form=form,
                           image_file=img)
Example #8
0
def account():
    form = AccountForm()
    if form.validate_on_submit():
        # Update user picture
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        # Update user info
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash("Your account has been updated!", 'success')
        return redirect(url_for('account'))
    elif request.method == 'GET':
        # Prepopulate field with user info
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file = url_for('static',
                         filename='images/' + current_user.image_file)
    return render_template('account.html', image_file=image_file, form=form)
Example #9
0
def edit_account(id):
    """
    Edit an entry
    """
    check_admin()

    add_account = False

    account = Account.query.get_or_404(id)
    form = AccountForm(obj=account)
    if form.validate_on_submit():
        account.AccNum = form.AccNum.data
        account.name = form.name.data
        account.AccCategory = form.AccCategory.data
        account.SaccCategory = form.SaccCategory.data
        account.balance = form.balance.data
        account.Comment = form.Comment.data

        db.session.commit()
        flash('You have successfully edited the entry.')

        # redirect to the departments page
        return redirect(url_for('admin.list_account'))
    form.AccNum.data = account.AccNum
    form.name.data = account.name
    form.AccCategory.data = account.AccCategory
    form.SaccCategory.data = account.SaccCategory
    form.balance.data = account.balance
    form.Comment.data = account.Comment

    return render_template('admin/accounts/account.html',
                           action="Edit",
                           add_account=add_account,
                           form=form,
                           account=account,
                           title="Edit Entry")
Example #10
0
def my_account():
    user_info = General.query.get(current_user.id)
    form = AccountForm(
        name=user_info.name,
        email=user_info.email,
        password=None,
        api_key=user_info.api_key,
    )
    if form.validate_on_submit():
        message = ""
        if form.password.data:
            hash_pw = generate_password_hash(form.password.data,
                                             method="pbkdf2:sha256",
                                             salt_length=8)
            user_info.password = hash_pw
            message += "Password change has been saved."
        user_info.name = form.name.data
        user_info.email = form.email.data
        user_info.api_key = form.api_key.data
        message += " All changes saved."
        flash(message)
        db.session.commit()
        return redirect(url_for("account.my_account"))
    return render_template("account.html", form=form, api=user_info.api_key)