Skip to content

Instantly share code, notes, and snippets.

@eugeniop
Created September 22, 2013 23:18
Show Gist options
  • Save eugeniop/6664806 to your computer and use it in GitHub Desktop.
Save eugeniop/6664806 to your computer and use it in GitHub Desktop.
Simolpe sample suing the "headless" Login Widget.
<html>
<head></head>
<body>
<h1>Headless</h1>
<% include header %>
<br><br>
<h3>Sign In</h3>
<hr />
<div class="signin">
<button class="signin-google">Sign In with Google</button>
<br/>
<br/>
<input type="text" id="username" placeholder="username"> <br/>
<input type="password" id="password" placeholder="password">
</div>
<button class="signin-db">Sign In with DB</button>
<h3>Sign Up</h3>
<hr />
<div class="signup">
<input type="text" id="username" placeholder="username"> <br/>
<input type="password" id="password" placeholder="password">
</div>
<button class="signup-db">Sign Up with DB</button>
<h3>Change Password</h3>
<hr />
<div class="resetPass">
<input type="text" id="username" placeholder="username"> <br/>
<input type="password" id="password" placeholder="new password">
</div>
<button class="resetPass-db">Change Password with DB</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script id="auth0" src="<%= auth0Url %>/auth0.js#mode=headless&amp;client=<%= clientID %>&amp;cdn=<%= auth0CDN %>&amp;assets=<%= auth0Assets %>"></script>
<script>
$(function() {
$('.signin-google').on('click', function() {
window.Auth0.signIn({connection: 'google-oauth2'});
});
$('.signin-google, .signin-db, .signup-db, .resetPass-db').hide();
var dbConnectionName = 'Username-Password-Authentication';
// signin
$('.signin-db').on('click', function() {
window.Auth0.signIn({
connection: dbConnectionName,
username: $('.signin #username').val(),
password: $('.signin #password').val(),
error: function(response) {
alert('signin error - ' + response.text);
console.log(response);
}
});
});
// signup
$('.signup-db').on('click', function() {
window.Auth0.signUp({
connection: dbConnectionName,
username: $('.signup #username').val(),
password: $('.signup #password').val(),
error: function(response) {
alert('signup error - ' + response.text);
console.log(response);
},
success: function(response) {
alert('success - ' + response.text);
}
});
});
// change password
$('.resetPass-db').on('click', function() {
window.Auth0.resetPassword({
connection: dbConnectionName,
username: $('.resetPass #username').val(),
password: $('.resetPass #password').val(),
error: function(response) {
alert('change password error - ' + response.text);
console.log(response);
},
success: function(response) {
alert('success! ' + response.text);
console.log(response);
}
});
});
})
window.Auth0.ready(function() {
$('.signin-google, .signin-db, .signup-db, .resetPass-db').show();
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment