Skip to content

Commit

Permalink
stub out authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
lloyd committed Oct 12, 2011
1 parent 1f052d8 commit f213549
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
24 changes: 24 additions & 0 deletions static/index.html
Expand Up @@ -56,6 +56,16 @@
margin-top: 5em;
}

#manage {
display: none;
}

#sign_in > img {
margin-top: .5em;
margin-left: 1em;
cursor: pointer;
}

</style>
</head>
<body>
Expand All @@ -74,6 +84,20 @@ <h1 id="title">MozHacks.org</h1>
</div>

<div id="manage">
<div id="auth">
<p>
Want to add or manage hacks? All you need is a <strong>mozilla.{org,com}</strong>,
email address.
</p>
<p>
Sign in to get started:
<span id="sign_in">
<img src="i/sign_in_blue.png" alt="BrowserID"></a>
</span>
</p>
</div>
<div id="control">
</div>
</div>

</body>
Expand Down
50 changes: 50 additions & 0 deletions static/js/main.js
@@ -1,4 +1,54 @@
function displayManage() {
$.get('/api/whoami', function (res) {
if (res === null) {
$("#auth").show();
} else {
showControl();
}
}, 'json');
}

function showControl() {
alert("now you get the control pane!");
}

// a handler that is passed an assertion after the user logs in via the
// browserid dialog
function gotVerifiedEmail(assertion) {
// got an assertion, now send it up to the server for verification
if (assertion !== null) {
$.ajax({
type: 'POST',
url: '/api/login',
data: { assertion: assertion },
success: function(res, status, xhr) {
showControl();
},
error: function(res, status, xhr) {
alert("login failure" + res);
}
});
}
}

// at startup let's check to see whether we're authenticated to
// myfavoritebeer (have existing cookie), and update the UI accordingly
$(document).ready(function() {

// when the user clicks on 'add a hack'...
$("#add_a_hack").click(function() {
$("#manage > *").hide();
$("#overview").fadeOut(200, function() {
$("#manage").fadeIn(200);
});

// hit the api to see which div to display
displayManage();
});

// when the user clicks sign in from the manage page...
$("#sign_in").click(function() {
navigator.id.getVerifiedEmail(gotVerifiedEmail);
});

});

0 comments on commit f213549

Please sign in to comment.