Exemplo n.º 1
0
def frm_login(request):
    # if request.META.get('HTTP_HOST') not in read_config('login_base_address', 'http://payment.gen-co.com/'):
    #     return redirect(read_config('login_base_address', 'http://payment.gen-co.com/'))
    if request.user.is_authenticated():
        return redirect('/')
    if request.method == 'GET':
        if not request.GET.get('skip'):
            if settings.IPL_DEBUG and get_client_ip(
                    request) == settings.IPL_DEBUG_HOST:
                res = settings.IPL_DEBUG_USER
            else:
                res = get_user_name_from_ip(request)
            if res:
                if User.objects.filter(username=res).exists():
                    requested_user = User.objects.get(username=res)
                    if not requested_user.is_staff:  # bug fix for personnel login fom home!
                        uid = requested_user.pk
                        request.session['cui'] = uid
                        LoginWithIPEventHandler().fire(
                            User.objects.get(pk=uid), None, uid)
                        return redirect('/user/nav/?uid=%s' % uid)
        return render(request, 'login/Login.html')
    elif request.method == 'POST':
        u_name = request.POST.get('u', -1)
        u_pass = request.POST.get('p', -1)
        if u_name is -1 or u_pass is -1:
            return send_error(request, _('invalid username or password'))
        user = authenticate(username=u_name, password=u_pass)
        ll = LoginLogs()
        if user is None:
            if User.objects.filter(username=u_name).exists():
                ll.user = User.objects.get(username=u_name)
                ll.ip_address = get_client_ip(request)
                ll.state = False
                ll.save()
            return send_error(request, _('invalid username or password'))

        try:
            ll.user = user
            ll.state = True
            ll.ip_address = get_client_ip(request)
            ll.save()
            if not user.is_active:
                InactiveAccountLoginEventHandler().fire(user, None, user.pk)
                return send_error(request, _('your account has been locked'))
            login(request, user)
            return HttpResponse('200')
        except Exception as e:
            print e.message or e.args
            return HttpResponseBadRequest('unknown error')
    else:
        return render(request, 'errors/AccessDenied.html')
Exemplo n.º 2
0
def temp_recharge(request):
    return redirect('/')
    user = request.user
    granted = False
    if user.is_staff or user.is_superuser:
        granted = True
    if request.method == 'GET':
        if not granted:
            uid = user.pk
        else:
            uid = request.GET.get('uid')
        if not validate_integer(uid):
            return render(request, 'errors/ServerError.html')
        if not granted:
            check = check_user_temp_charge(int(uid))
            if not check:
                fire_event(4300, request.user, None, request.user.pk)
                return redirect(
                    reverse(show_user_service_summery) + '?u=%s' % uid)
        res = temp_charge_user(uid, user.pk)
        if res:
            kill_user(uid, get_client_ip(request))
            # send_from_template.delay(uid, 15, ftime=read_config('service_temp_time', 2),
            #                          fta=read_config('service_temp_amount', 700))
            return redirect(reverse(show_user_service_summery) + '?u=%s' % uid)
        else:
            fire_event(4124, request.user, None, request.user.pk)
            return render(
                request, 'errors/CustomError.html',
                {'error_message': _('unable to charge. contact support')})
Exemplo n.º 3
0
def get_user_name_from_ip(request):
    ibs = IBSManager()
    try:
        ip = get_client_ip(request)
        res = ibs.get_username_from_ip(ip)
        failed = read_config('service_failed_users')
        failed_ids = failed.split(',')
        tmp_res = None
        for f in failed_ids:
            if User.objects.filter(username=res).exists():
                u = User.objects.get(username=res)
                if u.pk == int(f):
                    if IBSUserInfo.objects.filter(user=f).exists():
                        failed_ibs_id = IBSUserInfo.objects.get(user=f).ibs_uid
                    else:
                        failed_ibs_id = ibs.get_user_id_by_username(res)
                    ras_username = get_username_from_ras(
                        ip, int(failed_ibs_id))
                    return ras_username
                else:
                    tmp_res = res
            else:
                return None
        return tmp_res
    except Exception as e:
        print e.message
        res = None
    return res
Exemplo n.º 4
0
 def kill_user_by_request(user_id, request):
     if not user_id:
         return False
     try:
         ibs = IBSManager()
         if IBSUserInfo.objects.filter(user=user_id).exists():
             ibs_uid = IBSUserInfo.objects.get(user=user_id).ibs_uid
         else:
             ibs_uid = ibs.get_user_id_by_username(
                 User.objects.get(pk=user_id).username)
         if ibs.kill_user(ibs_uid):
             return True
         failed_user_id = read_config('service_failed_users', 3306)
         failed_user_ids = failed_user_id.split(',')
         ip_address = get_client_ip(request)
         for f in failed_user_ids:
             if IBSUserInfo.objects.filter(user=f).exists():
                 f_ibi = IBSUserInfo.objects.get(user=f).ibs_uid
             elif ip_address is not None:
                 fu = User.objects.get(pk=f)
                 f_ibi = ibs.get_user_id_by_username(fu.username, True)
             else:
                 return False
             connections = ibs.get_user_connection_info_1(f_ibi)
             for c in connections:
                 if c[4] == ip_address:
                     ibs = IBSManager()
                     if ibs.kill_failed_user(c[2], f_ibi, c[0]):
                         return True
         return False
     except Exception as e:
         logger.error(e.args or e.message)
         return False
