class TempDB: clients = { 1: Client(client_id=1, name="danny", email="*****@*****.**", password="******"), 2: Client(client_id=2, name="maddy", email="*****@*****.**", password="******"), 3: Client(client_id=3, name="daniel", email="*****@*****.**", password="******") }
class DbLayer: client = { 1: Client(client_id=1, username="******", password="******", firstname="John", lastname="Doe"), 2: Client(client_id=2, username="******", password="******", firstname="Julia", lastname="Smith"), 3: Client(client_id=3, username="******", password="******", firstname="Jack", lastname="Walker") }
def get_all_clients_of_user(self, user): client_list = [ Client("ASDFWERVKWNFJWEURHBSDFKU", ClientType.android, ClientStatus.online), Client("LDSFIJWFNSDFUWHEKFOV@#$UHJF", ClientType.pc, ClientStatus.offline) ] return client_list
def create_clients(): client1 = Client(id=12345, name="QFX Movies", description="QFX Movies is a good movie hall with different auditoriums.", screen_list_id=[1, 2]) client2 = Client(id=123456, name="BSR Movies", description="BSR Movies is one of the finest movie hall with dolby sound support.", screen_list_id=[3, 4]) client1.put() client2.put()
def __connect(self): """ Creates a new client and a new connection. """ host = self.txt_host.text() port = self.txt_port.text() serv = self.cbx_servers.currentText() if host != "" or port != "": port = int(port) nserv = int(serv) - 1 try: self.list_client[nserv] = Client(host, port) msg = QMessageBox() msg.setIcon(QMessageBox.Information) msg.setText("Info: Connection established") msg.exec_() except: msg = QMessageBox() msg.setIcon(QMessageBox.Information) msg.setText("Error: Connection couldn't be established") msg.exec_() else: msg = QMessageBox() msg.setIcon(QMessageBox.Information) msg.setText("Error: Please specify host and port") msg.exec_()
async def post(self): data = await self.request.json() client = Client(email=data.get('email'), password=data.get('password')) if self.request.app['db']: client.db = self.request.app['db'] q = {"email": client.client_email, "password": client.password} client_exit = await client.get(**q) if client_exit: client.pk = client_exit.get('_id') response = { 'client_id': "{}".format(client.pk), 'status': True, 'token': "{}".format(await client.token) } else: response = {'status': False, 'error': 'client not found'} return json_response(response)
async def post(self): data = await self.request.json() client = Client(email=data.get('email'), password=data.get('password')) if self.request.app['db']: client.db = self.request.app['db'] q = {'email': client.client_email} search = await client.objects.find_one(q) if not search: try: response = { 'status': True, 'client_id': "{}".format(await client.save()), } except (Exception, ) as error: response = {'status': False, 'error': "{}".format(error)} else: response = {'status': False, 'error': 'client already exist'} return json_response(response)
def get_client(cls, client_id): sql = f" select * from clients where id = {client_id} " cursor = connection.cursor() cursor.execute(sql) records = cursor.fetchall() client = [Client(elem[0], elem[1]) for elem in records] return client
def get_all_clients(cls): sql = "SELECT * FROM clients" cursor = connection.cursor() cursor.execute(sql) records = cursor.fetchall() clients = [Client(elem[0], elem[1]) for elem in records] return clients
def create_client(request): params = json.loads(request.body) client_name = params.get('client_name') scope = params.get('client_scope') redirect_uri = params.get('redirect_uri') grant_type = params.get('grant_type') response_type = params.get('response_type') has_client = Client.select().filter( Client.client_name == client_name).first() if has_client: return JsonResponse({'code': 1, 'msg': '客户端名称已存在,请换个名字试试'}) else: client = Client(client_name=client_name, scope=scope, redirect_uri=redirect_uri, grant_type=grant_type, response_type=response_type, user_id=request.user.id, client_id=gen_salt(24), client_secret=gen_salt(48)) client.save(force_insert=True) return JsonResponse({ 'code': 0, 'msg': '添加客户端成功', 'data': { 'client_id': client.client_id, 'client_secret': client.client_secret, 'scope': client.scope, 'redirect_uri': client.redirect_uri } })
def post(self): """ Create new client. """ parsed_args = parser.parse_args() if not parsed_args["name"]: abort(400, message="Name not provided.") if not parsed_args["surname"]: abort(400, message="Surname not provided.") client = Client( name=parsed_args["name"], surname=parsed_args["surname"], address=parsed_args["address"], city=parsed_args["city"], phone=parsed_args["phone"], user_id=parsed_args["user_id"], birthday=parsed_args["birthday"], ) user = session.query(User).filter( User.id == parsed_args["user_id"]).first() if user is not None: user.client = client client.user = user return self.finalize_post_req(client)
def update(self, *args): try: client: Client = Client() if len(args) is 0: raise Exception('Invalid arguments') if isinstance(args[0], int) or isinstance(int(args[0]), int): client.fill() client.id = args[0] values = client.getValues().split(',') old_values = self.getById(args[0]).getValues().split(',') keys = client.getKeys().split(',') for i in range(len(keys)): if values[i] == 'null': client.__setattr__(keys[i], old_values[i]) if isinstance(args[0], Client): client = args[0] if not client.isFull(): raise Exception('Invalid input') queryStr = '' keys = client.getKeys().split(',') values = client.getValues().split(',') for i in range(len(keys)): queryStr += keys[i] + ' = ' + values[i] + ', ' self.db.cursor.execute( f'Update "Client" Set {queryStr[:-2]} Where id = {client.id}') self.db.connect.commit() return True except Exception as err: print("Update error! ", err) return False
def post(self): json_data = request.get_json() username = json_data.get('username') email = json_data.get('email') non_hash_password = json_data.get('password') if Client.get_by_username(username): return {'message': 'username already used'}, HTTPStatus.BAD_REQUEST if Client.get_by_email(email): return {'message': 'email already used'}, HTTPStatus.BAD_REQUEST password = hash_password(non_hash_password) client = Client(username=username, email=email, password=password) client.save() data = { 'id': client.id, 'username': client.username, 'email': client.email, 'password': client.password } return data, HTTPStatus.OK
def post(self): form = NewClientForm(request.form) if form.validate(): from tasks import send_initial_sms, send_sms_followup client = Client(client_id=form.data['client_id'], name=form.data['name'], phone_number=form.data['phone_number'], delta=form.data['delta'], survey=form.data['survey'], initial_contact=True, time=form.data['time'], timezone=form.data['timezone']) client.time = arrow.get(client.time, client.timezone).to('utc').naive reminders.db.session.add(client) reminders.db.session.flush() reminders.db.session.commit() send_initial_sms(client.id) send_sms_followup.apply_async(args=[client.id], eta=client.get_followup_time()) return redirect(url_for('client.index'), code=303) else: return render_template('clients/new.html', form=form), 400
def read_client(): if user_validate(): clients = [] if request.args.get('name'): rows = persistence.read( 'SELECT * FROM CLIENTS WHERE NAME LIKE "%{}%"'.format( request.args.get('name').strip())) else: rows = persistence.read('SELECT * FROM CLIENTS') for client in rows: clients.append( Client(id=client[0], name=client[1], cpf=client[2], address=client[3], neighborhood=client[4], city=client[5], telephone=client[6], cellphone=client[7])) if not clients: flash('Não foi encontrado nenhum cliente.') flash('warning') return render_template('clients.html', clients=clients) else: return redirect(url_for('login'))
def new_object(self, client, null=None): sql = "INSERT INTO clients VALUES (DEFAULT,%s,%s) RETURNING *" cursor = connection.cursor() cursor.execute(sql, (client.username, client.password)) connection.commit() record = cursor.fetchone() return Client(record[0], record[1], record[2])
def create_client(self, client): sql = "INSERT INTO client VALUES (DEFAULT,%s ,%s) RETURNING *" cursor = connection.cursor() cursor.execute(sql, (client.username, client.accounts)) connection.commit() record = cursor.fetchone() return Client(record[0], record[1])
def update_client(self, change): sql = "UPDATE clients SET client_name=%s WHERE client_id=%s RETURNING * " cursor = connection.cursor() cursor.execute(sql, (change.client_name, change.client_id)) connection.commit() record = cursor.fetchone() return Client(record[0], record[1])
def get_client(id): sql = "Select id, name from clients where id = %s" cursor = connection.cursor() cursor.execute(sql, [id]) record = cursor.fetchone() try: client = Client(id=record[0], name=record[1], accounts=AccountsDAO.get_accounts_by_client(record[0])) return client except TypeError as e: return False
def setUp(self): self.cdao = ClientDAO(DB_PATH) self.client = Client() self.client.address = "TEST 1" self.client.comp_address = "TEST 2" self.client.zipcode = "TEST 3" self.client.id_profile = 1 self.client.name = "TEST 4" self.client.country = "TEST 5" self.client.city = "TEST 6"
def get_client(self, client_id): sql = "SELECT * FROM clients WHERE client_id = %s" cursor = connection.cursor() cursor.execute(sql, [client_id]) record = cursor.fetchone() if record: return Client(record[0], record[1], record[2], record[3]) else: raise UserNotFound(f"Client with id: {client_id} - Not Found")
def create_order(): """ Create a new order by placing products and client --- parameters: - in: header name: authorization required: true schema: type: string - in: query name: shop required: true schema: type: object parameters: id: type: integer - in: query name: total required: true schema: type: integer responses: 200: description: Successfully created the order schema: type: object parameters: message: type: string example: Success """ user = request.user shop = storage.get(User, user).shops[0] in_order = request.get_json() order = Order() order.date = str(datetime.utcnow()) order.description = json.dumps(in_order['shop']) order.total = in_order['total'] order.shop = shop.id order.origin = 'admin' client = storage.get(Client, shop.client) if client: order.client = client.id else: client = Client() client.username = shop.title client.email = storage.get(User, user).username client.phone = shop.phone order.client = client.id client.save() order.save() print() return jsonify(message='Success')
def get_all_clients(): sql = "Select id, name from clients" cursor = connection.cursor() cursor.execute(sql) records = cursor.fetchall() clients = [] for record in records: clients.append(Client(id=record[0], name=record[1], accounts=AccountsDAO.get_accounts_by_client(record[0]))) return clients
def create_client(self, client): sql = "INSERT INTO clients VALUES (DEFAULT,%s,%s,%s) RETURNING *" cursor = connection.cursor() cursor.execute(sql, (client.first_name, client.last_name, client.pin)) connection.commit() rec = cursor.fetchone() new_client = Client(rec[0], rec[1], rec[2], rec[3]).json() return new_client
def update_client(client_id): logging.info(f"Updating client") try: if client_id.isdigit(): client = Client(client_id, Client.json_parse(request.json).name) return ClientServiceImpl.update_client(client) else: raise ValueError except ValueError as e: return "No such client exist", 404
def login(username, password): hash = hash_pass(username, password) cursor.execute(login_query1) cursor.execute(login_query2, (username, str(hash))) user = cursor.fetchone() if (user): return Client(user[0], user[1], user[2], user[3]) else: return False
def create_client(self, client): sql = "INSERT INTO clients VALUES(default, %s, %s) RETURNING *" cursor = connection.cursor() cursor.execute(sql, (client.first_name, client.last_name)) connection.commit() record = cursor.fetchone() new_client = Client(record[0], record[1], record[2]) return new_client
def post(self): client = Client() # client.key=ndb.Key('Client', int(request.form['id'])) client.name = request.form['name'] client.description = request.form['description'] client.screen_list_id = [] res = client.put() if res: return jsonify({'message': "Success", "id": res.id()}) else: return jsonify({'error': 'error message.'})
def create_client(self, client): sql = "INSERT INTO clients VALUES (DEFAULT,%s,%s,%s) RETURNING *" cursor = connection.cursor() cursor.execute(sql, (client.name, client.email, client.password)) connection.commit() record = cursor.fetchone() new_client = Client(record[0], record[1], record[2], record[3]) return new_client
def get_client(self, client_id): sql = "SELECT * FROM clients WHERE client_id = %s" # %s is a placeholder for string cursor = connection.cursor() cursor.execute(sql, [client_id]) record = cursor.fetchone() if record: return Client(record[0], record[1]).json() else: raise ResourceNotFound(f"Client with id: {client_id} - Not Found")