示例#1
0
    def add(request, currency):
        logger = logging.getLogger(__name__)
        correlation_id = get_correlation_id_from_username(request.user)
        logger = setup_logger(request, logger, correlation_id)
        logger.info('========== Start add currency ==========')

        url = settings.DOMAIN_NAMES + api_settings.ADD_CURRENCY_URL.format(
            currency)
        logger.info("Add currency by {} user id".format(request.user.username))
        logger.info("Add currency from backend with {} url".format(url))

        params = {"value": currency}
        logger.info(
            "Add currency from backend with {} request body".format(params))
        start = time.time()
        response = requests.put(url,
                                headers=get_auth_header(request.user),
                                json=params,
                                verify=settings.CERT)
        finish = time.time()
        logger.info('Response_code: {}'.format(response.status_code))
        logger.info('Response_content: {}'.format(response.text))
        logger.info('Response_time: {}'.format(finish - start))

        response_json = response.json()
        status = response_json.get('status', {})
        code = status.get('code', '')

        ajax_code = 0
        message = status.get('message', 'Something went wrong.')
        if code in [
                'access_token_expire', 'authentication_fail',
                'invalid_access_token'
        ]:
            logger.info("{} for {} username".format(message, request.user))
            messages.add_message(
                request, messages.INFO,
                str('Your login credentials have expired. Please login again.')
            )
            ajax_code = 1
            logger.info('========== Finish add currency ==========')
            return JsonResponse({"status": ajax_code, "msg": message})

        currencyList = []
        if status['code'] == "success":
            ajax_code = 2
            logger.info("Currency was added")
            logger.info('========== Finish add currency ==========')
            currencyList = refine_data(response_json['data'])
        else:
            ajax_code = 3
            logger.info('========== Finish add currency ==========')

        return JsonResponse({
            "status": ajax_code,
            "msg": message,
            "data": currencyList
        })
示例#2
0
def cash_sofs(request, user_id):
    logger = logging.getLogger(__name__)
    correlation_id = get_correlation_id_from_username(request.user)
    logger = setup_logger(request, logger, correlation_id)
    url = CASH_SOFS_URL
    params = {'user_id': user_id, 'user_type': 2}

    result = ajax_functions._post_method(request, url, "", logger, params)
    return result
示例#3
0
 def delete_client_by_id(request, client_id):
     if not check_permissions_by_user(request.user, 'CAN_DELETE_CLIENTS'):
         return
     logger = logging.getLogger(__name__)
     correlation_id = get_correlation_id_from_username(request.user)
     logger = setup_logger(request, logger, correlation_id)
     logger.info("========== Start deleting client id ==========")
     url = api_settings.DELETE_CLIENT_URL.format(client_id)
     result = ajax_functions._delete_method(request, url, "", logger)
     logger.info('========== Finish deleting client id ==========')
     return result
示例#4
0
def deactive(request, id):

    logger = logging.getLogger(__name__)
    correlation_id = get_correlation_id_from_username(request.user)
    logger = setup_logger(request, logger, correlation_id)

    logger.info('========== Start deactivating card ==========')
    url = settings.DOMAIN_NAMES + ACTIVATE_CARD_PATH.format(card_id=id)
    params = {'is_stopped': True}
    result = ajax_functions._put_method(request, url, "", logger, params)
    logger.info('========== Finish deactivating card ==========')
    return result
def remove(request, token_id):
    logger = logging.getLogger(__name__)
    correlation_id = get_correlation_id_from_username(request.user)
    logger = setup_logger(request, logger, correlation_id)
    logger.info("Checking permission for [{}] username with [{}] permission".format(request.user, 'CAN_REMOVE_TRUST'))
    if not check_permissions_by_user(request.user, 'CAN_REMOVE_TRUST'):
        return {"status": 1, "msg": ''}
    logger.info('========== Start remove trust token ==========')
    url = settings.DOMAIN_NAMES + api_settings.DELETE_TRUST_TOKEN_API.format(token_id)
    result = ajax_functions._delete_method(request, url, "", logger, {})
    logger.info('========== Finish remove trust token ==========')
    return result
