diff --git a/www/Dockerfile b/www/Dockerfile index 289e167a7886fc40c99e512197864e5f08d324e2..e296a62ba4df71cfad97418ad32169079ff1cd8d 100644 --- a/www/Dockerfile +++ b/www/Dockerfile @@ -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 diff --git a/www/web/warpauth/templates/warpauth/profile.html b/www/web/warpauth/templates/warpauth/profile.html index a1b4b66fcfc993c6500f03ad1dc179b9ee660eb0..f8930e472945ce819f1c7fb36dfd38fd7ccca694 100644 --- a/www/web/warpauth/templates/warpauth/profile.html +++ b/www/web/warpauth/templates/warpauth/profile.html @@ -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> diff --git a/www/web/warpauth/templates/warpauth/profile/warp_pay.html b/www/web/warpauth/templates/warpauth/profile/warp_pay.html new file mode 100644 index 0000000000000000000000000000000000000000..890f3221c514f2b1fc8308b39745ab3d31511925 --- /dev/null +++ b/www/web/warpauth/templates/warpauth/profile/warp_pay.html @@ -0,0 +1,40 @@ +{% 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> + + diff --git a/www/web/warpauth/urls.py b/www/web/warpauth/urls.py index cfe293e08edad6e991102e58ae9b36527f5be9ef..d916b767a339e2ecca80603e6f21aa9e1e2a23ed 100644 --- a/www/web/warpauth/urls.py +++ b/www/web/warpauth/urls.py @@ -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'), ] diff --git a/www/web/warpauth/views/profile.py b/www/web/warpauth/views/profile.py index 3505b7e1904b6da83a6812497548a9d70503cdae..d2b3d3edefb91ea3adba523aaceaa8f1427c849c 100644 --- a/www/web/warpauth/views/profile.py +++ b/www/web/warpauth/views/profile.py @@ -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() diff --git a/www/web/warppay/views.py b/www/web/warppay/views.py index a0a17242f86158d65fa287ff81f591250660a1f7..efe221c4332fbe1d0a6061ab0d5db53d64286f65 100644 --- a/www/web/warppay/views.py +++ b/www/web/warppay/views.py @@ -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()