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
/** | |
* Flattens an array of arbitrarily nested arrays into a flat array. | |
* E.g. [[1,2,[3]],4] -> [1,2,3,4]. | |
* @param {array} array Array to be flatten. | |
*/ | |
function flatten(array) { | |
/** | |
* Checks if the given array has any nested array. | |
* @param {array} array Array to check if it is flat. | |
*/ |
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
/** | |
* Cognito signOut function wrapped inside a promise. | |
*/ | |
function signOut() { | |
User || (User = UserPool.getCurrentUser()) | |
if (!User) { | |
return Promise.reject('Current user session not found'); | |
} | |
return Promise.resolve(User.signOut()); | |
} |
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
/** | |
* Function to handle the display of the Welcome function only for authenticated | |
* users. If they are not authenticated, or an error occurs, we'll redirect them | |
* to the login page. | |
*/ | |
EventEmitter.on('Welcome:mount', function() { | |
// Check if the user is authenticated. | |
Cognito.isAuthenticated() | |
.then(function() { | |
// Mount the component on the DOM. |
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
/** | |
* Function to get a valid current user session from localstorage. | |
*/ | |
function getSession() { | |
User || (User = UserPool.getCurrentUser()); | |
return new Promise(function(resolve, reject) { | |
if (User === null) { | |
reject('No current session found.'); | |
return; | |
} |
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
/** | |
* Email confirmation function that uses AWS Cognito SDK. | |
* It wraps its API into a promise to better consume it from other parts of | |
* the application. | |
*/ | |
function confirm(username, code) { | |
User = new CognitoUser({ | |
Username : username, | |
Pool: UserPool, | |
}); |
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
/** | |
* Signup function that uses AWS Cognito SDK. It wraps its API into a promise | |
* to consume it easily from other parts of the app. | |
*/ | |
function logIn(username, password) { | |
var authenticationDetails = new AuthenticationDetails({ | |
Username: username, | |
Password: password, | |
}); | |
User = new CognitoUser({ |
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
/** | |
* Signup function that uses AWS Cognito SDK. It wraps its API into a promise | |
* to consume it easily from other parts of the app. | |
*/ | |
function signUp(email, password) { | |
var attributes = [new CognitoUserAttribute({ | |
Name: 'email', | |
Value: email, | |
})] | |
return new Promise(function(resolve, reject) { |
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
<script type="text/html" id="SignupForm"> | |
<div class="SignupForm"> | |
<div class="title">Sign Up</div> | |
<form class="form"> | |
<div class="Control"> | |
<label class="Control__label" for="user">User</label> | |
<input class="Control__input" name="user" type="text" placeholder="User" /> | |
</div> | |
<div class="Control"> | |
<label class="Control__label" for="password">Password</label> |
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
(function(EventEmitter, tmpl) { | |
var $root = document.getElementById('root'), | |
$container = document.createElement('div'), | |
$loginLink; | |
function handleLoginLink(event) { | |
event.preventDefault(); | |
EventEmitter.emit('SignupForm:unmount') | |
EventEmitter.emit('LoginForm:mount') |
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
(function(ready, EventEmitter) { | |
ready(function() { | |
EventEmitter.emit('LoginForm:mount') | |
}) | |
})(window.ready, window.EventEmitter) |