forked from thinkphp/browserID-MooTools
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ported https://github.com/thinkphp/browserID-MooTools to jquery
- Loading branch information
Showing
13 changed files
with
249 additions
and
378 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,43 @@ | ||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> | ||
<title>Plugin BrowserID MooTools</title> | ||
<style type="text/css"> | ||
h1,h2,h3,body { font-family:'gill sans','dejavu sans',verdana,sans-serif; } | ||
h1 { font-family:menlo,'dejavu sans mono',monospace; } | ||
h1 { | ||
font-weight:bold; | ||
font-size:43px; | ||
letter-spacing: -1px; | ||
color:#000; | ||
margin-bottom:0; | ||
position:relative; | ||
} | ||
button{border:none;background:transparent;margin:0 2em;} | ||
</style> | ||
<script src="http://www.google.com/jsapi?key=ABQIAAAA1XbMiDxx_BTCY2_FkPh06RRaGTYH6UMl8mADNa0YKuWNNa8VNxQEerTAUcfkyrr6OwBovxn7TDAH5Q"></script> | ||
<script type="text/javascript">google.load("mootools", "1.4");</script> | ||
<script src="https://browserid.org/include.js"></script> | ||
<script src="browserID-yui-compressed.js"></script> | ||
<script type="text/javascript"> | ||
<title>Demo for jquery-browserID plugin</title> | ||
|
||
window.addEvent('domready', function(){ | ||
$('login').addEvent('click',function(){ | ||
navigator.id.getVerifiedEmail(function(assertion){ | ||
if(assertion) { | ||
//got an assertion, now send it up to the server for verification | ||
verify(assertion); | ||
} else { | ||
alert("I still don't know you"); | ||
} | ||
}); | ||
}); | ||
}); | ||
<style type="text/css"> | ||
.browserid-login{ | ||
border: 0; | ||
width: 185px; | ||
height: 25px; | ||
cursor: pointer; | ||
background: url(https://developer.mozilla.org/files/3963/persona_sign_in_blue.png); | ||
text-indent: -9999px; | ||
} | ||
.browserid-logout{ | ||
|
||
function verify(assertion) { | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
|
||
var browserid = new BrowserID(assertion, { | ||
onComplete: function(response){ | ||
//if the server successfully verifies the assertion we | ||
//updating the UI by calling 'loggedIn()' | ||
if(response.status == 'okay') { | ||
loggedIn(response.email) | ||
//otherwise we handle the login failure | ||
} else { | ||
failure(response) | ||
} | ||
} | ||
}) | ||
} | ||
<h1>Demo for jquery-browserID plugin</h1> | ||
<button id="login"></button> | ||
|
||
function loggedIn(email) { | ||
//do stuff with email | ||
var p = new Element('p').set('text','Logged In as: ' + email) | ||
$('login').parentNode.replaceChild(p,$('login')) | ||
} | ||
<!--put the scripts in the bottom like a good front ender would--> | ||
|
||
function failure(f) { | ||
//do stuff with failure | ||
alert('Failure reason: ' + f.reason) | ||
} | ||
<!-- Check for support for browserid in the browser, fallback to loading the polyfill --> | ||
<script>navigator.id || document.write('<script src="//browserid.org/include.js"><\/script>')</script> | ||
<!-- Load jquery from google's CDN + fallback - stolen from h5bp.com--> | ||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> | ||
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.8.3.min.js"><\/script>')</script> | ||
<!--Load our browserid.jquery.js file--> | ||
<script src="jquery.browserid.js"></script> | ||
|
||
</script> | ||
</head> | ||
<body> | ||
<h1>Plugin BrowserID MooTools</h1> | ||
<button id="login"><img src="https://browserid.org/i/sign_in_green.png" alt="sign in with browser ID"></button> | ||
<script> | ||
$('#login').browserID({ | ||
onlogin : function(something){ | ||
console.log(something); | ||
} | ||
}); | ||
</script> | ||
</body> | ||
</html> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* Description : This is a jQuery client library for the BrowserID Protocol. | ||
* Created by Alex Wolkov (alexw.me) . | ||
*/ | ||
|
||
(function ($) { | ||
var options = { | ||
assertion : null, | ||
email : null, | ||
login_button_class : 'browserid-login', | ||
logout_button_class : 'browserid-logout', | ||
onlogin : null, | ||
onfail : null, | ||
onlogout : null, | ||
server : 'login.php' | ||
} | ||
var methods = { | ||
init : function (settings) { | ||
if(typeof settings === 'object'){ | ||
$.extend(options, settings); | ||
} | ||
this.addClass(options.login_button_class).on('click.login', _login); | ||
}, | ||
getEmail:function () { | ||
return options.email; | ||
} | ||
} | ||
var _login = function () { | ||
var $el = $(this); | ||
navigator.id.get(function (assertion) { | ||
if (assertion) { | ||
options.assertion = assertion; | ||
//got an assertion, now send it up to the server for verification | ||
_verify_assertion.apply($el); | ||
}else{ | ||
if(typeof options.onfail === 'function') { | ||
options.onfail.apply(this); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
var _logout = function () { | ||
navigator.id.logout(); | ||
options.assertion = null; | ||
options.email = null; | ||
$(this).removeClass(options.logout_button_class).removeClass(options.login_button_class); | ||
|
||
methods.init.apply($(this)); | ||
if(typeof options.onlogout === 'function') { | ||
options.onlogout.apply(this); | ||
} | ||
} | ||
|
||
var _verify_assertion = function(){ | ||
var $el = this; | ||
|
||
$.getJSON(options.server, {assertion:options.assertion}, function (response) { | ||
if(response.status && response.status == 'okay'){ | ||
options.email = response.email; | ||
$el.removeClass(options.login_button_class).addClass('options.logout_button_class').text('Logout ('+ response.email +')'); | ||
$el.off('click.login').on('click.logout',_logout); | ||
|
||
if(typeof options.onlogin === 'function') { | ||
options.onlogin.apply(this); | ||
} | ||
}else if(response.status !== 'okay'){ | ||
if(typeof options.onfail === 'function') { | ||
options.onfail.apply(response); | ||
} | ||
} | ||
}) | ||
} | ||
|
||
$.fn.browserID = function (method) { | ||
|
||
// Method calling logic | ||
if (methods[method]) { | ||
|
||
return methods[ method ].apply(this, Array.prototype.slice.call(arguments, 1)); | ||
} else if (typeof method === 'object' || !method) { | ||
|
||
return methods.init.apply(this, arguments); | ||
} | ||
} | ||
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,31 @@ | ||
Class: BrowserID {#BrowserID} | ||
============================== | ||
|
||
This is a MooTools client library for the BrowserID Protocol. BrowserID is a new way for users to log into web sites using their email address. | ||
This is a jquery plugin for the BrowserID Protocol. BrowserID is a new way for users to log into web sites using their email address. | ||
It aims to provide a secure way of proving your identity to servers across the internet, without having to create separate usernames and passwords each time. | ||
Instead of a new username, it uses your email address as you identity which allows it to be descentralized since anyone can send you an | ||
email verification message. | ||
|
||
### Syntax: | ||
|
||
var browserID = new BrowserID(assertion, options); | ||
|
||
``` | ||
$('<your button element>').browserid([options]); | ||
``` | ||
### Arguments: | ||
|
||
- assertion `String` - a string containing a signed claim that proves the user is who they say they are. | ||
|
||
- options `object` - The options for the BrowserID instance. | ||
|
||
### Events | ||
|
||
### onRequest | ||
|
||
* `function` Function to execute when you make a request. | ||
|
||
### Signature | ||
|
||
onRequest(); | ||
|
||
### onComplete | ||
|
||
* `function` Function to execute when the request is completed. | ||
|
||
### Signature | ||
|
||
onComplete(response); | ||
|
||
####Example options : | ||
``` | ||
var options = { | ||
onlogin : function(response){ ... }, | ||
onfail : function(response){ ... }, | ||
onlogout : function(response){ ... }, | ||
server : 'login.php' /* this is the verifier server url - attached in login.php */ | ||
} | ||
``` | ||
### Arguments | ||
|
||
- `object` The verifier will check that the assertion was meant for your website and is valid | ||
returns => {status: 'okay','email': 'user@mozilla.com'}, | ||
otherwise returns {status: 'failure','reason': 'audience missmatch'}, | ||
|
||
|
Oops, something went wrong.