コード例 #1
0
    def on_push_button_start_released(self):
        self.push_button_test.setEnabled(False)
        self.push_button_start.setEnabled(False)

        url = parse_url(self.line_edit_server_address.text())

        account = Account()
        account.assign_autogenerated_id()
        account.description = ''
        account.account_root_directory = account.id
        account.oxnote_home_folder = Configuration().get_setting(
            'drive_client',
            'api.defaults.oxnote_home_folder.name',
            default='.oxnote')
        account.application_data_folder = Configuration().get_setting(
            'drive_client',
            'api.defaults.application_data_folder.name',
            default='.oxnote')
        account.url_scheme = url.scheme if url.scheme and url.scheme in (
            'http', 'https') else 'https'
        account.url_host = url.host if url.host else None
        account.url_port = url.port if url.port else None
        account.url_uri = url.request_uri if url.request_uri and url.request_uri != '/' else '/ajax/'
        account.username = self.line_edit_username.text()
        account.password = self.line_edit_password.text()
        account.context_id = ''
        account.user_id = ''
        account.enabled = True
        account.drive_quota = -1

        AccountManager().save_account_configuration(account)

        self.close()
        self._oxnote_main_window_widget = MainWindow()
        self._oxnote_main_window_widget.show()
コード例 #2
0
    def run(self, name, backend):

        # Validate the parameters
        form = AddAccountForm(name=name, backend=backend)
        if not form.validate():
            self.err(**form.errors)
            return

        # Ask the user for the backend configuration options
        backend = Backend.get_backend(backend)
        config = {'backend': form.data['backend']}
        for field in backend.config_form():
            self.out((field.label.text, 'blue'))
            value = input('> ').strip()
            if value:
                config[field.name] = value

        # Validate the users configuration
        result = backend.validate_config(**config)
        if not result[0]:
            self.err('Invalid backend config:', **result[1])
            return

        # Create the new account
        account = Account(name=form.data['name'], backend=config)
        account.insert()

        self.out(('Account added: {0}'.format(account.api_key), 'bold_green'))
コード例 #3
0
def new_user():
    data = request.get_json()
    user_key = Account.random_api_key()
    hashed_password = Account.hash_password(data.get('password'))
    new_account = Account(data.get('firstname'), data.get('lastname'),
                          data.get('username'), data.get('email'),
                          hashed_password, user_key)
    new_account._insert()
    return jsonify({
        'session_id': new_account.user_key,
        'firstname': new_account.firstname,
        'lastname': new_account.lastname,
        'username': new_account.username
    })
コード例 #4
0
def test_local_account(app):
    """Create a local account"""

    # Add the local account
    with open('tests/data/local.cfg') as f:
        config = json.load(f)

    account = Account(name='local', backend=config)
    account.insert()

    yield account

    # Purge the account
    account.purge()
コード例 #5
0
ファイル: app.py プロジェクト: luuthi/bank-demo
def addnew():
    current_username = get_jwt_identity()
    if isadmin(current_username):
        if request.method == 'POST':
            data = request.json
            acc = Account(data['account_number'], data['firstname'],
                          data['lastname'], data['gender'], data['age'],
                          data['email'], data['city'], data['address'],
                          data['state'], data['employer'], data['balance'])
            accTbl = db.accounts
            result = accTbl.insert(acc.tojson())
            if result.inserted_id:
                return jsonify({'msg': 'insert successed'}), 201
            else:
                return jsonify({'msg': 'insert failed'}), 400
    else:
        return jsonify({"msg": 'Access permission denied'}), 400
コード例 #6
0
ファイル: app.py プロジェクト: luuthi/bank-demo
def update(id):
    current_username = get_jwt_identity()
    if isadmin(current_username):
        if request.method == 'PUT':
            data = request.json
            acc = Account(data['account_number'], data['firstname'],
                          data['lastname'], data['gender'], data['age'],
                          data['email'], data['city'], data['address'],
                          data['state'], data['employer'], data['balance'])
            accTbl = db.accounts
            result = accTbl.update_one({"account_number": int(id)},
                                       {"$set": acc.tojson()})
            if result.matched_count == 1:
                return jsonify({'msg': 'update successed'}), 201
            else:
                return jsonify({'msg': 'update failed'}), 400
    else:
        return jsonify({"msg": 'Access permission denied'}), 400
コード例 #7
0
def test_backends(app):
    """Create accounts to support each backend"""

    # Add the test accounts for each backend
    accounts = []
    for backend in ['local', 's3']:

        with open('tests/data/{backend}.cfg'.format(backend=backend)) as f:
            config = json.load(f)

        account = Account(name=backend, backend=config)
        account.insert()
        accounts.append(account)

    yield accounts

    # Purge the accounts
    for account in accounts:
        account.purge()
コード例 #8
0
ファイル: app.py プロジェクト: luuthi/bank-demo
def getall():
    acctbl = db.accounts
    data = acctbl.find()
    if data:
        rs = []
        for i in data:
            acc = Account(i['account_number'], i['firstname'], i['lastname'],
                          i['gender'], i['age'], i['email'], i['city'],
                          i['address'], i['state'], i['employer'],
                          i['balance'])
            rs.append(acc)
        return jsonify({
            "data": [x.tojson() for x in rs],
            "size": len(rs),
            "msg": 'get data successed'
        }), 200
    else:
        return jsonify({
            "data": None,
            "size": 0,
            "msg": 'get data failed'
        }), 404
コード例 #9
0
def test_accounts(app):
    """Load test accounts"""

    # Load the test account information
    with open('tests/data/accounts.json') as f:
        data = json.load(f)

    # Add the test accounts
    accounts = []
    for account_data in data:

        with open('tests/data/' + account_data['config_filepath']) as f:
            config = json.load(f)

        account = Account(name=account_data['name'], backend=config)
        account.insert()
        accounts.append(account)

    yield accounts

    # Purge the accounts
    for account in accounts:
        account.purge()