Created
May 9, 2017 19:31
-
-
Save chenkie/300982172a4639ebacfac7e062bd5be5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | |
<title>Sign In with Auth0</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> | |
</head> | |
<style> | |
body, html { | |
height: 100%; | |
background-color: #f9f9f9; | |
} | |
.login-container { | |
position: relative; | |
height: 100%; | |
} | |
.login-box { | |
position: absolute; | |
top: 50%; | |
transform: translateY(-50%); | |
padding: 15px; | |
background-color: #fff; | |
box-shadow: 0px 5px 5px #ccc; | |
border-radius: 5px; | |
border-top: 1px solid #e9e9e9; | |
} | |
.login-header { | |
text-align: center; | |
} | |
.login-header img { | |
width: 75px; | |
} | |
#error-message { | |
display: none; | |
} | |
</style> | |
<body> | |
<div class="login-container"> | |
<div class="col-xs-12 col-sm-4 col-sm-offset-4 login-box"> | |
<div class="login-header"> | |
<img src="https://cdn.auth0.com/styleguide/1.0.0/img/badge.svg"/> | |
<h3>Welcome</h3> | |
<h5>PLEASE LOG IN</h5> | |
</div> | |
<div id="error-message" class="alert alert-danger"></div> | |
<form> | |
<div class="form-group"> | |
<label for="name">Email</label> | |
<input | |
type="text" | |
class="form-control" | |
id="email" | |
placeholder="Enter your email"> | |
</div> | |
<div class="form-group"> | |
<label for="name">Password</label> | |
<input | |
type="password" | |
class="form-control" | |
id="password" | |
placeholder="Enter your password"> | |
</div> | |
<button | |
type="submit" | |
id="btn-login" | |
class="btn btn-primary btn-block"> | |
Log In | |
</button> | |
<button | |
type="button" | |
id="btn-signup" | |
class="btn btn-default btn-block"> | |
Sign Up | |
</button> | |
<hr> | |
<button | |
type="button" | |
id="btn-google" | |
class="btn btn-default btn-danger btn-block"> | |
Log In with Google | |
</button> | |
</form> | |
</div> | |
</div> | |
<!--[if IE 8]> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/ie8/0.2.5/ie8.js"></script> | |
<![endif]--> | |
<!--[if lte IE 9]> | |
<script src="https://cdn.auth0.com/js/base64.js"></script> | |
<script src="https://cdn.auth0.com/js/es5-shim.min.js"></script> | |
<![endif]--> | |
<script src="https://cdn.auth0.com/js/auth0/8.6/auth0.min.js"></script> | |
<script src="https://cdn.polyfill.io/v2/polyfill.js?features=Object.assign|always"></script> | |
<script> | |
window.addEventListener('load', function() { | |
var config = JSON.parse( | |
decodeURIComponent(escape(window.atob('@@config@@'))) | |
); | |
var webAuth = new auth0.WebAuth({ | |
domain: config.auth0Domain, | |
clientID: config.clientID, | |
redirectUri: config.callbackURL, | |
audience: config.extraParams.audience, | |
responseType: config.extraParams.response_type, | |
scope: config.extraParams.scope | |
}); | |
function login(e) { | |
e.preventDefault(); | |
var username = document.getElementById('email').value; | |
var password = document.getElementById('password').value; | |
var loginOptions = Object.assign({ | |
connection: 'Username-Password-Authentication', | |
username: username, | |
password: password | |
}, config.internalOptions); | |
webAuth.redirect.loginWithCredentials(loginOptions, function(err) { | |
if (err) displayError(err); | |
}); | |
} | |
function signup() { | |
var email = document.getElementById('email').value; | |
var password = document.getElementById('password').value; | |
var signupOptions = Object.assign({ | |
connection: 'Username-Password-Authentication', | |
email: email, | |
password: password | |
}, config.internalOptions); | |
webAuth.redirect.signupAndLogin(signupOptions, function(err) { | |
if (err) displayError(err); | |
}); | |
} | |
function loginWithGoogle() { | |
var loginOptions = Object.assign({ | |
connection: 'google-oauth2' | |
}, config.internalOptions); | |
webAuth.authorize(loginOptions, function(err) { | |
if (err) displayError(err); | |
}); | |
} | |
function displayError(err) { | |
var errorMessage = document.getElementById('error-message'); | |
errorMessage.innerHTML = err.description; | |
errorMessage.style.display = 'block'; | |
} | |
document.getElementById('btn-login').addEventListener('click', login); | |
document.getElementById('btn-google').addEventListener('click', loginWithGoogle); | |
document.getElementById('btn-signup').addEventListener('click', signup); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment