summaryrefslogtreecommitdiff
path: root/talerbank/app/views.py
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-08-20 13:38:59 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-08-20 13:38:59 +0530
commit0e924099cc9867464f083bd61699ee02ae238357 (patch)
treeffbf1656a04527d56464d9553d565ab9c43dfbf4 /talerbank/app/views.py
parent57b8e24a8e14b7d4bc03c8dc06b65c251c317e22 (diff)
downloadbank-0e924099cc9867464f083bd61699ee02ae238357.tar.gz
bank-0e924099cc9867464f083bd61699ee02ae238357.tar.bz2
bank-0e924099cc9867464f083bd61699ee02ae238357.zip
use credit/debit indicator for balance
Diffstat (limited to 'talerbank/app/views.py')
-rw-r--r--talerbank/app/views.py35
1 files changed, 29 insertions, 6 deletions
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index 3e25137..8449123 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -69,18 +69,20 @@ LOGGER = logging.getLogger(__name__)
# can handle (because of the wallet).
UINT64_MAX = (2 ** 64) - 1
+
class PaytoParse:
def __init__(self, payto_uri):
parsed_payto = urlparse(payto_uri)
if parsed_payto.scheme != "payto":
raise Exception("Bad Payto URI: '%s'" % payto_uri)
path_as_list = parsed_payto.path.split("/")
- if (len(path_as_list) == 0):
+ if len(path_as_list) == 0:
raise Exception("No account/user name found: '%s'" % payto_uri)
self.account = path_as_list[-1]
params = dict(parse_qsl(parsed_payto.query))
self.subject = params.get("subject")
+
##
# Exception raised upon failing login.
#
@@ -395,6 +397,7 @@ def get_acct_from_payto(uri_str: str) -> str:
raise Exception("Bad Payto URI: '%s'" % uri_str)
return wire_uri.path.split("/")[-1]
+
def get_subject_from_payto(uri_str: str) -> str:
wire_uri = urlparse(uri_str)
if wire_uri.scheme != "payto":
@@ -405,6 +408,7 @@ def get_subject_from_payto(uri_str: str) -> str:
raise Exception("Subject not found in Payto URI: '%s'" % uri_str)
return subject
+
##
# Class representing the registration form.
class UserReg(forms.Form):
@@ -480,7 +484,7 @@ def register(request):
msg = "Wrong field(s): %s." % ", ".join(input_data.errors.keys())
raise InvalidInputData(msg)
username = input_data.cleaned_data["username"]
- password = input_data.cleaned_data["password"]
+ password = input_data.cleaned_data["password"]
user = internal_register(username, password)
except UsernameUnavailable as e:
return render(request, "register.html", {"not_available": True})
@@ -518,8 +522,12 @@ def logout_view(request):
django.contrib.auth.logout(request)
return redirect("index")
+
def config_view(request):
- return JsonResponse(dict(version="0:0:0", currency=settings.TALER_CURRENCY), status=200)
+ return JsonResponse(
+ dict(version="0:0:0", currency=settings.TALER_CURRENCY), status=200
+ )
+
def extract_history(account, delta, start=None):
history = []
@@ -879,6 +887,7 @@ def get_payto_from_account(request, acct):
h = get_plain_host(request)
return f"payto://x-taler-bank/{h}/{acct.user.username}"
+
def get_reserve_pub(subject):
# obey to regex: \\b[a-z0-9A-Z]{52}\\b
regex = re.compile(r"\b[a-z0-9A-Z]{52}\b")
@@ -887,6 +896,7 @@ def get_reserve_pub(subject):
return ret.group(0)
return None
+
@require_GET
@login_via_headers
def twg_history_incoming(request, user_account, acct_id):
@@ -965,6 +975,7 @@ def basic_auth(request):
username, password = base64.b64decode(tokens[1]).decode("utf-8").split(":")
return django.contrib.auth.authenticate(username=username, password=password)
+
def make_taler_withdraw_uri(request, withdraw_id):
if request.is_secure():
proto_extra = ""
@@ -979,6 +990,7 @@ def make_taler_withdraw_uri(request, withdraw_id):
p = "/".join([host] + pfx_components + [str(withdraw_id)])
return f"taler{proto_extra}://withdraw/{p}"
+
@login_via_headers
@csrf_exempt
@require_POST
@@ -998,7 +1010,9 @@ def withdraw_headless(request, user):
try:
exchange_user = User.objects.get(username=exchange_account_name)
except User.DoesNotExist:
- return JsonResponse(dict(hint="exchange bank account does not exist"), status=404)
+ return JsonResponse(
+ dict(hint="exchange bank account does not exist"), status=404
+ )
exchange_bankaccount = exchange_user.bankaccount
wire_transfer(
Amount.parse(data.get("amount")),
@@ -1044,7 +1058,9 @@ def api_withdraw_operation(request, withdraw_id):
or op.selected_reserve_pub != selected_reserve_pub
):
return JsonResponse(
- dict(code=5600, hint="selection of withdraw parameters already done"),
+ dict(
+ code=5600, hint="selection of withdraw parameters already done"
+ ),
status=409,
)
else:
@@ -1275,7 +1291,14 @@ def bank_accounts_api_balance(request, user_account, acct_id):
f"credentials do not match URL ('{acct_id}' vs '{user_account.username}')"
)
- return JsonResponse(dict(balance=acct.balance.stringify()))
+ return JsonResponse(
+ dict(
+ # The balance field is kept as long as the cashier still uses it
+ balance=acct.balance.stringify(),
+ balance_amount=acct.balance.amount,
+ credit_debit_indicator=("credit" if acct.balance.is_positive else "debit"),
+ )
+ )
@csrf_exempt