Skip to content
Snippets Groups Projects
Commit 3e33a781 authored by Christian Dresen's avatar Christian Dresen
Browse files

[WarpAuth] First implementation of WarpPay-Settings

parent 815e953d
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,7 @@ RUN pip3 install \
django-two-factor-auth \
matterhook \
markdown \
bcrypt \
--upgrade
RUN pip3 install git+https://github.com/nkunihiko/django-bootstrap3-datetimepicker.git
......
......@@ -15,6 +15,9 @@
<li role="presentation">
<a href="#change_passwd" aria-controls="change_passwd" role="tab" data-toggle="tab">{% trans "change_password" %}</a>
</li>
<li role="presentation">
<a href="#warp_pay" aria-controls="warp_pay" role="tab" data-toggle="tab">{% trans "warp_pay" %}</a>
</li>
<li role="presentation">
<a href="/account/two_factor/">{% trans "two_factor_authentication" %}</a>
</li>
......@@ -27,6 +30,9 @@
<div role="tabpanel" class="tab-pane fade in" id="change_passwd">
{% include "warpauth/profile/change_password.html" %}
</div>
<div role="tabpanel" class="tab-pane fade in" id="warp_pay">
{% include "warpauth/profile/warp_pay.html" %}
</div>
</div>
</div>
<script>
......
{% load i18n %}
<div>
<br />
{% if error_warp_pay_settings %}
<div class="alert alert-danger">{{ error_warp_pay_settings }}</div><br>
{% endif %}
{% if success_warp_pay_settings %}
<div class="alert alert-success">{% trans "settings_changed_successful" %}</div><br>
{% endif %}
<form class="form-horizontal" method="POST" action="/account/profile/warp_pay/" role="form">
{% csrf_token %}
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " for="id_curr_pw">{% trans "current_password" %}</label>
<div class=" col-sm-10 col-lg-10 ">
<input class=" form-control" id="id_curr_pw" name="curr_pw" type="password" />
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " for="id_new_pin">{% trans "new_pin_code" %}</label>
<div class=" col-sm-10 col-lg-10 ">
<input class=" form-control" id="id_new_pin" name="new_pin" type="password" />
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " for="id_new_pin_confirm">{% trans "confirm_pin_code" %}</label>
<div class=" col-sm-10 col-lg-10 ">
<input class=" form-control" id="id_new_pin_confirm" name="new_pin_confirm" type="password" />
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button style="float: left" type="submit" formmethod="post" class="btn btn-primary">{% trans "save_settings" %}</button>
</div>
</div>
</form>
</div>
......@@ -14,6 +14,7 @@ urlpatterns = [
url(r'^account/profile/$', profile.index, name='profile_index'),
url(r'^account/profile/change_password/$', profile.change_password, name='change_password'),
url(r'^account/profile/change_information/$', profile.change_information, name='change_information'),
url(r'^account/profile/warp_pay_settings/$', profile.warp_pay_settings, name='warp_pay_settings'),
]
......@@ -9,6 +9,7 @@ from warpauth.models import LdapUser, LdapUserForm
from warpauth.util import *
import logging
from django.conf import settings
import bcrypt
##
# http://www.python-ldap.org/doc/html/ldap.html#ldap.LDAPObject
......@@ -26,6 +27,9 @@ def clear_error_messages():
page_context["success_info"] = False
page_context["error_passwd"] = ""
page_context["success_passwd"] = False
page_context["error_warp_pay_settings"] = ""
page_context["success_warp_pay_settings"] = False
page_context["selected_tab"] = ""
......@@ -44,7 +48,6 @@ def change_information(request):
if request.method != 'POST':
return redirect("profile_index")
user = LdapUser.objects.get(uid=str(request.user))
if "first_name" in request.POST:
first_name = request.POST["first_name"]
......@@ -55,7 +58,7 @@ def change_information(request):
card_id = request.POST["card_id"]
else:
card_id = 0
if "email" not in request.POST:
page_context["error_info"] = "err_invalid_email"
return HttpResponse(render(request, 'warpauth/profile.html', page_context))
......@@ -80,7 +83,8 @@ def change_information(request):
user.last_name = last_name
user.cn = cn
user.email = email
user.card_id=card_id
user.card_id = card_id
user.save()
page_context["success_info"] = True
......@@ -88,6 +92,23 @@ def change_information(request):
return HttpResponse(render(request, 'warpauth/profile.html', page_context))
@login_required(login_url=settings.LOGIN_URL, redirect_field_name=None)
def warp_pay_settings(request):
page_context["selected_tab"] = "#warp_pay"
if request.method == 'POST':
user = LdapUser.objects.get(uid=str(request.user))
if request.POST["new_pin"] != "":
if request.POST["new_pin"].isnummeric() and request.POST["new_pin"] == request.POST["new_pin_confirm"]:
pin = int(request.POST["new_pin"])
user.pinCode = bcrypt.hashpw(pin, bcrypt.gensalt())
user.save()
page_context["success_warp_pay_settings"] = True
else:
page_context["error_warp_pay_settings"] = "YO"
return HttpResponse(render(request, 'warpauth/profile.html', page_context))
@login_required(login_url=settings.LOGIN_URL, redirect_field_name=None)
def change_password(request):
clear_error_messages()
......
......@@ -19,7 +19,7 @@ from rest_framework import status
def category_list(request):
if request.method == 'GET':
products = ProductCategory.objects.all()
serializer = ProductCategorySerializer(products,context={'request': request}, many=True)
serializer = ProductCategorySerializer(products, context={'request': request}, many=True)
return Response(serializer.data)
return Response()
......@@ -31,7 +31,7 @@ def category_list(request):
def product_list(request):
if request.method == 'GET':
products = Product.objects.all()
serializer = ProductSerializer(products,context={'request': request}, many=True)
serializer = ProductSerializer(products, context={'request': request}, many=True)
return Response(serializer.data)
elif request.method == 'PUT':
return Response()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment