예제 #1
0
 def get(self, client_id: str, id: str) -> Account:
     client_ref = self.get_client_ref(client_id)
     accounts = client_ref.get().to_dict()['accounts']
     # search in array of accounts
     for account in accounts:
         if account['id'] == id:
             return Account(**account)
예제 #2
0
def login_loop():
    views.login_welcome()
    while True:
        views.display_login_menu()
        choice = views.get_login_choice()
        if int(choice) > 3:
            print("That is not an option!")
        #CREATE AN ACCOUNT																					
        elif int(choice) == 1:																										
            print("-----Create an Account-----")																								
            full_name = input("What is your full name?: ")	
            values = {"full_name":full_name, "pin": views.input_new_pin(), "balance": 0.00}		
            new_account = Account(**values)
            new_account.save()													
            print("Account Created! Your account number is:", new_account.account_number)													
            continue
        #LOGIN TO EXISTING ACCOUNT										
        elif int(choice) == 2:	
            account_num = views.get_login_num()
            pin = views.input_pin()
            if Account.validate(account_num, pin) == True: 
                loaded_account = Account.load_account(account_num, pin)
                print("This is your loaded account: ", loaded_account.account_number)
                return loaded_account
        #EXIT PROGRAM
        elif int(choice) == 3:													
            break															
예제 #3
0
파일: auth.py 프로젝트: venatha/havana
    def signup_post(self):
        if Account.query.filter_by(audit_is_deleted=False, name=request.form['account_name']).first():
            flash('Account name already in use', 'error')
            return self._render('auth/signup.html', 'Register')
        if User.query.filter_by(audit_is_deleted=False, username=request.form['username']).first():
            flash('Username already in use', 'error')
            return self._render('auth/signup.html', 'Register')
        if User.query.filter_by(audit_is_deleted=False, email_address=request.form['email_address']).first():
            flash('Email address already in use', 'error')
            return self._render('auth/signup.html', 'Register')
        if request.form['password'] != request.form['password_confirm']:
            flash('Password and confirmation do not match', 'error')
            return self._render('auth/signup.html', 'Register')

        account = Account(name=request.form['account_name'])
        account.create()

        user = User(username=request.form['username'],
                    email_address=request.form['email_address'],
                    account_id=account.id)
        user.create()

        user.update_password(request.form['password'])

        flash('User created successfully, Please login', 'success')
        return self._render('auth/login.html', 'Login')
예제 #4
0
def add_account():
    username = request.form.get('username')
    email = request.form.get('email')
    password = request.form.get('password')
    repassword = request.form.get('repassword')
    group_ids = request.form.get('group_ids')

    if username is None or username == '' or group_ids is None or group_ids == '[]' or email is None or email == '' or not password or not repassword:
        return u'输入有误,请检查', 502
    username = username.replace(' ', '')
    if username.find('@') != -1:
        return u'用户名不能出现"@",请更换用户名', 502

    if password != repassword:
        return u'密码不匹配,请检查', 502

    if Account.query.filter(Account.username == username).count():
        return u'该用户名已被占用,请更换用户名', 502

    if Account.query.filter(Account.email == email).count():
        return u'该邮箱已被占用,请更换邮箱', 502

    account_item = Account(username=username,
                           email=email,
                           password=password,
                           groups=group_ids.replace('"', ''))
    db.session.add(account_item)
    db.session.commit()
    return 'success'
예제 #5
0
def create_account():
    body = flask_rebar.get_validated_body()

    account = Account(**body)
    db.session.add(account)
    db.session.commit()

    return account, 201
예제 #6
0
def test_account(test_user):
    account = Account(name='test account',
                      balance=123.33,
                      description='random desc',
                      currency=currencies[1],
                      account_type=account_types[0],
                      user=test_user)
    return account
예제 #7
0
    def create(self, account_create: AccountCreate) -> Account:
        data = account_create.dict()
        # create document inside client document
        client_ref = self.get_client_ref(data['client_id'])
        client_ref.update({self.array_name: firestore.ArrayUnion([data])})
        # the object will be the last one created
        account = client_ref.get().to_dict()['accounts'][-1]

        if account['id'] == data['id']:
            return Account(**account)
예제 #8
0
def create_account(db: Session, account: AccountCreate):
    db_account_type = Account(name=account.name,
                              balance=account.balance,
                              account_type_id=account.account_type_id,
                              bank_id=account.bank_id,
                              user_id=account.user_id)
    db.add(db_account_type)
    db.commit()
    db.refresh(db_account_type)
    return db_account_type
예제 #9
0
 def create(self, db: Session, *, obj_in: AccountCreate) -> Account:
     db_obj = Account(
         email=obj_in.email,
         hashed_password=get_password_hash(obj_in.password),
         full_name=obj_in.full_name,
         is_superuser=obj_in.is_superuser,
     )
     db.add(db_obj)
     db.commit()
     db.refresh(db_obj)
     return db_obj
    def post(self):
        account = Account(account_id=request.json['account_id'],
                          status=request.json['status'],
                          balance=request.json['balance'])
        db.session.add(account)
        db.session.commit()

        output = {
            'message': 'Account Created',
            'resource_id': account.account_id,
            'status': 200
        }

        return output
예제 #11
0
def create_account(
    db_session: Session,
    first_name: str,
    last_name: str,
    email: str,
    password: str,
    is_system_admin: bool = False,
    is_active: bool = False,
    send_registration_email: bool = True,
    is_verified: bool = False,
):
    """Create an user account."""
    account_obj = Account(
        first_name=first_name,
        last_name=last_name,
        is_system_admin=is_system_admin,
        is_active=is_active,
    )
    db_session.add(account_obj)
    db_session.flush()

    email_obj = EmailAddress(account_id=account_obj.id,
                             email=email,
                             primary=True,
                             verified=is_verified)

    password_obj = Password(account_id=account_obj.id, password=password)

    db_session.add(email_obj)
    db_session.add(password_obj)
    db_session.commit()

    # Send registration email.
    if send_registration_email:
        token = create_token_from_id(email_obj.id)
        registration_link = "{}/{}/verify?token={}".format(
            FRONTEND_BASE_URL, email_obj.id, token)
        send_email(
            to_email=email,
            subject="Welcome!",
            body="""Weclome to the website. 
            <p />Please use the following link to continue your registration. 
            <p /><a href="{}">{}</a>
            """.format(registration_link, registration_link),
        )

    db_session.refresh(account_obj)

    return account_obj
예제 #12
0
def create_account(*, username: str, password: str, email: str,
                   account_type: str) -> Account:
    """
    Create user account if not exist. Return Account object on success, None on failure.
    """
    username_format_check(username)
    password_format_check(password)
    account_type_check(account_type)
    account = Account.objects.filter(username=username).first()
    if account:
        return None
    account = Account(username=username,
                      password=hashed_password(password),
                      account_type=account_type)
    account.save()
    create_email(email=email, account=account)
    return account
예제 #13
0
    def import_row(self, row, which):
        if which == self.ACCOUNTS:
            account = Account(
                account_id=row[1],  # Acct Id
                company_name=row[2],  # Account Name
                person_name=None,  # only from Divisions
                phone_number=row[3],
                address=("%s, %s, %s, %s, %s, %s" %
                         (row[8], row[9], row[10], row[11], row[12], row[13])),
                driver_voucher=self.safe_cast(None, bool),
                special_requirements=row[0]  # Account Notes
            )
            account.put()

        elif which == self.VEHICLE:
            vehicle = Vehicle(vehicle_id=row[0])
            vehicle.put()
