Skip to content

Instantly share code, notes, and snippets.

View pankajpatel's full-sized avatar
🎯
Focusing

Pankaj Patel pankajpatel

🎯
Focusing
View GitHub Profile
@pankajpatel
pankajpatel / securityRules.js
Created May 9, 2015 20:19
Firebase Security Rules
{
"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'"
}
@pankajpatel
pankajpatel / createFirebaseUser.js
Created May 9, 2015 20:23
Create New User on FirebaseDB
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);
}
});
@pankajpatel
pankajpatel / authenticateFirebaseUser.js
Created May 9, 2015 20:24
Authenticate a user with email and password on FirebaseDB
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;
}
@pankajpatel
pankajpatel / contactAppWithAuth.html
Created May 21, 2015 16:56
Contact Store App HTML in Firebase with Authentication. Read more at http://time2hack.com/2015/05/simple-login-in-firebase-web-api.html
<!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">
@pankajpatel
pankajpatel / contactAppWithAuth.js
Created May 21, 2015 16:59
Contact Store App JavaScript in Firebase with Authentication. Read more at http://time2hack.com/2015/05/simple-login-in-firebase-web-api.html
//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>');
@pankajpatel
pankajpatel / contactApp.js
Last active August 29, 2015 14:22
Angular App with route configuration for Contact Store Application
var app = angular.module( 'contactApp', ['ngRoute'] );
app.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/contacts', {
templateUrl: 'partials/contacts.html',
controller: 'ContactsController'
}).
when('/contacts/:contactId', {
@pankajpatel
pankajpatel / directory.txt
Created June 8, 2015 05:48
Directory Structure for Contact Store Application
contactStore
+ css
- style.css
- ...
+ js
+ partials
- newContact.html
- contacts.html
- ...
- app.js
@pankajpatel
pankajpatel / app.js
Last active August 29, 2015 14:22
Complete app.js for contact store application
var app = angular.module( 'contactApp', ['ngRoute'] );
app
.config(['$routeProvider',
function($routeProvider) {
$routeProvider
.when('/contacts', {
templateUrl: 'js/partials/contacts.html',
controller: 'ContactsController'
})
@pankajpatel
pankajpatel / controllers.js
Last active August 29, 2015 14:22
Complete controllers.js for contact store application
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);
@pankajpatel
pankajpatel / contacts.html
Last active August 29, 2015 14:22
contacts listing template for contact store application
<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>