Exemple #1
0
def add_account(message):
    user = models.User.query.filter_by(telegram_chat_id=message.chat.id).first()
    if user is None:
        return False

    try:
        server_name, username, password = message.text.split()[1:]
        server_url = 'http://' + server_name

    except ValueError:
        bot.send_message(message.chat.id, 'Usage: `/add_account <server (e.g. ts1.travian.net)> <username> <password>`')
        return False

    account = models.Account.query.filter_by(server_url=server_url, username=username).first()
    if account is not None:
        bot.send_message(message.chat.id, 'Account already added')
        return False

    account = models.Account(server_url=server_url, username=username, password=password, user_id=user.id)

    if account.login():
        bot.send_message(message.chat.id, 'Successfully added your account')
        db.session.add(account)
        db.session.commit()

        travian.travian_threads.append(travian.Travian(account.id))
        travian.travian_threads[-1].start()

    else:
        bot.send_message(message.chat.id, 'Could not login into your account, probably incorrect data provided')
Exemple #2
0
def add_account():
    r = request.get_json()
    a = models.Account(name=r['name'], balance=config.OPENING_BALANCE)
    db.session.add(a)
    db.session.commit()
    return make_response(
        jsonify({"response": {
            'name': a.name,
            'balance': a.balance
        }}), 200)
Exemple #3
0
def addAccount(surname, firstname, username, password):
    from app import db, models

    newPassword = hashPassword(password)
    account = models.Account(surname=surname,
                             username=username,
                             firstname=firstname,
                             password=newPassword,
                             account_type=3)
    db.session.add(account)
    db.session.commit()
Exemple #4
0
def login(username, password):
    user = models.Account(surname="test1",
                          username="******",
                          firstname="test",
                          password="******",
                          account_type=3)
    db.session.add(user)

    for account in models.Account.query.all():
        if account.username == username and account.password == password:
            return True
    return False
Exemple #5
0
def main(args):
    salt = b'MuchSecure'
    bytePassword = bytes(args[2], 'utf-8')
    hashedPassword = hashlib.pbkdf2_hmac('sha256', bytePassword, salt, 100000)
    account = models.Account(surname=args[5],
                             username=args[1],
                             firstname=args[4],
                             password=hashedPassword,
                             account_type=args[3])
    db.session.add(account)
    db.session.commit()

    return 0
Exemple #6
0
def registerAccount(surname, username, firstName,
                    password):  #fails if database does not have surname
    user = models.Account(surname=surname,
                          username=username,
                          firstname=firstName,
                          password=password,
                          account_type=3)
    for account in models.Account.query.all():
        if account.username == username:
            return False
        else:
            db.session.add(user)
            return True
Exemple #7
0
def signup():
    if current_user.is_authenticated:
        logging.error('{} some how managed to access a link to the signup page whilst already logged in.'.format(current_user.username))
        return redirect('/')
    form = SignUpForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        flash('Welcome to Squad Journal, %s'%(form.username.data), 'st')
        a = models.Account(username=form.username.data, email=form.email.data, password=hashed_password, date_created=datetime.datetime.utcnow())
        db.session.add(a)
        db.session.commit()
        return redirect('/login')
    return render_template('signup.html', title='Squad Journal - Sign-Up', form=form)
 def handle(self, *args, **options):
     call_command('makemigrations')
     call_command('migrate')
     call_command('flush', '--noinput')
     print('Deleted Database')
     admin_username = '******'
     admin_password = '******'
     new_admin = User(username=admin_username, is_superuser=True, is_staff=True)
     new_admin.set_password(admin_password)
     new_admin.save()
     admin_account = models.Account(user=new_admin, role='المديرين')
     admin_account.save()
     print('created account // username: admin -- password: admin')
     default_company = models.Company(company_name='Zoom Print')
     default_company.save()
     print('Company named ' + default_company.company_name + ' Created.!')
Exemple #9
0
def add_account():
    form = forms.AddAccountForm()
    if form.validate_on_submit():
        account = models.Account(server_url=form.server_url.data,
                                 username=form.username.data,
                                 password=form.password.data,
                                 user_id=g.user.id)
        db.session.add(account)
        db.session.commit()

        if form.default.data:
            g.user.default_account = account.id
            db.session.commit()

        return redirect(url_for('manage'))

    return render_template('add_account.html', form=form)
Exemple #10
0
destination_session.flush()

# add parent_ids after flushing to prevent foreign key contraint failures
# sqlalchemy.exc.IntegrityError: (pymysql.err.IntegrityError)
# (1452, 'Cannot add or update a child row: a foreign key constraint fails
for category in categories:
    category.parent_id = category_parent_ids.get(category.id)
destination_session.flush()

accounts = []
for account in source_session.query(m.Account):
    accounts.append(
        m.Account(
            id=account.id,
            name=account.name,
            user_id=account.user_id,
            starting_balance=account.starting_balance,
            category_id=account.category_id,
            properties=account.properties,
        ))
destination_session.add_all(accounts)
destination_session.flush()

paychecks = []
for paycheck in source_session.query(m.Paycheck):
    paychecks.append(
        m.Paycheck(
            id=paycheck.id,
            date=paycheck.date,
            company_name=paycheck.company_name,
            gross_pay=paycheck.gross_pay,
            federal_income_tax=paycheck.federal_income_tax,
Exemple #11
0
#!/usr/bin/python3

from app import models
from app.db import SessionLocal, engine

db = SessionLocal()
models.Base.metadata.create_all(bind=engine)

account_record = models.Account(accountname='Transaktionskonto Bank',
                                accountnumber=1910)
db.add(account_record)
account_record = models.Account(accountname='Utgående MOMS 25%',
                                accountnumber=2611)
db.add(account_record)
account_record = models.Account(accountname='Debiterad ingående MOMS',
                                accountnumber=2641)
db.add(account_record)
account_record = models.Account(accountname='Försäljning datorer',
                                accountnumber=3010)
db.add(account_record)
account_record = models.Account(accountname='inköp komponenter',
                                accountnumber=4010)
db.add(account_record)
db.commit()

account_record = db.query(models.Account).filter_by(accountnumber=1910).all()

db.close()
Exemple #12
0
    DEBUG = False
    app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URI')
    app.config['UPLOAD_FOLDER'] = os.environ.get('UPLOAD_FOLDER')
    app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY')
db = SQLAlchemy(app)

login_manager = LoginManager()
login_manager.init_app(app)

from app import views  # nopep8
from app import models  # nopep8

db.create_all()

# Adds one test object to the database
try:
    userOne = models.Account("*****@*****.**", "verysolidpassword")
    userTwo = models.Account("*****@*****.**", "verysolidpassword")
    db.session.add(userOne)
    db.session.add(userTwo)
    db.session.commit()
    db.engine.dispose()
    home = models.Folder("home", userTwo.email, userTwo.id)
    userTwo.folders.append(home)
    db.session.add(home)
    db.session.commit()
    db.engine.dispose()
except Exception:
    db.session.rollback()
    db.engine.dispose()