예제 #14
0
def accounts():
    accounts = Account.query.filter_by(user=current_user)
    if request.method == 'POST':
        account = Account.query.filter_by(user=current_user,
                                          name=request.form.get('name')).first()
        if account is not None:
            return render_template('accounts.html', error_message=ErrorMessage.ACCOUNT_ALREADY_EXISTS.value,
                                   account_types=account_types, accounts=enumerate(
                                       accounts, start=1),
                                   currencies=currencies, currency_rate_date=get_currency_rate_date())
        account = Account(name=request.form.get('name'), balance=request.form.get('balance'),
                          description=request.form.get('description'), currency=request.form.get('currency'),
                          account_type=request.form.get('account_type'), user=current_user)
        db.session.add(account)
        db.session.commit()
        return redirect(url_for('accounts'))
    return render_template('accounts.html', account_types=account_types, accounts=enumerate(accounts, start=1),
                           currencies=currencies, currency_rate_date=get_currency_rate_date())
예제 #15
0
파일: commands.py 프로젝트: venatha/havana
def seed_db():
    acct = Account.query.filter_by(name='Internal').first()
    if acct:
        print('DB contents already exist, Cannot seed again')
        quit(1)

    accounts = [
        {'name': 'Internal', 'is_suspended': False},
    ]

    # Internal Users
    internal_users = [
        {'username': '******', 'email_address': '*****@*****.**', 'is_admin': True},
        {'username': '******', 'email_address': '*****@*****.**', 'is_admin': True},
        {'username': '******', 'email_address': '*****@*****.**', 'is_admin': True}
    ]

    # Reserved Users
    for i in range(1, 10):
        internal_users.append({
            'username': '******'.format(i),
            'email_address': 'Reserved {0}'.format(i),
            'is_admin': False
        })

    # Add the accounts
    for item in accounts:
        account = Account()
        for key, value in item.items():
            setattr(account, key, value)
        db.session.add(account)
    db.session.commit()

    internal_account = Account.query.filter_by(name='Internal').first()
    for item in internal_users:
        item['account_id'] = internal_account.id
        user = User()
        for key, value in item.items():
            setattr(user, key, value)
        db.session.add(user)
    db.session.commit()

    print('DB seeded successfully')
    return
예제 #16
0
def create_account(*, username: str, password: str, email: str,
                   account_type: str) -> Account:
    """
    Create user account if not exist. Return Account object on success, None on failure.
    """
    username_format_check(username)
    password_format_check(password)
    account_type_check(account_type)
    account = Account.objects.filter(username=username).first()
    if account:
        user_existed = True
        return user_existed, {
            'access_token': '',
            'account': {
                'id': 0,
                'username': '',
                'account_type': '',
            }
        }
    else:
        user_existed = False
        account = Account(username=username,
                          password=hashed_password(password),
                          account_type=account_type)
        account.save()
        create_email(email=email, account=account)

        account = Account.objects.filter(
            username=username, password=hashed_password(password)).first()
        access_token = generate_access_token(account)
        return user_existed, {
            'access_token': access_token,
            'account': {
                'id': account.id,
                'username': account.username,
                'account_type': account.account_type,
            }
        }
예제 #17
0
파일: accounts.py 프로젝트: jhladky/hmint
def new():
    account = Account(request.get_json(force=True))
    db.session.add(account)
    db.session.commit()
    return jsonify(success=True, account_id=account.id)
예제 #18
0
# coding=utf-8
from cookielib import LWPCookieJar

import requests.utils
import requests

from app.models.account import Account
from app.settings import COOKIE_FILENAME

user = Account('*****@*****.**', 'wrx0831')


def auth():
    tmp = requests.utils.dict_from_cookiejar(user.cookies)
    session = requests.Session()
    cookie = LWPCookieJar()
    cookie.load(filename=COOKIE_FILENAME)
    print type(cookie), cookie
    session.cookies = cookie
    s = session.post('https://www.leetcode.com/dream_going')
    print s.status_code


if __name__ == '__main__':
    user.login()
    print user.is_login
    print user.username
    tmp = requests.utils.dict_from_cookiejar(user.cookies)
    print tmp
    auth()
예제 #19
0
 def list(self, client_id: str) -> List[Account]:
     client_ref = self.get_client_ref(client_id)
     accounts = client_ref.get().to_dict()['accounts']
     return [Account(**account) for account in accounts]