Exemplo n.º 5
0
def mellat_post_back(request):
    if request.method == 'POST':
        ref_id = request.POST.get('RefId', False)
        res_code = request.POST.get('ResCode', False)
        order_id = request.POST.get('SaleOrderId', False)
        sf_id = request.POST.get('SaleReferenceId', False)
        message = _('the payment has been canceled')
        banking_done = False
        if not (ref_id or res_code or order_id or sf_id):
            message = _('invalid parameters')
            fire_event(4645, None, get_client_ip(request))
            banking_done = False
        try:
            if not validate_integer(order_id):
                banking_done = False
            if not InvoicePaymentTracking.objects.filter(pk=order_id).exists():
                message = _('banking parameters are not correct')
                error_page = render(request, 'finance/payment/PostBack.html', {'msg': message})
                return error_page
            ep = InvoicePaymentTracking.objects.get(pk=order_id)
            i = Invoice.objects.get(pk=ep.invoice.pk)
            if i.is_paid:
                return redirect('/')
            ep.end_time = datetime.today()
            ep.final_res = sf_id
            ep.save()
            if not isinstance(res_code, bool) and res_code == '0':
                message = _('your account has been charged')
                banking_done = True
            if banking_done:
                data = BankProperties.objects.filter(bank__internal_value=identifier)
                terminal_id = long(data.get(name=properties[2]).value)
                bank_username = data.get(name=properties[0]).value
                bank_password = data.get(name=properties[1]).value
                bml = BMLPaymentAPI(bank_username, bank_password, terminal_id)
                error_counter = 0
                while error_counter < 10:
                    verify_res = bml.verify_payment(long(order_id), long(sf_id))
                    if verify_res[0] and (verify_res[1] == '0' or verify_res[1] == 0):
                        bml.settle_payment(long(order_id), sf_id)
                        ep.is_success = True
                        break
                    elif verify_res[0] and (verify_res[1] != '0' and verify_res[1] != 0):
                        banking_done = False
                        break
                    else:
                        error_counter += 1
                if error_counter > 9:
                    ep.is_success = False
                    message = _('unable to complete payment')
                    banking_done = False
                ep.save()
            if banking_done:
                pi = PayInvoice(invoice=i.pk, ref_code=str(sf_id), use_discount=False, is_online=True,
                                price=i.price, comment=None, request=request)
                if pi.pay().get_invoice():
                    pi.commit()
                fire_event(4632, i)
            else:
                fire_event(5707, i)
            if banking_done:
                if i.service.service_type == 1:
                    if get_is_new_service(i.pk):
                        extra = get_next_charge_transfer(i.user_id)
                    else:
                        extra = 0
                    InvoicePaidNotification().send(user_id=i.user_id, service_type=i.service.service_type,
                                                   service=i.service_text, extra_data=i.extra_data,
                                                   expire_date=convert_date(
                                                       i.user.fk_user_current_service_user.get().expire_date),
                                                   bank_ref=i.ref_number,
                                                   transfer=extra
                                                   )
                    # send_from_template.delay(i.user_id, 13,
                    #                          cus=i.service_text,
                    #                          adt=extra,
                    #                          fid=i.pk,
                    #                          exp=convert_date(i.user.fk_user_current_service_user.get().expire_date,
                    #                                           True),
                    #                          brn=str(sf_id))
                elif i.service.service_type == 2:
                    InvoicePaidNotification().send(user_id=i.user_id, service_type=i.service.service_type,
                                                   service=i.service_text + ' - ' + convert_credit(
                                                       i.service.content_object.amount),
                                                   extra_data=i.extra_data,
                                                   expire_date=convert_date(
                                                       i.user.fk_user_current_service_user.get().expire_date),
                                                   bank_ref=i.ref_number)
                    # send_from_template.delay(i.user_id, 14,
                    #                          ta=convert_credit(i.service.content_object.amount),
                    #                          fid=i.pk,
                    #                          brn=str(sf_id))
            page_res = render(request, 'finance/payment/PostBack.html', {'msg': message, 'i': i,
                                                                         'done': banking_done})
            return page_res
        except Exception as e:
            print ("Error in post back : %s \r\n with this params : \r\n%s"
                   % (" ".join((str(a) for a in e.args)), " , ".join(request.POST)))
            return render(request, 'errors/ServerError.html')
    else:
        return redirect(reverse(show_all_invoices))