diff --git a/lemonldap-ng-portal/site/coffee/totpregistration.coffee b/lemonldap-ng-portal/site/coffee/totpregistration.coffee index ec2d97c87..5244fedf6 100644 --- a/lemonldap-ng-portal/site/coffee/totpregistration.coffee +++ b/lemonldap-ng-portal/site/coffee/totpregistration.coffee @@ -31,11 +31,15 @@ getKey = (reset) -> # Display key and QR code success: (data) -> if data.error + if data.error.match /totpExistingKey/ + console.log 'ErrorTOTP:', data.error + $("#divToHide").hide() return setMsg data.error, 'warning' unless data.portal and data.user and data.secret return setMsg('PE24', 'danger') # Generate OTP url + $("#divToHide").show() s = "otpauth://totp/#{escape(data.portal)}:#{escape(data.user)}?secret=#{data.secret}&issuer=#{escape(data.portal)}" if data.digits != 6 s += "&digits=#{data.digits}" diff --git a/lemonldap-ng-portal/site/htdocs/static/common/js/totpregistration.js b/lemonldap-ng-portal/site/htdocs/static/common/js/totpregistration.js index b7ded1416..612c5ace7 100644 --- a/lemonldap-ng-portal/site/htdocs/static/common/js/totpregistration.js +++ b/lemonldap-ng-portal/site/htdocs/static/common/js/totpregistration.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.12.7 +// Generated by CoffeeScript 1.9.3 /* LemonLDAP::NG TOTP registration script @@ -43,11 +43,16 @@ LemonLDAP::NG TOTP registration script success: function(data) { var qr, s; if (data.error) { + if (data.error.match(/totpExistingKey/)) { + console.log('ErrorTOTP:', data.error); + $("#divToHide").hide(); + } return setMsg(data.error, 'warning'); } if (!(data.portal && data.user && data.secret)) { return setMsg('PE24', 'danger'); } + $("#divToHide").show(); s = "otpauth://totp/" + (escape(data.portal)) + ":" + (escape(data.user)) + "?secret=" + data.secret + "&issuer=" + (escape(data.portal)); if (data.digits !== 6) { s += "&digits=" + data.digits; diff --git a/lemonldap-ng-portal/site/htdocs/static/common/js/totpregistration.min.js b/lemonldap-ng-portal/site/htdocs/static/common/js/totpregistration.min.js index df39fe841..cf3366621 100644 --- a/lemonldap-ng-portal/site/htdocs/static/common/js/totpregistration.min.js +++ b/lemonldap-ng-portal/site/htdocs/static/common/js/totpregistration.min.js @@ -1 +1 @@ -(function(){var a,b,d,c,e;d=function(f,g){$("#msg").html(window.translate(f));$("#color").removeClass("message-positive message-warning message-danger alert-success alert-warning alert-danger");$("#color").addClass("message-"+g);if(g==="positive"){g="success"}return $("#color").addClass("alert-"+g)};a=function(g,f,i){var h;console.log("Error",i);h=JSON.parse(g.responseText);if(h&&h.error){h=h.error.replace(/.* /,"");console.log("Returned error",h);return d(h,"warning")}};c="";b=function(f){d("yourTotpKey","warning");return $.ajax({type:"POST",url:portal+"/2fregisters/totp/getkey",dataType:"json",data:{newkey:f},error:a,success:function(i){var g,h;if(i.error){return d(i.error,"warning")}if(!(i.portal&&i.user&&i.secret)){return d("PE24","danger")}h="otpauth://totp/"+(escape(i.portal))+":"+(escape(i.user))+"?secret="+i.secret+"&issuer="+(escape(i.portal));if(i.digits!==6){h+="&digits="+i.digits}if(i.interval!==30){h+="&period="+i.interval}g=new QRious({element:document.getElementById("qr"),value:h,size:150});$("#serialized").text(h);if(i.newkey){d("yourNewTotpKey","warning")}else{d("yourTotpKey","success")}return c=i.token}})};e=function(){var f;f=$("#code").val();if(!f){return d("fillTheForm","warning")}else{return $.ajax({type:"POST",url:portal+"/2fregisters/totp/verify",dataType:"json",data:{token:c,code:f,TOTPName:$("#TOTPName").val()},error:a,success:function(g){if(g.error){if(g.error.match(/badCode/)){return d("badCode","warning")}else{return d(g.error,"danger")}}else{return d("yourKeyIsRegistered","success")}}})}};$(document).ready(function(){b(0);$("#changekey").on("click",function(){return b(1)});return $("#verify").on("click",function(){return e()})})}).call(this); \ No newline at end of file +(function(){var a,b,d,c,e;d=function(f,g){$("#msg").html(window.translate(f));$("#color").removeClass("message-positive message-warning message-danger alert-success alert-warning alert-danger");$("#color").addClass("message-"+g);if(g==="positive"){g="success"}return $("#color").addClass("alert-"+g)};a=function(g,f,i){var h;console.log("Error",i);h=JSON.parse(g.responseText);if(h&&h.error){h=h.error.replace(/.* /,"");console.log("Returned error",h);return d(h,"warning")}};c="";b=function(f){d("yourTotpKey","warning");return $.ajax({type:"POST",url:portal+"/2fregisters/totp/getkey",dataType:"json",data:{newkey:f},error:a,success:function(i){var g,h;if(i.error){if(i.error.match(/totpExistingKey/)){console.log("ErrorTOTP:",i.error);$("#divToHide").hide()}return d(i.error,"warning")}if(!(i.portal&&i.user&&i.secret)){return d("PE24","danger")}$("#divToHide").show();h="otpauth://totp/"+(escape(i.portal))+":"+(escape(i.user))+"?secret="+i.secret+"&issuer="+(escape(i.portal));if(i.digits!==6){h+="&digits="+i.digits}if(i.interval!==30){h+="&period="+i.interval}g=new QRious({element:document.getElementById("qr"),value:h,size:150});$("#serialized").text(h);if(i.newkey){d("yourNewTotpKey","warning")}else{d("yourTotpKey","success")}return c=i.token}})};e=function(){var f;f=$("#code").val();if(!f){return d("fillTheForm","warning")}else{return $.ajax({type:"POST",url:portal+"/2fregisters/totp/verify",dataType:"json",data:{token:c,code:f,TOTPName:$("#TOTPName").val()},error:a,success:function(g){if(g.error){if(g.error.match(/badCode/)){return d("badCode","warning")}else{return d(g.error,"danger")}}else{return d("yourKeyIsRegistered","success")}}})}};$(document).ready(function(){b(0);$("#changekey").on("click",function(){return b(1)});return $("#verify").on("click",function(){return e()})})}).call(this); \ No newline at end of file diff --git a/lemonldap-ng-portal/site/templates/bootstrap/totp2fregister.tpl b/lemonldap-ng-portal/site/templates/bootstrap/totp2fregister.tpl index 7a6f56848..c317485ac 100644 --- a/lemonldap-ng-portal/site/templates/bootstrap/totp2fregister.tpl +++ b/lemonldap-ng-portal/site/templates/bootstrap/totp2fregister.tpl @@ -7,11 +7,13 @@
-
- -
-      
-
+ +
+ +
+        
+
+
Name :