diff --git a/browserid/static/js/browserid.js b/browserid/static/js/browserid.js index c6d11d79590358d2b4f79824eeeea7f29cc39b1e..8b3ed8e61e0071251b5e93910976502ad063c3ed 100644 --- a/browserid/static/js/browserid.js +++ b/browserid/static/js/browserid.js @@ -37,6 +37,10 @@ $(function() { "use strict"; + /** + * For the main page + */ + if ($('#vAlign').length) { $(window).bind('resize', function() { $('#vAlign').css({'height' : $(window).height() }); }).trigger('resize'); } @@ -224,81 +228,70 @@ $(function() { } } } -}); -/* -======= - $(function() { - BrowserIDIdentities.checkAuthenticationAndSync(function onSuccess(authenticated) { - if (authenticated) { - $("body").addClass("authenticated"); - } - }, function onComplete(authenticated) { - if (authenticated && $('#emailList').length) { - display_saved_ids(); - } - }); - }); - function display_saved_ids() - { - $('#cancellink').click(function() { - if (confirm('Are you sure you want to cancel your account?')) { - BrowserIDIdentities.cancelUser(function() { - document.location="/"; - }); - } + /** + * For the prove page + */ + function getParameterByName( name ) { + name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); + var regexS = "[\\?&]"+name+"=([^&#]*)"; + var regex = new RegExp( regexS ); + var results = regex.exec( window.location.href ); + if( results == null ) + return ""; + else + return decodeURIComponent(results[1].replace(/\+/g, " ")); + } + + function emailRegistrationSuccess() { + $("div.status").text("Address confirmed!"); + $("body").delay(1000).fadeOut(500, function() { + // if the close didn't work, then let's redirect the the main page where they'll + // get to see the ids that they've created. + document.location = '/'; }); + } - $("#emailList").empty(); - var emails = BrowserIDIdentities.getStoredEmailKeypairs(); - _(emails).each(function(data, e) { - var block = $("<div>").addClass("emailblock"); - var label = $("<div>").addClass("email").text(e); - var meta = $("<div>").addClass("meta"); + function emailRegistrationFailure(why) { + $("div.status").text("Error encountered while attempting to confirm your address. Have you previously verified this address?"); + } - var pub = $("<div class='keyblock'>").hide(); - - var keyText = data.pub.value; - pub.text(keyText); - - var linkblock = $("<div>"); - var puba = $("<a>").text("[show public key]"); - // var priva = $("<a>").text("[show private key]"); - puba.click(function() {pub.show();}); - // priva.click(function() {priv.show()}); - linkblock.append(puba); - // linkblock.append(" / "); - // linkblock.append(priva); - - var deauth = $("<button>").text("Forget this Email"); - meta.append(deauth); - deauth.click(function(data) { - // If it is a primary, we do not have to go back to the server. - // XXX put this into the BrowserIDIdentities abstraction - if (data.isPrimary) { - BrowserIDStorage.removeEmail(e); - display_saved_ids(); - } - else { - // remove email from server - BrowserIDIdentities.removeIdentity(e, display_saved_ids); + var token = getParameterByName("token"), + path = document.location.pathname; + + if (token && path === "/prove") { + BrowserIDNetwork.completeEmailRegistration(token, function onSuccess(valid) { + if (valid) { + emailRegistrationSuccess(); + } else { + emailRegistrationFailure("unknown"); } - }.bind(null, data)); - - var d = new Date(data.created); - var datestamp = $("<div class='date'>").text("Signed in at " + d.toLocaleString()); - - meta.append(datestamp); - meta.append(linkblock); - - block.append(label); - block.append(meta); - // block.append(priv); - block.append(pub); - - $("#emailList").append(block); + + }, function onFailure() { + failure("Error Communicating With Server!"); }); } -}()); - */ + + + if(token && path === "/verify") { + $("#signUpForm").submit(function(event) { + event.preventDefault(); + + var email = $("#email").val(), + pass = $("#password").val(), + pass2 = $("#vpassword").val(); + + if (pass && pass === pass2) { + BrowserIDNetwork.completeUserRegistration(token, pass, function onSuccess(registered) { + if (registered) { + $("#congrats").fadeIn(250); + } + }, function onFailure() { + + }); + } + }); + } +}); + diff --git a/browserid/views/prove.ejs b/browserid/views/prove.ejs index 17439c745cfb5ba0b5714d53c78af35e39cc9bef..f79ec80a97f98138c2fc3c63900d9f3e580182bf 100644 --- a/browserid/views/prove.ejs +++ b/browserid/views/prove.ejs @@ -8,44 +8,3 @@ One moment while we attempt to confirm your email address... </div> </div> -<script> -function getParameterByName( name ) -{ - name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); - var regexS = "[\\?&]"+name+"=([^&#]*)"; - var regex = new RegExp( regexS ); - var results = regex.exec( window.location.href ); - if( results == null ) - return ""; - else - return decodeURIComponent(results[1].replace(/\+/g, " ")); -} - -function success() { - $("div.status").text("Address confirmed!"); - $("body").delay(1000).fadeOut(500, function() { - // if the close didn't work, then let's redirect the the main page where they'll - // get to see the ids that they've created. - document.location = '/'; - }); -} - -function failure(why) { - $("div.status").text("Error encountered while attempting to confirm your address. Have you previously verified this address?"); -} - -$(function() { - var token = getParameterByName("token"); - BrowserIDNetwork.completeEmailRegistration(token, function onSuccess(valid) { - if (valid) { - success(); - } else { - failure("unknown"); - } - - }, function onFailure() { - failure("Error Communicating With Server!"); - }); -}); - -</script> diff --git a/browserid/views/verify.ejs b/browserid/views/verify.ejs index 9f4b3a2ae739b780b5543b75f14835296b4cf3b5..6a6293d0c73052a19246f03c646787e9bef87895 100644 --- a/browserid/views/verify.ejs +++ b/browserid/views/verify.ejs @@ -1,32 +1,31 @@ - <div id="vAlign"> - <div id="signUpFormWrap"> - <!-- XXX this form submits to nowhere --> - <form id="signUpForm" class="cf"> - <p class="hint">Finish signing into <span class="website"><strong>http://www.nytimes.com</strong></span></p> - <h1 class="serif">Last step!</h1> - <ul class="inputs"> - <li> - <label class="serif" for="email">Email Address</label> - <input class="youraddress sans" id="email" placeholder="Your Email" type="email" disabled="disabled"> - </li> - <li> - <label class="serif" for="password">New Password</label> - <input class="sans" id="password" placeholder="Enter a Password" type="password" autofocus> - </li> - <li> - <label class="serif" for="vpassword">Verify Password</label> - <input class="sans" id="vpassword" placeholder="Repeat Password" type="password"> - </li> - </ul> - <div class="submit cf"> - <input type="submit" class="create" value="Finish"/> - </div> - </form> - - <div id="congrats"> - <p class="serif">Thank you signing up with <strong>BrowserID</strong>. You can now use your <strong>BrowserID</strong> account to <em>Sign In</em> or <em>Sign Up</em> to websites all across the web!</p> - </div> - - </div> +<div id="vAlign"> + <div id="signUpFormWrap"> + <form id="signUpForm" class="cf"> + <p class="hint">Finish signing into <span class="website"><strong>http://www.nytimes.com</strong></span></p> + <h1 class="serif">Last step!</h1> + <ul class="inputs"> + <li> + <label class="serif" for="email">Email Address</label> + <input class="youraddress sans" id="email" placeholder="Your Email" type="email" disabled="disabled"> + </li> + <li> + <label class="serif" for="password">New Password</label> + <input required class="sans" id="password" placeholder="Enter a Password" type="password" autofocus> + </li> + <li> + <label class="serif" for="vpassword">Verify Password</label> + <input required class="sans" id="vpassword" placeholder="Repeat Password" type="password"> + </li> + </ul> + <div class="submit cf"> + <input type="submit" class="create" value="Finish"/> + </div> + </form> + + <div id="congrats"> + <p class="serif">Thank you signing up with <strong>BrowserID</strong>. You can now use your <strong>BrowserID</strong> account to <em>Sign In</em> or <em>Sign Up</em> to websites all across the web!</p> </div> + + </div> +</div>