Esempio n. 1
0
    def post(self, request, client, client_id):
        data = json.loads(request.body.decode('utf-8'))

        account_data = {}
        account_data['login'] = data.pop('login')
        account_data['password'] = data.pop('password')
        data.pop('role', None)

        result = BaseAccontsView.user_validator(account_data)
        if result['status'] != 'Success':
            return result

        response = requests.post(settings.DANCERS_SERVICE_BASE_URL +
                                 'dancers/sportsmans/',
                                 headers={
                                     'Authorization': settings.SERVICE_SECRET,
                                     'From': settings.SERVICE_ID,
                                     'To': 'Dancers'
                                 },
                                 json=data)

        if response.status_code != 200:
            return {
                'status': 'Failed',
                'message': 'Service Error',
                'code': 500
            }

        print(response.json())
        account_data['uuid'] = response.json()['data']
        account_data['password'] = BaseView.hash_password(
            account_data['password'])
        response = Users.objects.create(**account_data).pk
        BaseView.log(user_auth_log, request, client, client_id)
        return {'status': 'Success', 'data': response, 'code': 200}
 def post(self, request, client, client_id):
     # TODO отправка данных на сервис танцоров
     data = json.loads(request.body.decode('utf-8'))
     data['service_secret'] = BaseView.hash_password(data['service_secret'])
     response = Services.objects.create(**data).pk
     BaseView.log(service_log, request, client, client_id)
     return {'status': 'Success', 'data': response, 'code': 200}
Esempio n. 3
0
 def authentication(self, data):
     user = Users.objects.filter(login=data['login'])
     if not user or BaseView.hash_password(
             data['password']) != user[0].password:
         return {
             'status': 'Failed',
             'message': 'Invalid credentials',
             'code': 400
         }
     tokens = BaseView.get_tokens(access_token_size,
                                  refresh_token_size,
                                  access_token_ttl,
                                  refresh_token_ttl,
                                  uuid=user[0].uuid,
                                  role=user[0].role,
                                  type='User')
     return {'status': 'Success', 'data': tokens, 'code': 200}
 def authentication(self, data):
     service = Services.objects.filter(service_id=data['service_id'])
     if not service or BaseView.hash_password(
             data['service_secret']) != service[0].service_secret:
         return {
             'status': 'Failed',
             'message': 'Invalid credentials',
             'code': 400
         }
     tokens = BaseView.get_tokens(access_token_size,
                                  refresh_token_size,
                                  access_token_ttl,
                                  refresh_token_ttl,
                                  from_service=service[0].service_id,
                                  to_service=data['service'],
                                  type='Service')
     return {'status': 'Success', 'data': tokens, 'code': 200}