def activate(request, system_user_id):
    logger = logging.getLogger(__name__)
    correlation_id = get_correlation_id_from_username(request.user)
    logger = setup_logger(request, logger, correlation_id)
    logger.info('========== Start activating system user ==========')
    url = settings.DOMAIN_NAMES + api_settings.SYSTEM_USER_STATUS_URL.format(
        system_user_id)
    params = {'is_suspended': False}

    result = ajax_functions._put_method(request, url, "", logger, params)
    logger.info('========== Finish activating system user ==========')
    return result
示例#7
0
def delete_relationship(request, relationship_id):
    logger = logging.getLogger(__name__)
    correlation_id = get_correlation_id_from_username(request.user)
    logger = setup_logger(request, logger, correlation_id)
    logger.info("Checking permission for [{}] username with [{}] permission".format(request.user, 'CAN_DELETE_AGENT_RELATIONSHIP'))
    if not check_permissions_by_user(request.user, 'CAN_DELETE_AGENT_RELATIONSHIP'):
        return {"status": 1, "msg": ''}
    logger.info('========== Start delete relationship ==========')
    url = settings.DOMAIN_NAMES + api_settings.DELETE_RELATIONSHIP.format(relationship_id)

    result = ajax_functions._delete_method(request, url, "", logger)
    logger.info('========== Finish delete relationship ==========')
    return result
示例#8
0
def unblock(request, ticket_id):
    logger = logging.getLogger(__name__)
    correlation_id = get_correlation_id_from_username(request.user)
    logger = setup_logger(request, logger, correlation_id)
    logger.info(
        "Checking permission for [{}] username with [{}] permission".format(
            request.user, 'CAN_DELETE_FRAUD_TICKET'))
    if not check_permissions_by_user(request.user, 'CAN_DELETE_FRAUD_TICKET'):
        return JsonResponse({"status": 0, "msg": ''})
    logger.info('========== Start unblocking device ==========')
    url = api_settings.DELETE_FRAUD_TICKET.format(ticket_id=ticket_id)
    result = ajax_functions._delete_method(request, url, "", logger)
    logger.info('========== Finish unblocking device ==========')
    return result
def delete(request, categoryId):
    if not check_permissions_by_user(request.user, 'CAN_DELETE_CATEGORY'):
        return
    logger = logging.getLogger(__name__)
    correlation_id = get_correlation_id_from_username(request.user)
    logger = setup_logger(request, logger, correlation_id)

    logger.info('========== Start deleting category ==========')
    url = settings.DOMAIN_NAMES + DELETE_CATEGORY.format(
        category_id=categoryId)

    result = ajax_functions._delete_method(request, url, "", logger)
    logger.info('========== Finish deleting category ==========')
    return result
示例#10
0
 def regenerate(request, client_id):
     if not check_permissions_by_user(request.user,
                                      'CAN_REGENERATE_CLIENTS'):
         return
     logger = logging.getLogger(__name__)
     correlation_id = get_correlation_id_from_username(request.user)
     logger = setup_logger(request, logger, correlation_id)
     logger.info('========== Start regenerating client secret ==========')
     url = api_settings.REGENERATE_CLIENT_SECRET_URL.format(client_id)
     result = ajax_functions._post_method(request, url,
                                          "regenerating client secret",
                                          logger)
     logger.info('========== Finish regenerating client secret ==========')
     return result
示例#11
0
def get_user_name(request):
    logger = logging.getLogger(__name__)
    correlation_id = get_correlation_id_from_username(request.user)
    logger = setup_logger(request, logger, correlation_id)
    logger.info('========== Start get user name ==========')
    user_id = request.POST.get('id')
    user_type = request.POST.get('type')
    if user_type == "2":
        url = api_settings.SEARCH_AGENT
    else:
        url = api_settings.MEMBER_CUSTOMER_PATH
    params = {'id': user_id}
    result = ajax_functions._post_method(request, url, "", logger, params)
    logger.info('========== Finish get user name ==========')
    return result
示例#12
0
def stop_share_benefit_relationship(request, relationship_id):
    logger = logging.getLogger(__name__)
    correlation_id = get_correlation_id_from_username(request.user)
    logger = setup_logger(request, logger, correlation_id)
    logger.info("Checking permission for [{}] username with [{}] permission".format(request.user, 'CAN_SHARE_AGENT_BENEFIT'))
    if not check_permissions_by_user(request.user, 'CAN_SHARE_AGENT_BENEFIT'):
        return {"status": 1, "msg": ''}
    logger.info('========== Start stop share benefit relationship ==========')
    url = settings.DOMAIN_NAMES + api_settings.SHARE_BENEFIT_RELATIONSHIP.format(relationship_id)
    params = {
        "is_sharing_benefit": "false"
    }
    result = ajax_functions._put_method(request, url, "", logger, params)
    logger.info('========== Finish stop share benefit relationship ==========')
    return result
