diff --git a/members/static/js/application_controllers.js b/members/static/js/application_controllers.js index 4e7a7bc..1e3aa7b 100644 --- a/members/static/js/application_controllers.js +++ b/members/static/js/application_controllers.js @@ -31,7 +31,7 @@ app.controller("applicationController", function($scope, $http, $location, $wind $scope.response = null; $scope.widgetId = null; $scope.model = { - key: '6LevHAcUAAAAAA45B7c-7qja-2aSwHztr9xb4K2Z' + key: "6LevHAcUAAAAAA45B7c-7qja-2aSwHztr9xb4K2Z" }; $scope.setResponse = function(response) { $scope.response = response; @@ -47,16 +47,17 @@ app.controller("applicationController", function($scope, $http, $location, $wind var valid; //server side validation $scope.member.reCaptchaResponse = vcRecaptchaService.getResponse() - if($scope.member.reCaptchaResponse === "") { + console.log($scope.member.reCaptchaResponse); + if($scope.member.reCaptchaResponse === "") { notyError("Ole hyvä ja täytä kuvavarmennus"); } else { $http.post("/members/api/request", $scope.member).then(function(data){ notySuccess("Hakemus lähetetty!"); - $window.location.href = "/application/"; + $window.location.href = "/application/success"; }, function(data){ notyError("Jokin meni vikaan. Yritä uudelleen."); vcRecaptchaService.reload($scope.widgetId); }); } } -}); \ No newline at end of file +}); diff --git a/members/templates/application_index.html b/members/templates/application_index.html index 2c54ac2..7457cc9 100644 --- a/members/templates/application_index.html +++ b/members/templates/application_index.html @@ -64,7 +64,7 @@
Tallenna
- \ No newline at end of file + diff --git a/members/templates/application_success.html b/members/templates/application_success.html new file mode 100644 index 0000000..370a897 --- /dev/null +++ b/members/templates/application_success.html @@ -0,0 +1,15 @@ + + + + + + + + + Hienoa! Jäsenhakemuksesi on nyt lähetetty. + + +

Hienoa! Jäsenhakemuksesi on nyt lähetetty.

+ Takaisin Sähköinsinöörikillan web-sivuille + + diff --git a/members/views.py b/members/views.py index 3bae31d..0fd0067 100644 --- a/members/views.py +++ b/members/views.py @@ -17,23 +17,22 @@ def validateReCaptcha(response): 'response': response, } url = "https://www.google.com/recaptcha/api/siteverify" - headers = {'Content-type': 'application/json'} - resp = requests.post(url, data=json.dumps(values), headers=headers) + headers = {'Content-type': 'application/x-www-form-urlencoded'} + resp = requests.post(url, values, headers=headers) result = json.loads(resp.text) print(resp.text) - print(values) if not result["success"]: return False return True -def sendmail(subject, message): - send_mail( - subject, - message, - 'no-reply@sahkoinsinoorikilta.fi', - ['viestintamestari@sahkoinsinoorikilta.fi'], - fail_silently=False - ) +#def sendmail(subject, message): + #send_mail( + # subject, + # message, + # 'no-reply@sahkoinsinoorikilta.fi', + # ['viestintamestari@sahkoinsinoorikilta.fi'], + # fail_silently=False + #) @ensure_csrf_cookie @require_http_methods(["GET"]) @@ -44,6 +43,10 @@ def index(request, *args, **kwargs): @ensure_csrf_cookie def applicationindex(request, *args, **kwargs): return render(request, 'application_index.html',{}) + +@ensure_csrf_cookie +def applicationSuccessIndex(request, *args, **kwargs): + return render(request, 'application_success.html',{}) @ensure_csrf_cookie @require_http_methods(["GET"]) @@ -120,8 +123,12 @@ def member_requests(request, *args, **kwargs): def new_member_request(request, *args, **kwargs): try: data = json.loads(request.body.decode("utf-8")) + print("jsondada:") + print(data) #get captcha response from member captcha = data.pop("reCaptchaResponse", "") + print("Captcha:") + print(captcha) #send response to google and check it out captcha_ok = validateReCaptcha(captcha) #if not ok, inform user @@ -141,7 +148,7 @@ def new_member_request(request, *args, **kwargs): message += 'To mail list: ' + str(mem.jas) + '\r\n' message += 'Created: ' + mem.created.isoformat(' ') + '\r\n' message += 'Please go to the http://sika.sahkoinsinoorikilta.fi/members/ and do something about it!\r\n' - sendmail(subject, message) + #sendmail(subject, message) return HttpResponse(json.dumps(mem.get_dict())) except ValueError: return HttpResponseBadRequest('{"error" : "Invalid parameters supplied"}') diff --git a/requirements.txt b/requirements.txt index 39bb1aa..43a6d84 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,3 +14,4 @@ paramiko==2.0.2 qrcode==5.3 Pillow==3.3.1 requests==2.11.1 +django-nocaptcha-recaptcha==0.0.19 diff --git a/sikweb/urls.py b/sikweb/urls.py index 17c3ca8..13ffd1f 100644 --- a/sikweb/urls.py +++ b/sikweb/urls.py @@ -47,6 +47,7 @@ from infoscreen.views import createSossoItem from infoscreen.views import admin as infoscreen_admin #application from members.views import applicationindex +from members.views import applicationSuccessIndex urlpatterns = [ # main @@ -83,4 +84,5 @@ urlpatterns = [ url(r'^infoscreen/admin$', infoscreen_admin), #application url(r'^application/$', applicationindex), + url(r'^application/success$', applicationSuccessIndex), ]