コード例 #1
0
ファイル: routes.py プロジェクト: d1mlex/test_task
def account():
    user_pic = url_for('static', filename='pics/' + current_user.user_pic)
    all_posts = [post[0] for post in posts]
    post_names = [i for i in all_posts if i != current_user.post_name]
    acc_form = AccountForm(prefix='form1')
    new_user_form = AddNewUserForm(prefix='form2')
    delete_user_form = DeleteUserForm(prefix='form3')
    if acc_form.submit1.data and acc_form.validate_on_submit():
        print('1')
        flash('Сохранено', 'success')
        return redirect(url_for('account'))
    if new_user_form.submit2.data and new_user_form.validate_on_submit():
        print('2')
        flash('Пользователь добавлен', 'success')
        return redirect(url_for('account'))
    if delete_user_form.submit3.data and delete_user_form.validate_on_submit():
        print('3')
        flash('Пользователь удален', 'success')
        return redirect(url_for('account'))
    return render_template('account.html',
                           acc_form=acc_form,
                           posts=post_names,
                           user_pic=user_pic,
                           new_user_form=new_user_form,
                           all_posts=all_posts,
                           delete_user_form=delete_user_form)
コード例 #2
0
ファイル: main.py プロジェクト: kmvdj23/HR-System
def settings():
    form = AccountForm(obj=current_user)

    # Set new labels
    form.password.label.text = 'New password'
    form.confirm_pass.label.text = 'Confirm New Password'

    if form.validate_on_submit():
        current_user.first_name = request.form.get('first_name')
        current_user.last_name = request.form.get('last_name')
        current_user.username = request.form.get('username')
        current_user.mobile = request.form.get('mobile')

        old_pass = request.form.get('old_password')
        new_pass = request.form.get('password')

        if old_pass != '' and new_pass != '' and password_decrypt(
                old_pass, current_user.password):
            current_user.password = password_encrypt(new_pass)

        db.session.commit()

        flash('Account settings modified', 'success')
        return redirect(url_for('main.settings_page'))

    else:
        flash('Account settings not modified', 'danger')
        return render_template('pages/settings.html', form=form)
コード例 #3
0
def profile():
    form = AccountForm(obj=current_user)

    if form.validate_on_submit():
        form.populate_obj(current_user)
        current_user.save()

        return(redirect(url_for('main.profile')))

    return render_template('/pages/profile.html', form=form)
コード例 #4
0
ファイル: routes.py プロジェクト: jedgecombe/ship-that-stinks
def update_account():
    form = AccountForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter_by(id=current_user.id).first()
            user.set_password(form.password.data)
            db.session.add(user)
            db.session.commit()
            flash('Password has been updated!', 'success')
            return redirect(url_for('index'))
    return render_template('update_account.html', title='My account', form=form)
コード例 #5
0
def reset_password(reset_token):
    account = Account.deserialize_token(reset_token)
    form = AccountForm(obj=account)

    if account and form.validate_on_submit():
        account.password = password_encrypt(request.form.get('password'))
        account.save()

        flash('Password has been reset', 'success')
        return redirect(url_for('main.login_page'))

    flash('An error occurred', 'danger')
    return redirect(url_for('main.login_page'))
コード例 #6
0
def account():
    form = AccountForm()

    if form.validate_on_submit():
        if form.new_password.data:
            current_user.set_password(form.new_password.data)
        if form.new_username.data:
            current_user.username = form.new_username.data
        db.session.commit()
        return redirect(url_for("home"))

    # Displays profile page
    return render_template("account.html", title="Account Settings", links=links, form=form)
コード例 #7
0
def change_password():
    form = AccountForm(obj=current_user)

    if form.validate_on_submit():
        if password_decrypt(request.form.get('old_password'), current_user.password):
            current_user.password = password_encrypt(request.form.get('password'))
            current_user.save()
            flash('Password changed succesfully', 'success')
        else:
            flash('Entered password does not match your current password', 'danger')
    else:
        flash('Password was not changed', 'danger')

    return redirect(url_for('main.profile'))
コード例 #8
0
def new_account():
    form = AccountForm()
    if request.method == 'POST' and form.validate_on_submit():
        username = request.form['username']
        if [x for x in users.users if x.username == username]:
            form.error = True
            return render_template('new_account.html', form=form)
        password = request.form['password']
        users.users.append(
            users.User(id=len(users.users) + 1,
                       username=username,
                       password=password))
        return redirect(url_for('accepted'))
    return render_template('new_account.html', form=form)
コード例 #9
0
ファイル: accounts.py プロジェクト: djit/monitor
def accountsNew():
    if request.method == 'POST':
        form = AccountForm(request.form)
        if form.validate():
            db.accounts.insert_one(form.data)
            flash('New account  %s added' %(form.name.data))
            return redirect('/admin/accounts')
        else:
            return render_template('backend/accounts/edit.html',
                                    form=form,
                                    title='New account')
    form = AccountForm()
    return render_template('backend/accounts/edit.html',
                            form=form,
                            title='New account')
コード例 #10
0
def account():
    form = AccountForm(current_user.username, current_user.email)
    if form.validate_on_submit():
        pw = request.form['password']
        current_user.username = form.username.data
        current_user.email = form.email.data
        current_user.about_me = form.about_me.data
        if pw != '':
            current_user.set_password(form.password.data)
        db.session.commit()
        return redirect(url_for('account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
        form.about_me.data = current_user.about_me
    return render_template('account.html', form=form)
コード例 #11
0
ファイル: it.py プロジェクト: kmvdj23/HR-System
def edit_page(username):
    account = Account.find_account(username)
    generated_password = generate_random_password()

    if not account:
        flash('User does not exist', 'danger')
        return redirect(url_for('it.accounts_page'))

    form = AccountForm(obj=account)

    form.role.default = account.role
    form.process()

    return render_template('pages/write_account.html',
                           form=form,
                           account=account,
                           generated_password=generated_password)
コード例 #12
0
ファイル: views.py プロジェクト: jessicacnx/smart-attendance
def login():
    account_form = AccountForm()

    if request.method == 'POST':
        if account_form.validate_on_submit():
            fullname = account_form.fullname.data
            username = account_form.username.data
            exists = Account.query.filter_by(username=username).first(
            )  # Checks database to see if username already exists
            if not exists:
                account = Account(fullname, username)
                db.session.add(account)
                db.session.commit()
            return render_template('home.html')

    else:
        return render_template('login.html', form=account_form)
コード例 #13
0
 def get_context_data(self, **kwargs):
     context = super(SaleFormView, self).get_context_data(**kwargs)
     context['sale'] = self.request.GET.get('sale')
     context['items'] = Item.objects.all().order_by('name')
     context['top_up_form'] = TopUpForm(prefix='top-up',
                                        initial=self.get_initial())
     context['account_form'] = AccountForm(prefix='account')
     return context
コード例 #14
0
ファイル: it.py プロジェクト: kmvdj23/HR-System
def register_page():
    form = AccountForm()

    # Set required fields
    form.password.validators.append(DataRequired())
    form.confirm_pass.validators.append(DataRequired())

    return render_template('pages/write_account.html', form=form)
コード例 #15
0
ファイル: it.py プロジェクト: kmvdj23/HR-System
def edit(username):
    account = Account.find_account(username)
    generated_password = generate_random_password()
    form = AccountForm(obj=account)

    form.role.default = account.role
    form.process()

    if form.validate_on_submit():
        form.populate_obj(account)

        db.session.commit()

        flash(f'Account updated for { account.username }', 'success')
    else:
        flash('Account not modified', 'danger')
        print('==================== ERRORS: edit() ================')
        for err in form.errors:
            print(err)
        return render_template('pages/write_account.html',
                               form=form,
                               account=account,
                               generated_password=generated_password)

    return redirect(url_for('it.accounts_page'))
コード例 #16
0
def launch_view(request, template='launch.html'):
    client = docker.from_env()
    container_launch = {}
    msg = []
    host_port = random.randrange(8000, 9000)
    accounts_active = accounts_running(client.containers.list(), client)
    if request.method == 'POST':
        form = AccountForm(request.POST)
        if form.is_valid():
            image = form.cleaned_data['account']
            if accounts_active.has_key(image):
                msg.append('account is already active')
                container_launch[image] = accounts_active[image]
            else:
                #cmd = "docker run -d -p %s:8443 sshbox:%s" %(host_port, image)
                cmd = "docker run -v /logvol:/logvol -d -p %s:8443 -h %s sshbox:%s" % (
                    host_port, image, image)
                run_cmd = os.system(cmd)
                if run_cmd == 0:
                    container_launch[str(image)] = host_port
                    msg.append(
                        'account activated click below link to access account')
                else:
                    msg.append('sorry the account name is not valid')
            form = AccountForm()
    else:
        form = AccountForm()
    return render_to_response(template, {
        'form': form,
        'container': container_launch,
        'msg': msg
    },
                              context_instance=RequestContext(request))
コード例 #17
0
def reset_password_page(reset_token):
    account = Account.deserialize_token(reset_token)
    form = AccountForm(obj=account)

    if account:
        return render_template('/pages/reset.html', form=form, reset_token=reset_token, account=account)

    flash('Token is invalid!', 'danger')
    return redirect(url_for('main.login_page'))
コード例 #18
0
def signup():
    if(current_user.is_authenticated and current_user.is_active):
        return redirect(url_for('main.home'))

    form = AccountForm(request.form)

    if form.validate_on_submit():
        account = Account()
        form.populate_obj(account)

        account.password = password_encrypt(account.password)

        account.save()

        if login_user(account) and account.is_active():
            account.update_activity_tracking(request.remote_addr)
            return redirect(url_for('main.home'))

    return render_template('/pages/signup.html', form=form)
コード例 #19
0
ファイル: accounts.py プロジェクト: djit/monitor
def accountsEdit(id):
    account = db.accounts.find_one({ '_id': ObjectId(id) })
    if account:
        if request.method == 'POST':
            form = AccountForm(request.form)
            if form.validate():
                db.accounts.update({ '_id': ObjectId(id) }, form.data)
                return redirect('/admin/accounts')
            else:
                return render_template('backend/accounts/edit.html',
                                        form=form,
                                        title='account: ' + account['name'])
        form=accountForm(data=account)
        return render_template('backend/accounts/edit.html',
                                form=form,
                                title='account: ' + account['name'])
    else:
        flash('account %s not found' %id)
    return redirect('/admin/accounts')
コード例 #20
0
ファイル: it.py プロジェクト: kmvdj23/HR-System
def register():
    form = AccountForm()

    # Set required fields
    form.password.validators.append(DataRequired())
    form.confirm_pass.validators.append(DataRequired())

    if form.validate_on_submit():
        account = Account()
        form.populate_obj(account)

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

        flash(f'Account for { account.username } created successfully',
              'success')
    else:
        flash('Account not created', 'danger')
        print('==================== ERRORS: register() ================')
        for err in form.errors:
            print(err)
            return render_template('pages/write_account.html', form=form)

    return redirect(url_for('it.accounts_page'))
コード例 #21
0
def account():
    """
    Route for url: server/settings/account/
    """
    if 'username' in session:
        form = AccountForm()
        if request.method == 'GET':
            cur                  = get_cursor()
            user_data            = get_user_data(cur, session['username'])
            form.first_name.data = user_data['first_name']
            form.last_name.data  = user_data['last_name']
            form.email.data      = user_data['email']
            return render_template('account.html', form     = form,
                                                   username = session['username'])

        if request.method == 'POST':
            if form.validate():
                cur = get_cursor()
                update_user_data(cur, form, session['username'])
                flash('Your account information has been successfully updated!')
                return redirect(url_for('account'))
            return render_template('account.html', form     = form,
                                                   username = session['username'])
    return abort(404)
コード例 #22
0
def edit():
    log(log.INFO, "/account_details")
    if "id" in request.args:
        id = int(request.args["id"])
        account = Account.query.filter(Account.id == id).first()
        if account is None:
            flash("Wrong account id.", "danger")
            log(log.ERROR, "Wrong account id.")
            return redirect(url_for("main.accounts"))
        form = AccountForm(
            id=account.id,
            name=account.name,
            product_id=account.product_id,
            phone_id=account.phone_id,
            reseller_id=account.reseller_id,
            sim=account.sim,
            imei=account.imei,
            comment=account.comment,
            activation_date=account.activation_date,
            months=account.months,
        )
        form.products = Product.query.filter(
            Product.deleted == False)  # noqa E712
        form.resellers = Reseller.query.filter(
            Reseller.deleted == False)  # noqa E712
        form.phones = all_phones()
        form.extensions = AccountExtension.query.filter(
            AccountExtension.account_id == form.id.data).all()
        form.name_changes = (AccountChanges.query.filter(
            AccountChanges.account_id == form.id.data).filter(
                AccountChanges.change_type ==
                AccountChanges.ChangeType.name).all())
        form.sim_changes = (AccountChanges.query.filter(
            AccountChanges.account_id == form.id.data).filter(
                AccountChanges.change_type ==
                AccountChanges.ChangeType.sim).all())
        form.is_edit = True
        form.save_route = url_for("account.save")
        form.delete_route = url_for("account.delete")
        form.close_button = url_for("main.accounts")
        form.reseller_name = account.reseller.name
        return render_template("account_details.html", form=form)
    else:
        prev_product = None
        prev_reseller = None
        if 'prev_reseller' in request.args and 'prev_product' in request.args:
            prev_product = request.args['prev_product']
            prev_reseller = request.args['prev_reseller']
        form = AccountForm()
        form.products = organize_list_starting_with_value(
            Product.query.filter(Product.deleted == False)  # noqa E712
            .order_by(Product.name).all(),
            prev_product) if prev_product else Product.query.all()
        form.resellers = organize_list_starting_with_value(
            Reseller.query.order_by(Reseller.name).all(),
            prev_reseller if prev_reseller else 'NITRIX')
        form.phones = all_phones()
        form.is_edit = False
        form.save_route = url_for("account.save")
        form.delete_route = url_for("account.delete")
        form.close_button = url_for("main.accounts")
        return render_template("account_details.html", form=form)
コード例 #23
0
def save():
    log(log.INFO, "/account_save")
    form = AccountForm(request.form)
    if form.validate_on_submit():
        form.name.data = form.name.data.strip()
        form.sim.data = form.sim.data.strip()
        new_account = False
        if form.id.data > 0:
            # Edit exists account
            account = Account.query.filter(Account.id == form.id.data).first()
            if account.name != form.name.data:
                # Changed account name
                change = AccountChanges(account=account)
                change.change_type = AccountChanges.ChangeType.name
                change.value_str = account.name
                change.save()
                flash(
                    f'In account {account.name} name changed to {form.name.data}',
                    'info')
            if account.sim != form.sim.data:
                # Changed account SIM
                change = AccountChanges(account=account)
                change.change_type = AccountChanges.ChangeType.sim
                change.value_str = account.sim
                change.save()
                flash(
                    f'In account {account.name} sim changed to {form.sim.data}',
                    'info')

            for k in request.form.keys():
                account.__setattr__(k, form.__getattribute__(k).data)
        else:
            # Add a new account
            if Account.query.filter(
                    Account.name == form.name.data,
                    Account.product_id == form.product_id.data).first():
                log(log.WARNING,
                    "Attempt to register account with existing credentials")
                flash('Such account already exists', 'danger')
                return redirect(url_for("account.edit"))
            new_account = True
            if form.sim_cost.data == 'yes':
                form.comment.data += f'\r\n\r\n{SIM_COST_ACCOUNT_COMMENT}'

            account = Account(
                name=form.name.data,
                product_id=form.product_id.data,
                reseller_id=form.reseller_id.data,
                phone_id=form.phone_id.data,
                sim=form.sim.data,
                imei=form.imei.data,
                comment=form.comment.data,
                activation_date=form.activation_date.data,
                months=form.months.data,
            )
            flash(f'Account {account.name} added', "info")
        # Check that months must be in 1-12
        if not 0 < account.months <= 12:
            flash("Months must be in 1-12", "danger")
            return redirect(url_for("account.edit", id=account.id))
        account.save()
        if new_account and ninja.configured:
            nina_api_result = add_ninja_invoice(account, new_account,
                                                'Activated')
            if not nina_api_result:
                log(log.ERROR,
                    "Could not register account as invoice in Invoice Ninja!")
                flash("WARNING! Account registration in Ninja failed!",
                      "danger")
        # Change Resellers last activity
        reseller = Reseller.query.filter(
            Reseller.id == account.reseller_id).first()
        reseller.last_activity = datetime.now()
        reseller.save()

        log(log.INFO, "Account data was saved")
        if request.form["submit"] == "save_and_add":
            return redirect(
                url_for("account.edit",
                        prev_reseller=account.reseller.name,
                        prev_product=account.product.name))
        if request.form["submit"] == "save_and_edit":
            return redirect(url_for("account.edit", id=account.id))
        return redirect(url_for("main.accounts", id=account.id))
    else:
        flash("Form validation error", "danger")
        log(log.ERROR, "Form validation error")
    return redirect(url_for("account.edit", id=form.id.data))
コード例 #24
0
ファイル: main.py プロジェクト: kmvdj23/HR-System
def settings_page():
    form = AccountForm()
    return render_template('pages/settings.html', form=form)
コード例 #25
0
def link_account():

    form = AccountForm()

    if form.validate_on_submit():

        # validate third party credentials
        api_url = app.config['THIRD_PARTY_API_URL'][form.institution.data]
        login = form.login.data
        pwd = form.password.data

        try:
            response = get_thirdparty_credentials(api_url, login, pwd)
        except:
            institution = form.institution.data
            flash("Couldn't connect to third-party-api (institution = {})".
                  format(institution))
            return render_template(
                'account.html',
                form=form,
                institutions=["abc_bank", "xyz_bank", "xyz_trade"])

        if response.status_code == 400 or response.status_code == 401:
            flash("Invalid login or password.")
            return render_template(
                'account.html',
                form=form,
                institutions=["abc_bank", "xyz_bank", "xyz_trade"])

        # get third party account info
        api_url = app.config['THIRD_PARTY_API_URL'][form.institution.data]
        account_login, account_password_hash = response.json().values()
        account_resp = get_thirdparty_accountinfo(api_url, account_login,
                                                  account_password_hash)

        # get third party transactions
        api_url = app.config['THIRD_PARTY_API_URL'][form.institution.data]
        transactions_resp = get_thirdparty_transactions(
            api_url,
            account_resp.json().get("id"))

        # add account record
        account = Account(created_at=datetime.now(),
                          last_update=datetime.now(),
                          account_institution=form.institution.data,
                          account_name=form.account_name.data,
                          account_url=app.config['THIRD_PARTY_API_URL'][
                              form.institution.data],
                          account_login=account_login,
                          account_password_hash=account_password_hash,
                          account_balance=account_resp.json().get("balance"),
                          third_party_id=account_resp.json().get("id"),
                          user_id=current_user.id)
        db.session.add(account)
        db.session.commit()

        # add transaction records (multiple)
        for transaction_resp in transactions_resp.json().get("json_list"):
            date_fmt = "%a, %d %b %Y %H:%M:%S %Z"
            transaction_date = datetime.strptime(transaction_resp.get("date"),
                                                 date_fmt)
            transaction = Transaction(
                transaction_date=transaction_date,
                transaction_seller=transaction_resp.get("seller"),
                transaction_amount=transaction_resp.get("amount"),
                category=determine_category(transaction_resp.get("seller")),
                customized=False,
                third_party_id=transaction_resp.get("id"),
                user_id=current_user.id,
                account_id=account.id)
            db.session.add(transaction)
        db.session.commit()

        flash('Congratulations, you have successfully linked your account!')

        return redirect(url_for('overview'))

    return render_template('account.html',
                           form=form,
                           institutions=["abc_bank", "xyz_bank", "xyz_trade"])
コード例 #26
0
def profile(action):
    form = AccountForm(obj=current_user)
    return render_template('/divs/div-profile.html', action=action, form=form)