def activate(request, client_id):
    if not check_permissions_by_user(request.user, 'CAN_SUSPEND_CLIENTS'):
        return

    logger = logging.getLogger(__name__)
    correlation_id = get_correlation_id_from_username(request.user)
    logger = setup_logger(request, logger, correlation_id)
    logger.info('========== Start activating client ==========')
    url = settings.DOMAIN_NAMES + api_settings.ACTIVATE_CLIENT_URL.format(
        client_id)
    params = {
        'status': 'active',
    }
    result = ajax_functions._put_method(request, url, "", logger, params)
    logger.info('========== Finish activating client ==========')
    return result
示例#14
0
def inactive(request, campaign_id):
    # if not check_permissions_by_user(request.user, 'CAN_SUSPEND_CLIENTS'):
    #     return

    logger = logging.getLogger(__name__)
    correlation_id = get_correlation_id_from_username(request.user)
    logger = setup_logger(request, logger, correlation_id)
    logger.info('========== Start inactivate campaign ==========')
    url = settings.DOMAIN_NAMES + UPDATE_CAMPAIGNS.format(bak_rule_id=campaign_id)
    params = {
        'is_active': False,
        'name': request.POST.get("campaign_name"),
        'description': request.POST.get("campaign_description")
    }
    result = ajax_functions._put_method(request, url, "", logger, params)
    logger.info('========== Finish inactivate campaign ==========')
    return result
示例#15
0
def activate(request, agent_id):
    logger = logging.getLogger(__name__)
    correlation_id = get_correlation_id_from_username(request.user)
    logger = setup_logger(request, logger, correlation_id)
    logger.info(
        "Checking permission for [{}] username with [{}] permission".format(
            request.user, 'CAN_SUSPEND_AGENTS'))
    if not check_permissions_by_user(request.user, 'CAN_SUSPEND_AGENTS'):
        return {"status": 1, "msg": ''}
    logger.info('========== Start activating agent ==========')
    url = settings.DOMAIN_NAMES + api_settings.AGENT_STATUS_URL.format(
        agent_id)
    params = {
        'is_suspended': False,
    }

    result = ajax_functions._put_method(request, url, "", logger, params)
    logger.info('========== Finish activating agent ==========')
    return result
def _upload_file_view(request):
    logger = logging.getLogger(__name__)
    correlation_id = get_correlation_id_from_username(request.user)
    logger = setup_logger(request, logger, correlation_id)
    if request.method == 'POST':
        upload_file = request.FILES.get('file_data', None)
        if (upload_file == None):
            is_wrong_file = request.session.get(
                'wrong_file_type_%s' % _get_cache_key(request), None)
            del request.session['wrong_file_type_%s' % _get_cache_key(request)]
            request.session.save()

            if is_wrong_file:
                data = {'id': -1, "code": "Upload must be in csv format"}
                return HttpResponse(json.dumps(data))
        # 8MB = 1024 * 1024 * 8 = 8388608
        if upload_file.size > 8388608:
            data = {'id': -1, "code": "file_exceeded_max_size"}
        else:
            data = _upload_via_api(request, upload_file, 1, logger)
        return HttpResponse(json.dumps(data))
示例#17
0
def activate(request, service_id):
    logger = logging.getLogger(__name__)
    correlation_id = get_correlation_id_from_username(request.user)
    logger = setup_logger(request, logger, correlation_id)
    logger.info('========== Start activating service ==========')
    url = settings.DOMAIN_NAMES + api_settings.SERVICE_URL.format(service_id)

    url_get_detail = api_settings.SERVICE_DETAIL_URL.format(service_id)
    success, status_code, status_message, data = RestfulHelper.send \
        ("GET", url_get_detail, {}, request, "getting service detail")
    if success:
        params = {
            'status': 1,
            'service_group_id': data['service_group_id'],
            'currency': data['currency'],
            'description': data['description'],
            'service_name': data['service_name']
        }

    result = ajax_functions._put_method(request, url, "", logger, params)
    logger.info('========== Finish activating service ==========')
    return result
