Ejemplo n.º 1
0
def create_account():
    if session.get('userId') and session.get('roleId')=="1111":
        form = Create_Account_Form()
        if(request.method=='POST'):
            if form.validate_on_submit():
                ws_cust_id=form.ws_cust_id.data
                ws_acc_id=generate_Account_Id()
                ws_acct_type=form.ws_acct_type.data
                ws_acct_balance=form.ws_acct_balance.data
                status='Active'
                x = datetime.now()
                d=x.strftime("%x")
                y = datetime.now()
                t=y.strftime("%X")
                dt = d + " " + t 
                print("##############"+dt+"##############")  
                ws_acct_lastUdate =datetime.strptime(dt,'%m/%d/%y %H:%M:%S')  
                message='customer created successfully'
                Account(ws_cust_id=ws_cust_id,ws_acct_id=ws_acc_id,ws_acct_type=ws_acct_type,ws_acct_balance=ws_acct_balance,ws_acct_crdate=date.today()).save()
                Account_Status(ws_cust_id=ws_cust_id,ws_acct_id=ws_acc_id,ws_acct_type=ws_acct_type,ws_acct_status=status,ws_message=message,ws_acct_lastUdate=ws_acct_lastUdate).save()
                flash('Thank  for creating account.we will get  back to you soon', 'success')
                return redirect(url_for('create_account'))
            
        
        return render_template('create_account.html',form=form)
    else:
        flash("Sorry You are not authorised to access this page","danger")
        return redirect("/")
Ejemplo n.º 2
0
def create_account():
    if request.method == "POST":
        customer_id = request.form["customerId"]
        check_cusid = Customer.objects(customer_id=customer_id).first()
        account_id = str(
            int(Account.objects.order_by('-customer_id').first().account_id) +
            2)
        account_type = request.form["account_type"]
        check_type = Account.objects(customer_id=customer_id,
                                     account_type=account_type).first()
        deposit_amount = request.form["depositAmount"]
        if (not check_cusid):
            message = "Customer Id doesnot Exist"
        elif (check_type):
            message = "Customer already has account of specific type"
            account = Account.objects(customer_id=customer_id,
                                      account_type=account_type).first()
            account.account_status = message
            account.save()

        else:
            message = "Account Created Successfully"
            account = Account(customer_id=customer_id,
                              account_id=account_id,
                              account_type=account_type,
                              deposit_amount=deposit_amount,
                              account_status=message).save()
        return render_template("create_account.html", message=message)
    return render_template("create_account.html")
Ejemplo n.º 3
0
def create_account():
    data = request.get_json()
    account = Account(**data)
    if Account.find_account(data['username']) is not None:
        abort(400, f"Username '{data['username']}' is already taken")
    elif Account.find_account(data['email']) is not None:
        abort(400, f"Email '{data['email']}' is already taken")

    try:
        return account.save().to_dict()
    except Exception as e:
        current_app.logger.error(e)
        abort(400, "could not create account")
Ejemplo n.º 4
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('core.index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = Account(email=form.email.data,
                       login=form.login.data,
                       password=form.password.data)
        data_login = user.login
        data_email = user.email
        data_password = user.password
        db.engine.execute(
            "INSERT INTO accounts(login, email, password) VALUES(%s, %s, %s)",
            data_login, data_email, data_password)
        db.session.commit()
        flash('Thanks for registering! Now you can login!')
        return redirect(url_for('users.login'))
    return render_template('register.html', form=form)
Ejemplo n.º 5
0
def create_account():
    if session.get('ROLE') != "acc_exec":
        flash("Action Not Allowed", category="danger")
        return redirect('main.home')
    else:
        form = AccountDetailsForm()
        form.acc_no.data = Account.generate_acc_no()
        if form.validate_on_submit():
            account = Account(acc_no=form.acc_no.data,
                              acc_balance=form.acc_balance.data,
                              acc_type=form.acc_type.data,
                              cust_id=form.cust_id.data)
            db.session.add(account)
            db.session.commit()
            flash("Account Successfully Created!!!", category="success")
            return redirect(url_for('main.home'))
        return render_template("accounts/create_account.html",
                               form=form,
                               title="Create Account")
Ejemplo n.º 6
0
def create_account():
    if not session.get('user_id'):
        return redirect(url_for('login'))
    if request.method == 'POST':
        ws_cust_id = request.form['ws_cust_id']
        ws_acct_id = get_random_alphaNumeric_string(9)
        ws_acct_type = request.form['ws_acct_type']
        ws_acct_balance = int(request.form['ws_acct_balance'])
        if ws_acct_balance <= 0:
            flash("Account creation Failed due to negative amount!", "danger")
            return redirect(url_for('create_account'))
        ws_acct_crdate = datetime.now()
        ws_acct_lasttrdate = datetime.now()
        ws_acct_duration = 0
        ws_status = 'CREATED'
        account = Account.objects(ws_cust_id=ws_cust_id,
                                  ws_acct_type=ws_acct_type)
        if account:
            flash(
                "Current User already have this type of account please try other",
                "danger")
            return redirect(url_for('create_account'))
        account = Account(ws_cust_id=ws_cust_id,
                          ws_acct_id=ws_acct_id,
                          ws_acct_type=ws_acct_type,
                          ws_acct_balance=ws_acct_balance,
                          ws_acct_crdate=ws_acct_crdate,
                          ws_message='CREATED',
                          ws_acct_lasttrdate=ws_acct_lasttrdate,
                          ws_acct_duration=ws_acct_duration,
                          ws_status=ws_status)
        account.save()
        transactions = Transactions(
            ws_tnsc_id=get_random_alphaNumeric_string(8),
            ws_acct_id=ws_acct_id,
            ws_desc='Deposit',
            ws_amt=ws_acct_balance,
            ws_trxn_date=datetime.now())
        transactions.save()
        flash("Account creation initiated successfully!", "success")
        return redirect('/accounts/' + ws_acct_id)
    return render_template("account_management/create_account.html")
