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) -> json_response: response = {} data = await self.request.json() chat = Chat(pk=data.get('id')) if self.request.app['db']: chat.db = self.request.app['db'] try: chat_is = await chat.get() if not chat_is: raise ObjectNotFound else: if not chat_is.get('author') == self.request.client.get('_id'): raise NotPermissions else: response = { 'status': True, } except (Exception, ) as error: response = {'status': False, 'error': "{}".format(error)} finally: 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)
async def post(self): data = await self.request.json() try: client = Client( pk=ObjectId(data.get('id')) ) if self.request.app['db']: client.db = self.request.app['db'] if await client.get(): await client.delete() response = { 'status': True } else: response = { 'status': False, 'error': 'client not found' } except(Exception,) as error: response = { 'status': False, 'error': "{}".format(error) } 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, "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)
async def get(self) -> json_response: chat = Chat() if self.request.app['db']: chat.db = self.request.app['db'] response = {'status': True, 'chats-list': await chat.list} return json_response(response)
async def wrapper(request, *args, **kwargs): token_in_header = request._request.__dict__.get('headers').get('AUTHORIZATION', None) if token_in_header: token = Token() try: token_is = await token.objects.find_one({ 'token': token_in_header }) try: if not token_is: raise TokenIsNotFound else: client = Client( pk=token_is.get('client') ) request._request.client = await client.get() if not client: raise ClientNotFoundViaToken return await func(request, *args, **kwargs) except(Exception,) as error: access_logger.error("%s" % error) return json_response({ 'status': False, 'error': 'token not correct' }) except(Exception,) as error: access_logger.error("%s" % error) return json_response({ 'status': False, 'error': '%s' % error })
async def post(self) -> json_response: assert self.request.client is not None chat = Chat(author=self.request.client.get('_id')) if self.request.app['db']: chat.db = self.request.app['db'] response = {'status': True, 'chat': "{}".format(await chat.save())} return json_response(response)
async def get(self): chat = Chat() response = { 'status': True, 'chats-list': await chat.list } return json_response( response )
async def post(self): chat = Chat( author=self.request.client.get('_id') ) response = { 'status': True, 'chat': "{}".format(await chat.save()) } return json_response( response )
async def get(self): client_obj = Client(pk=ObjectId(self.request.match_info.get('id'))) if self.request.app['db']: client_obj.db = self.request.app['db'] client = await client_obj.get() result = { 'id': "{}".format(client.get('_id')), 'email': "{}".format(client.get('email')), } return json_response(result)
async def get(self): client_obj = Client( pk=ObjectId(self.request.match_info.get('id')) ) if self.request.app['db']: client_obj.db = self.request.app['db'] client = await client_obj.get() result = { 'id': "{}".format(client.get('_id')), 'email': "{}".format(client.get('email')), } return json_response(result)
async def post(self): data = await self.request.json() try: client = Client(pk=ObjectId(data.get('id'))) if self.request.app['db']: client.db = self.request.app['db'] if await client.get(): await client.delete() response = {'status': True} else: response = {'status': False, 'error': 'client not found'} except (Exception, ) as error: response = {'status': False, 'error': "{}".format(error)} return json_response(response)
async def get(self) -> json_response: chat = Chat(pk=self.request.match_info.get('id')) if self.request.app['db']: chat.db = self.request.app['db'] chat_info = await chat.get() if chat_info: response = { 'status': True, 'chat-uid': "{}".format(chat.pk), 'client-list': await chat.list_clients, 'author': "{}".format(chat_info.get('author')) } else: response = {'status': False, 'error': 'chat not found'} access_logger.log("%s" % response) return json_response(response)
async def get(self): chat = Chat( pk=self.request.match_info.get('id') ) chat_info = await chat.get() if chat_info: response = { 'status': True, 'chat-uid': "{}".format(chat.pk), 'client-list': await chat.list_clients, 'author': "{}".format(chat_info.get('author')) } else: response = { 'status': False, 'error': 'chat not found' } access_logger.log("%s" % response) return json_response( response )