示例#18
0
 def post(self, request, *args, **kwargs):
     context = super(UpdateProductStatusOfCategory, self).get_context_data(**kwargs)
     logger = logging.getLogger(__name__)
     correlation_id = get_correlation_id_from_username(request.user)
     logger = setup_logger(request, logger, correlation_id)
     product_id = request.POST.get('product_id')
     product_status_get = request.POST.get('product_status')
     product_status = True if product_status_get == 'true' else False
     logger.info('========== Start getting product detail ==========')
     product_detail, status_code = self.get_product_detail(product_id)
     if status_code in ["access_token_expire", 'authentication_fail', 'invalid_access_token']:
         return JsonResponse({"status": "1"})
     logger.info('========== Finish getting product detail ==========')
     body = {
         'is_active': product_status,
         "name": product_detail['name'],
         "description": product_detail['description'],
         "image_url": product_detail['image_url'],
         "denomination": product_detail['denomination'],
         "min_price": 0 if not product_detail['min_price'] else float(product_detail['min_price']),
         "max_price": 0 if not product_detail['max_price'] else float(product_detail['max_price']),
         "is_allow_price_range": product_detail['is_allow_price_range'],
         "product_category_id": product_detail['product_category'].get('id', None),
         "payment_service_id": product_detail['payment_service_id']
     }
     if product_status:
         logger.info('========== Start active product ==========')
     else:
         logger.info('========== Start inactive product ==========')
     url = api_settings.UPDATE_PRODUCT_STATUS_IN_CATEGORY.format(product_id=product_id)
     result = ajax_functions._put_method(request, url, "", logger, body)
     if product_status:
         logger.info('========== Finish active product ==========')
     else:
         logger.info('========== Finish inactive product ==========')
     return result
示例#19
0
 def dispatch(self, request, *args, **kwargs):
     check_permissions(request, "SYS_BAL_ADJUST_APPROVE")
     correlation_id = get_correlation_id_from_username(self.request.user)
     self.logger = setup_logger(self.request, logger, correlation_id)
     return super(BalanceAdjustmentListActionView,
                  self).dispatch(request, *args, **kwargs)
示例#20
0
 def dispatch(self, request, *args, **kwargs):
     correlation_id = get_correlation_id_from_username(self.request.user)
     self.logger = setup_logger(self.request, logger, correlation_id)
     return super(SPIUrlConfigurationDelete,
                  self).dispatch(request, *args, **kwargs)
 def dispatch(self, request, *args, **kwargs):
     correlation_id = get_correlation_id_from_username(self.request.user)
     self.logger = setup_logger(self.request, logger, correlation_id)
     return super(CustomerManagementSummary, self).dispatch(request, *args, **kwargs)
