gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-bank] branch master updated: Managing 3/4 of debt li


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] branch master updated: Managing 3/4 of debt limit exceeded exceptions, and getting rid of helper function used to create reserves.
Date: Thu, 23 Mar 2017 12:12:33 +0100

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository bank.

The following commit(s) were added to refs/heads/master by this push:
     new 11a7e1e  Managing 3/4 of debt limit exceeded exceptions, and getting 
rid of helper function used to create reserves.
11a7e1e is described below

commit 11a7e1ec7db25f5658bd28d26b7f9641b21edf01
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Mar 23 12:11:30 2017 +0100

    Managing 3/4 of debt limit exceeded exceptions, and getting rid
    of helper function used to create reserves.
---
 talerbank/app/templates/profile_page.html |  5 ++
 talerbank/app/views.py                    | 98 ++++++++++++++++---------------
 2 files changed, 55 insertions(+), 48 deletions(-)

diff --git a/talerbank/app/templates/profile_page.html 
b/talerbank/app/templates/profile_page.html
index 8cf3643..d4c5e29 100644
--- a/talerbank/app/templates/profile_page.html
+++ b/talerbank/app/templates/profile_page.html
@@ -45,6 +45,11 @@
   <section id="main">
     <article>
       <div class="notification">
+        {% if not initial_bonus %}
+        <p class="informational informational-fail">
+          No initial bonus given, poor bank!
+        </p>
+        {% endif %}
         {% if just_withdrawn %}
         <p class="informational informational-ok">
           Withdrawal approved!
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index 63ee611..dfc62d7 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -88,6 +88,7 @@ def get_session_flag(request, name):
 def profile_page(request):
     just_withdrawn = get_session_flag(request, "just_withdrawn")
     just_registered = get_session_flag(request, "just_registered")
+    initial_bonus = get_session_flag(request, "initial_bonus")
     user_account = BankAccount.objects.get(user=request.user)
     history = extract_history(user_account)
     reserve_pub = request.session.get("reserve_pub")
@@ -205,12 +206,37 @@ def pin_tan_verify(request):
         # This is not a withdraw session, we redirect the user to the
         # profile page.
         return redirect("profile")
-    return create_reserve_at_exchange(request,
-                                      amount,
-                                      exchange_url,
-                                      exchange_account_number,
-                                      reserve_pub,
-                                      sender_wiredetails)
+    try:
+        BankAccount.objects.get(account_no=exchange_account_number)
+    except BankAccount.DoesNotExist:
+        raise HttpResponseBadRequest("The bank account #{} of exchange {} does 
not exist".format(exchange_account_no, exchange_url))
+    logging.info("asking exchange {} to create reserve 
{}".format(exchange_url, reserve_pub))
+    json_body = dict(
+            reserve_pub=reserve_pub,
+            execution_date="/Date(" + str(int(time.time())) + ")/",
+            sender_account_details=sender_account_details,
+             # just something unique
+            transfer_details=dict(timestamp=int(time.time() * 1000)),
+            amount=amount,
+    )
+    user_account = BankAccount.objects.get(user=request.user)
+    exchange_account = 
BankAccount.objects.get(account_no=exchange_account_number)
+    try:
+        wire_transfer(amount, user_account, exchange_account, reserve_pub)
+    except DebtLimitExceededException:
+        request.session["debt_limit"] = True
+        return redirect("profile")
+
+    request_url = urljoin(exchange_url, "admin/add/incoming")
+    res = requests.post(request_url, json=json_body)
+    if res.status_code != 200:
+        return render(request, "error_exchange.html", dict(
+            message="Could not transfer funds to the exchange.  The exchange 
({}) gave a bad response.".format(exchange_url),
+            response_text=res.text,
+            response_status=res.status_code,
+        ))
+    request.session["just_withdrawn"] = True
+    return redirect("profile")
 
 
 class UserReg(forms.Form):
@@ -237,7 +263,11 @@ def register(request):
         user_account.save()
     bank_internal_account = BankAccount.objects.get(account_no=1)
     amount = dict(value=100, fraction=0, currency=settings.TALER_CURRENCY)
-    wire_transfer(amount, bank_internal_account, user_account, "Joining bonus")
+    try:
+        wire_transfer(amount, bank_internal_account, user_account, "Joining 
bonus")
+    except DebtLimitExceededException:
+        logger.info("Debt situation encountered")
+        request.session["initial_bonus"] = False
     request.session["just_registered"] = True
     user = django.contrib.auth.authenticate(username=username, 
password=password)
     django.contrib.auth.login(request, user)
@@ -322,10 +352,18 @@ def add_incoming(request):
         credit_account = user_account = 
BankAccount.objects.get(user=data["credit_account"])
     except BankAccount.DoesNotExist:
         return HttpResponse(status=404)
-    wire_transfer(data["amount"],
-                  debit_account,
-                  credit_account,
-                  subject)
+    try:
+        wire_transfer(data["amount"],
+                      debit_account,
+                      credit_account,
+                      subject)
+    except DebtLimitExceededException:
+        return JsonResponse({"outcome": "fail",
+                             "hint": "debit count has reached its debt limit"},
+                             status=403)
+    
+
+
     return JsonResponse({"outcome": "ok"}, status=200)
 
 
@@ -345,42 +383,6 @@ def withdraw_nojs(request):
     return response
 
 
-def create_reserve_at_exchange(request,
-                               amount,
-                               exchange_url,
-                               exchange_account_no,
-                               reserve_pub,
-                               sender_account_details):
-    try:
-        BankAccount.objects.get(account_no=exchange_account_no)
-    except BankAccount.DoesNotExist:
-        raise HttpResponseBadRequest("The bank account #{} of exchange {} does 
not exist".format(exchange_account_no, exchange_url))
-    logging.info("asking exchange {} to create reserve 
{}".format(exchange_url, reserve_pub))
-    json_body = dict(
-            reserve_pub=reserve_pub,
-            execution_date="/Date(" + str(int(time.time())) + ")/",
-            sender_account_details=sender_account_details,
-             # just something unique
-            transfer_details=dict(timestamp=int(time.time() * 1000)),
-            amount=amount,
-    )
-    request_url = urljoin(exchange_url, "admin/add/incoming")
-    res = requests.post(request_url, json=json_body)
-    if res.status_code != 200:
-        return render(request, "error_exchange.html", dict(
-            message="Could not transfer funds to the exchange.  The exchange 
({}) gave a bad response.".format(exchange_url),
-            response_text=res.text,
-            response_status=res.status_code,
-        ))
-    user_account = BankAccount.objects.get(user=request.user)
-    exchange_account = BankAccount.objects.get(account_no=exchange_account_no)
-    # Build subject including Exchange base URL here.
-    logger.info("Reserve data: '%s'" % json.dumps(res.json()))
-    wire_transfer(amount, user_account, exchange_account, reserve_pub)
-    request.session["just_withdrawn"] = True
-    return redirect("profile")
-
-
 def wire_transfer(amount,
                   debit_account,
                   credit_account,
@@ -421,7 +423,7 @@ def wire_transfer(amount,
     if 1 == amounts.amount_cmp(debit_account.balance_obj, threshold) \
        and 0 != amounts.amount_cmp(amounts.get_zero(), threshold):
         logger.error("Negative balance '%s' not allowed." % 
json.dumps(debit_account.balance_obj))
-        logger.info("Your threshold is: '%s'." % json.dumps(threshold))
+        logger.info("%s's threshold is: '%s'." % (debit_account.user.username, 
json.dumps(threshold)))
         raise DebtLimitExceededException()
 
     with transaction.atomic():

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]