Ejemplo n.º 7
0
def create_account():

        if not session.get('username'):
          return redirect(url_for('login'))
        if request.method == "POST":
    
            customer_id = request.form["CustomerId"]
            account_id = request.form['AccountId']
            account_type    = request.form["Account"]
            deposit_amount  = request.form["DepositAmount"]
            temp = User.objects(customer_ssn_id=customer_id)
            if temp:
                account = Account(account_id=account_id,customer_ssn_id=customer_id, account_type=account_type, deposit_amount= deposit_amount)
                account.save()
                flash("You are successfully registered!","success")
                return redirect(url_for('index'))
            else:
                flash("Oops!!No such customer exist!!Register first","danger")
                return redirect(url_for('register'))
                
        return render_template("acccountcreate.html")
Ejemplo n.º 8
0
def create_account():
    if not session.get('username'):
        return redirect(url_for('login'))
    form = AccountForm()

    customer_Id = form.customerId.data
    account_type = form.account_type.data
    deposit = form.deposit.data
    customer = Customer()

    if customer_Id:
        classess = list(
            Customer.objects.aggregate(*[{
                '$lookup': {
                    'from': 'account',
                    'localField': 'customerId',
                    'foreignField': 'customerId',
                    'as': 'r1'
                }
            }, {
                '$match': {
                    'customerId': customer_Id
                }
            }]))
        print(classess)
        if classess:
            acc = Account(customerId=customer_Id,
                          account_type=account_type,
                          deposit=deposit)
            acc.save()
            flash("Account created", 'success')
            return redirect(url_for('create_account'))
        else:
            flash("account not found")

    return render_template("create_account.html",
                           title="Create Account",
                           account_management=True,
                           form=form)
Ejemplo n.º 9
0
def register():
    try:
        form = AccountRegistration()

        if request.method == 'GET':
            return render_template('register_account.html', form=form)

        req_body = request.form

        identity_dict = {
            key: value
            for key, value in req_body.iteritems()
            if key in Identity.__table__._columns
        }
        identity = Identity(**identity_dict).insert()

        db.session.flush()

        account_dict = {
            key: value
            for key, value in req_body.iteritems()
            if key in Account.__table__._columns
        }
        account_dict['identity_id'] = identity.id
        account_dict.update(identity_id=identity.id, category='user')
        account = Account(**account_dict)
        account.hash_password()
        account.insert()

        db.session.commit()

        return 'Registered successfully'

    except SQLAlchemyError as error:
        db.session.rollback()
        abort(400, str(error))
Ejemplo n.º 10
0
def test_create_with_invalid_values_raises_exceptions(db_session, username,
                                                      password, email, exc):
    with pytest.raises(exc):
        Account(username, password, email).save()
Ejemplo n.º 11
0
import pytest
from sqlalchemy.exc import IntegrityError

from application.models import Account, Package, PackageLock

user1 = Account("test_user1", "password", "*****@*****.**")
user2 = Account("test_user2", "password", "*****@*****.**")
pkg1 = Package("package1", False, False)
pkg2 = Package("package2", False, True)


def test_create_account(db_session):
    user1.save()
    user2.save()

    assert user1.to_dict() == {
        "username": user1.username,
        "email": user1.email
    }
    assert user2.to_dict() == {
        "username": user2.username,
        "email": user2.email
    }


@pytest.mark.parametrize("username, password, email, exc", [
    ("test_user1", "password", "*****@*****.**", IntegrityError),
    ("test_user3", "password", "*****@*****.**", IntegrityError),
    ("", "password", "*****@*****.**", ValueError),
    ("test_user3", "", "*****@*****.**", ValueError),
    ("test_user3", "password", "", ValueError),
Ejemplo n.º 12
0
from application import db, bcrypt
from application.models import Customer, Account
import random as rd

accountnumber = rd.randint(10000000, 11111111)

customers = Customer.query.all()
for customer in customers:
    account1 = Account(acc_no=accountnumber + 1,
                       acc_balance=float(rd.randint(1000, 10000)),
                       acc_type='S',
                       cust_id=customer.cust_id)
    accountnumber += 1
    print(account1)
    db.session.add(account1)
    db.session.commit()
    account2 = Account(acc_no=accountnumber + 1,
                       acc_balance=float(rd.randint(1000, 10000)),
                       acc_type='C',
                       cust_id=customer.cust_id)
    accountnumber += 1
    print(account2)
    db.session.add(account2)
    db.session.commit()

accounts = Account.query.all()
for account in accounts:
    print(account)
Ejemplo n.º 13
0
from application import app, db
from application.models import User, Customer, Account
from flask import render_template, request, Response, flash, redirect
from application.forms import LoginForm
while (Customer.objects.all().count() == 0):
    Customer(ssn_id="111222333444",
             customer_id="900000000",
             customer_name="Subhankar Majumder",
             age="23",
             address="Sodepur",
             state="West Bengal",
             city="Kolkata",
             customer_status="Demo Customer created Successfully").save()
    Account(customer_id="900000000",
            account_id="101011000",
            account_type="Current Account",
            deposit_amount="1000",
            account_status="Demo Account created Successfully").save()


@app.route("/", methods=['POST', 'GET'])
@app.route("/login", methods=['POST', 'GET'])
def login():
    form = LoginForm()
    if form.validate_on_submit():
        id = form.user_id.data
        password = form.password.data
        user = User.objects(user_id=id).first()
        if user and password == user.password and user.work == "executive":
            return redirect("/executive")
        elif user and password == user.password and user.work == "cashier":