示例#22
0
    def authenticate(self, request=None, username=None, password=None):
        try:
            loggers = setup_logger(request, logger, request.user)
            loggers.info('[Start authentication backend service]')
            client_id = settings.CLIENTID
            client_secret = settings.CLIENTSECRET
            url = settings.DOMAIN_NAMES + api_settings.LOGIN_URL

            loggers.info('Auth URL: {}'.format(url))

            payload = {
                'username': username,
                'password': encrypt_text(password),
                'grant_type': 'password',
                'client_id': client_id
            }
            headers = {
                'content-type': 'application/x-www-form-urlencoded',
                'client_id': client_id,
                'client_secret': client_secret,
            }
            loggers.info('Calling authentication backend')

            start_date = time.time()
            auth_response = requests.post(url,
                                          params=payload,
                                          headers=headers,
                                          verify=settings.CERT)

            done = time.time()
            loggers.info("Response code {}".format(auth_response.status_code))
            loggers.info("Response time is {} sec.".format(done - start_date))
            json_data = auth_response.json()
            if auth_response.status_code == 200:
                access_token = json_data.get('access_token', None)
                correlation_id = json_data.get('correlation_id', None)

                if access_token != "" and access_token is not None:
                    loggers.info('Checking user is exit in system')
                    user, created = User.objects.get_or_create(
                        username=username)
                    if created:
                        loggers.info("{} user was created".format(username))
                        user.is_staff = True
                        user.save()

                    user_profiles = self.get_user_profiles(
                        username, access_token, correlation_id, loggers)
                    loggers.info("Adding access token for {} user name".format(
                        username))
                    auth, created_token = Authentications.objects.get_or_create(
                        user=user)
                    auth.access_token = access_token
                    auth.correlation_id = correlation_id
                    auth.system_user_id = user_profiles['id']
                    auth.username = user_profiles['username']
                    auth.firstname = user_profiles['firstname']
                    auth.lastname = user_profiles['lastname']
                    auth.email = user_profiles['email']
                    auth.mobile_number = user_profiles['mobile_number']
                    auth.is_deleted = bool(user_profiles['is_deleted'])
                    auth.created_timestamp = user_profiles['created_timestamp']
                    auth.last_updated_timestamp = user_profiles[
                        'last_updated_timestamp']
                    auth.save()
                    loggers.info(
                        "Authentication success and generate session for {} user name"
                        .format(username))

                    loggers.info(
                        '========== Finish authentication backend service =========='
                    )

                    request.session['access_token'] = access_token
                    request.session['correlation_id'] = correlation_id

                    return user
                else:
                    loggers.error(
                        "Cannot get access token from response of {} user name"
                        .format(username))
                    loggers.info('[Finish authentication backend service]')
                    return None
            else:
                if json_data.get('error_description') == 'Invalid credential':
                    messages.add_message(
                        request, messages.INFO,
                        "Your username and password didn't match. Please try again."
                    )
                elif json_data.get(
                        'error_description') == 'Account has been suspended':
                    messages.add_message(
                        request, messages.INFO,
                        "Your account has been suspended. \n Please contact your administrator."
                    )

        except Exception as ex:
            loggers.error(ex)
            loggers.error(
                "[{} user name authentication to backend was failed]".format(
                    username))
            return None
示例#23
0
 def dispatch(self, request, *args, **kwargs):
     correlation_id = get_correlation_id_from_username(self.request.user)
     self.logger = setup_logger(self.request, logger, correlation_id)
     return super(AgentManagementProduct,
                  self).dispatch(request, *args, **kwargs)
 def dispatch(self, request, *args, **kwargs):
     correlation_id = get_correlation_id_from_username(self.request.user)
     self.logger = setup_logger(self.request, logger, correlation_id)
     return super(FeeDistributionsUpdate,
                  self).dispatch(request, *args, **kwargs)
示例#25
0
 def dispatch(self, request, *args, **kwargs):
     correlation_id = get_correlation_id_from_username(self.request.user)
     self.logger = setup_logger(self.request, logger, correlation_id)
     return super(CompanyBalanceView, self).dispatch(request, *args, **kwargs)
 def dispatch(self, request, *args, **kwargs):
     correlation_id = get_correlation_id_from_username(self.request.user)
     self.logger = setup_logger(self.request, logger, correlation_id)
     return super(TransactionHistoryView,
                  self).dispatch(request, *args, **kwargs)
示例#27
0
 def dispatch(self, request, *args, **kwargs):
     correlation_id = get_correlation_id_from_username(self.request.user)
     self.logger = setup_logger(self.request, logger, correlation_id)
     return super(PaymentAndFeeStructureDetailView,
                  self).dispatch(request, *args, **kwargs)
 def dispatch(self, request, *args, **kwargs):
     check_permissions(request, 'CAN_APPROVE_VOUCHER_ADJUSTMENT')
     correlation_id = get_correlation_id_from_username(self.request.user)
     self.logger = setup_logger(self.request, logger, correlation_id)
     return super(RejectVoucherRefundView,
                  self).dispatch(request, *args, **kwargs)
示例#29
0
 def dispatch(self, request, *args, **kwargs):
     correlation_id = get_correlation_id_from_username(self.request.user)
     self.logger = setup_logger(self.request, logger, correlation_id)
     return super(ServiceList, self).dispatch(request, *args, **kwargs)
 def dispatch(self, request, *args, **kwargs):
     correlation_id = get_correlation_id_from_username(self.request.user)
     self.logger = setup_logger(self.request, logger, correlation_id)
     return super(DeleteSettingBonus, self).dispatch(request, *args, **kwargs)