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
{ | |
"rules": { | |
"profiles": { | |
"$uid": { | |
// grants write access to the owner of this user account whose uid must exactly match the key ($uid) | |
".write": "auth !== null && auth.uid === $uid", | |
// grants read access to any user who is logged in with an email and password | |
".read": "auth !== null && auth.provider === 'password'" | |
} |
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
dbRef.createUser({ | |
email : $('#registerEmail').val(), //get the email from Form | |
password : $('#registerPassword').val() //get the pass from Form | |
}, function(error, userData) { | |
if (error) { | |
console.log("Error creating user:", error); | |
} else { | |
console.log("Successfully created user account with uid:", userData.uid); | |
} | |
}); |
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
dbRef.authWithPassword({ | |
email : $('#loginEmail').val(), | |
password : $('#loginPassword').val() | |
}, function(error, authData) { | |
if (error) { | |
console.log("Login Failed!", error); | |
} else { | |
console.log("Authenticated successfully with payload:", authData); | |
auth = authData; | |
} |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> | |
<title>Time to Hack: Simple Login with Firebase Web API</title> | |
<!-- Latest compiled and minified CSS --> | |
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> |
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
//create firebase reference | |
var dbRef = new Firebase("https://contactsbooks.firebaseio.com/"); | |
var contactsRef = dbRef.child('contacts') | |
var usersRef = dbRef.child('users') | |
var auth = null; | |
//Register | |
$('#doRegister').on('click', function (e) { | |
e.preventDefault(); | |
$('#registerModal').modal('hide'); | |
$('#messageModalLabel').html('<span class="text-center text-info"><i class="fa fa-cog fa-spin"></i></span>'); |
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
var app = angular.module( 'contactApp', ['ngRoute'] ); | |
app.config(['$routeProvider', | |
function($routeProvider) { | |
$routeProvider. | |
when('/contacts', { | |
templateUrl: 'partials/contacts.html', | |
controller: 'ContactsController' | |
}). | |
when('/contacts/:contactId', { |
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
contactStore | |
+ css | |
- style.css | |
- ... | |
+ js | |
+ partials | |
- newContact.html | |
- contacts.html | |
- ... | |
- app.js |
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
var app = angular.module( 'contactApp', ['ngRoute'] ); | |
app | |
.config(['$routeProvider', | |
function($routeProvider) { | |
$routeProvider | |
.when('/contacts', { | |
templateUrl: 'js/partials/contacts.html', | |
controller: 'ContactsController' | |
}) |
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
app | |
.controller('ContactsController', ['storage', '$scope', '$window', function(storage, $scope, $window){ | |
$scope.contacts = []; | |
if( $scope.contacts.length == 0){ | |
$scope.contacts = JSON.parse( storage.recall( 'contacts' ) ); | |
} | |
$scope.deleteContact = function (index) { | |
var areYouSure = $window.confirm('Are you sure about deleting this contact?'); | |
if( areYouSure ){ | |
$scope.contacts.splice( index, 1); |
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
<div> | |
<ul class="list-group contacts"> | |
<li class="list-group-item" ng-if="contacts.length <= 0"><p>No Contacts!</p></li> | |
<li class="list-group-item" ng-repeat="contact in contacts"> | |
<div class="actions pull-right"> | |
<a href="#edit/{{$index}}" class="btn btn-primary btn-xs">Edit</a> | |
<button class="btn btn-danger btn-xs" ng-click="deleteContact($index)" >Delete</button> | |
</div> | |
<div> | |
<p class="lead"><a href="#contacts/{{$index}}">{{contact.name}}</a></p> |