Skip to content
This repository was archived by the owner on Aug 25, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions app/account/account.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ <h2>Account</h2>
<fieldset>
<legend>Change Password</legend>

<label>
<span>Old Password:</span>
<input type="password" ng-keypress="clear()" ng-model="oldpass"/>
</label>

<label>
<span>New Password:</span>
<input type="password" ng-keypress="clear()" ng-model="newpass"/>
Expand All @@ -36,7 +31,7 @@ <h2>Account</h2>
<input type="password" ng-keypress="clear()" ng-model="confirm"/>
</label>

<button ng-click="changePassword(oldpass, newpass, confirm)">change password</button>
<button ng-click="changePassword(newpass, confirm)">change password</button>

<p class="error" ng-show="err">{{err}}</p>
<p class="good" ng-show="msg">{{msg}}</p>
Expand All @@ -52,16 +47,11 @@ <h2>Account</h2>
<input type="text" ng-keypress="clear()" ng-model="newEmail"/>
</label>

<label>
<span>Password:</span>
<input type="password" ng-keypress="clear()" ng-model="pass"/>
</label>

<button ng-click="changeEmail(pass, newEmail)">update email</button>
<button ng-click="changeEmail(newEmail)">update email</button>

<p class="error" ng-show="emailerr">{{emailerr}}</p>
<p class="good" ng-show="emailmsg">{{emailmsg}}</p>
</fieldset>
</form>

<button ng-click="logout()">Log Out</button>
<button ng-click="logout()">Log Out</button>
34 changes: 12 additions & 22 deletions app/account/account.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
(function (angular) {
"use strict";

var app = angular.module('myApp.account', ['firebase', 'firebase.utils', 'firebase.auth', 'ngRoute']);
var app = angular.module('myApp.account', ['firebase', 'firebase.appauth', 'ngRoute']);

app.controller('AccountCtrl', ['$scope', 'Auth', 'fbutil', 'user', '$location', '$firebaseObject',
function($scope, Auth, fbutil, user, $location, $firebaseObject) {
var unbind;
app.controller('AccountCtrl', ['$scope', 'Auth', '$location', '$firebaseObject',
function($scope, Auth, $location, $firebaseObject) {
// create a 3-way binding with the user profile object in Firebase
var profile = $firebaseObject(fbutil.ref('users', user.uid));
profile.$bindTo($scope, 'profile').then(function(ub) { unbind = ub; });
$scope.profile = Auth.$getAuth();
console.log("firebase.User = ",JSON.stringify($scope.profile));

// expose logout function to scope
$scope.logout = function() {
if( unbind ) { unbind(); }
profile.$destroy();
Auth.$unauth();
Auth.$signOut();
$location.path('/login');
};

$scope.changePassword = function(pass, confirm, newPass) {
$scope.changePassword = function(newPass, confirm) {
resetMessages();
if( !pass || !confirm || !newPass ) {
if( !confirm || !newPass ) {
$scope.err = 'Please fill in all password fields';
}
else if( newPass !== confirm ) {
$scope.err = 'New pass and confirm do not match';
}
else {
Auth.$changePassword({email: profile.email, oldPassword: pass, newPassword: newPass})
Auth.$updatePassword(newPass)
.then(function() {
$scope.msg = 'Password changed';
}, function(err) {
Expand All @@ -38,16 +35,9 @@

$scope.clear = resetMessages;

$scope.changeEmail = function(pass, newEmail) {
$scope.changeEmail = function(newEmail) {
resetMessages();
var oldEmail = profile.email;
Auth.$changeEmail({oldEmail: oldEmail, newEmail: newEmail, password: pass})
.then(function() {
// store the new email address in the user's profile
return fbutil.handler(function(done) {
fbutil.ref('users', user.uid, 'email').set(newEmail, done);
});
})
Auth.$updateEmail(newEmail)
.then(function() {
$scope.emailmsg = 'Email changed';
}, function(err) {
Expand All @@ -74,4 +64,4 @@
})
}]);

})(angular);
})(angular);
14 changes: 13 additions & 1 deletion app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,35 @@

// Declare app level module which depends on filters, and services
angular.module('myApp', [
'firebase',
'myApp.config',
'myApp.security',

'firebase.appauth',

'myApp.home',
'myApp.account',
'myApp.chat',
'myApp.login'
])

.config(['$routeProvider', function ($routeProvider) {
// Initialize Firebase
var config = {
apiKey: PRIVATE.firebase_api,
authDomain: PRIVATE.firebase_authDomain,
databaseURL: PRIVATE.firebase_databaseURL
};
firebase.initializeApp(config);

$routeProvider.otherwise({
redirectTo: '/home'
});
}])

.run(['$rootScope', 'Auth', function($rootScope, Auth) {
// track status of authentication
Auth.$onAuth(function(user) {
Auth.$onAuthStateChanged(function(user) {
$rootScope.loggedIn = !!user;
});
}]);
8 changes: 4 additions & 4 deletions app/chat/chat.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function (angular) {
"use strict";

var app = angular.module('myApp.chat', ['ngRoute', 'firebase.utils', 'firebase']);
var app = angular.module('myApp.chat', ['ngRoute', 'firebase']);

app.controller('ChatCtrl', ['$scope', 'messageList', function($scope, messageList) {
$scope.messages = messageList;
Expand All @@ -12,8 +12,8 @@
};
}]);

app.factory('messageList', ['fbutil', '$firebaseArray', function(fbutil, $firebaseArray) {
var ref = fbutil.ref('messages').limitToLast(10);
app.factory('messageList', ['$firebaseArray', function($firebaseArray) {
var ref = firebase.database().ref('messages').limitToLast(10);;
return $firebaseArray(ref);
}]);

Expand All @@ -24,4 +24,4 @@
});
}]);

})(angular);
})(angular);
8 changes: 5 additions & 3 deletions app/components/auth/auth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
angular.module('firebase.auth', ['firebase', 'firebase.utils'])
.factory('Auth', ['$firebaseAuth', 'fbutil', function($firebaseAuth, fbutil) {
return $firebaseAuth(fbutil.ref());
angular.module('firebase.appauth', ['firebase'])
// renamed as per
// https://stackoverflow.com/questions/39244924/angularfire-and-firebase-upgrade-error-unknown-provider-firebaseauthprovider#39249547
.factory('Auth', ['$firebaseAuth', function($firebaseAuth) {
return $firebaseAuth();
}]);
4 changes: 2 additions & 2 deletions app/components/ngcloak/ngcloak-decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ angular.module('myApp')
// make a copy of the old directive
var _compile = directive.compile;
directive.compile = function(element, attr) {
Auth.$waitForAuth().then(function() {
Auth.$waitForSignIn().then(function() {
// after auth, run the original ng-cloak directive
_compile.call(directive, element, attr);
});
};
// return the modified directive
return $delegate;
}]);
}]);
}]);
6 changes: 3 additions & 3 deletions app/components/security/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// to be used by authRequired() in the services below
var securedRoutes = [];

angular.module('myApp.security', ['ngRoute', 'firebase.auth', 'myApp.config'])
angular.module('myApp.security', ['ngRoute', 'myApp.config'])

.config(['$routeProvider', function ($routeProvider) {
// routes which are not in our map are redirected to /home
Expand All @@ -30,7 +30,7 @@
securedRoutes.push(path); // store all secured routes for use with authRequired() below
route.resolve = route.resolve || {};
route.resolve.user = ['Auth', function (Auth) {
return Auth.$requireAuth();
return Auth.$requireSignIn();
}];
$routeProvider.when(path, route);
return this;
Expand All @@ -46,7 +46,7 @@
.run(['$rootScope', '$location', 'Auth', 'loginRedirectPath',
function ($rootScope, $location, Auth, loginRedirectPath) {
// watch for login status changes and redirect if appropriate
Auth.$onAuth(check);
Auth.$onAuthStateChanged(check);

// some of our routes may reject resolve promises with the special {authRequired: true} error
// this redirects to the login page whenever that is encountered
Expand Down
12 changes: 6 additions & 6 deletions app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
// Declare app level module which depends on filters, and services
angular.module('myApp.config', [])

// version of this seed app is compatible with angularFire 1.0.0
// version of this seed app is compatible with angularFire 2.x.x
// see tags for other versions: https://github.com/firebase/angularFire-seed/tags
.constant('version', '1.0.0')
.constant('version', '2.0.0')

// where to redirect users if they need to authenticate (see security.js)
.constant('loginRedirectPath', '/login')

// your Firebase data URL goes here, no trailing slash
.constant('FBURL', 'https://angularfire-seed-dev.firebaseio.com')
//.constant('FBURL', 'https://peep3auth.firebaseio.com')

// double check that the app has been configured before running it and blowing up space and time
.run(['FBURL', '$timeout', function(FBURL, $timeout) {
if( FBURL.match('//INSTANCE.firebaseio.com') ) {
angular.element(document.body).html('<h1>Please configure app/config.js before running!</h1>');
.run(['$timeout', function($timeout) {
if( PRIVATE.firebase_databaseURL.match('https://INSTANCE.firebaseio.com') ) {
angular.element(document.body).html('<h1>Please configure app/private.js before running!</h1>');
$timeout(function() {
angular.element(document.body).removeClass('hide');
}, 250);
Expand Down
13 changes: 7 additions & 6 deletions app/home/home.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
(function(angular) {
"use strict";

var app = angular.module('myApp.home', ['firebase.auth', 'firebase', 'firebase.utils', 'ngRoute']);
var app = angular.module('myApp.home', ['firebase.appauth', 'firebase', 'ngRoute']);

app.controller('HomeCtrl', ['$scope', 'fbutil', 'user', '$firebaseObject', 'FBURL', function ($scope, fbutil, user, $firebaseObject, FBURL) {
$scope.syncedValue = $firebaseObject(fbutil.ref('syncedValue'));
$scope.user = user;
$scope.FBURL = FBURL;
app.controller('HomeCtrl', ['$scope', '$firebaseObject', 'Auth', function ($scope, $firebaseObject, Auth) {
var ref = firebase.database().ref('syncedValue');
$scope.syncedValue = $firebaseObject(ref);
$scope.user = Auth.$getAuth();;
$scope.FBURL = PRIVATE.firebase_databaseURL;
}]);

app.config(['$routeProvider', function ($routeProvider) {
Expand All @@ -19,7 +20,7 @@
// in the controller, but this makes things cleaner (controller doesn't need to worry
// about auth status or timing of accessing data or displaying elements)
user: ['Auth', function (Auth) {
return Auth.$waitForAuth();
return Auth.$waitForSignIn();
}]
}
});
Expand Down
18 changes: 9 additions & 9 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<title>My AngularJS App</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="bower_components/html5-boilerplate/css/normalize.css">
<link rel="stylesheet" href="bower_components/html5-boilerplate/css/main.css">
<link rel="stylesheet" href="bower_components/html5-boilerplate/dist/css/normalize.css">
<link rel="stylesheet" href="bower_components/html5-boilerplate/dist/css/main.css">
<link rel="stylesheet" href="app.css"/>
<script src="bower_components/html5-boilerplate/js/vendor/modernizr-2.6.2.min.js"></script>
<script src="bower_components/html5-boilerplate/dist/js/vendor/modernizr-2.8.3.min.js"></script>
</head>
<body ng-cloak>

Expand All @@ -25,25 +25,25 @@
<div>AngularFire-seed v<span app-version></span></div>

<!-- In production use:
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.x/angular.min.js"></script>
<script src="//cdn.firebase.com/js/client/2.2.x/firebase.js"></script>
<script src="//cdn.firebase.com/libs/angularfire/1.0.x/angularfire.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.x/angular.min.js"></script>
<script src="//cdn.firebase.com/js/client/3.6.x/firebase.js"></script>
<script src="//cdn.firebase.com/libs/angularfire/2.0.x/angularfire.min.js"></script>
-->
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/firebase/firebase.js"></script>
<script src="bower_components/angularfire/dist/angularfire.js"></script>


<script src="private.js"></script>

<script src="app.js"></script>
<script src="config.js"></script>

<script src="components/appversion/appversion-directive.js"></script>
<script src="components/auth/auth.js"></script>
<script src="components/firebase.utils/firebase.utils.js"></script>
<script src="components/ngcloak/ngcloak-decorator.js"></script>
<script src="components/reverse/reverse-filter.js"></script>
<script src="components/security/security.js"></script>
<script src="components/auth/auth.js"></script>

<script src="home/home.js"></script>
<script src="account/account.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion app/login/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ <h2>Login Page</h2>
<form>
<label>
<span>email</span>
<input type="text" ng-model="email" />
<input type="email" ng-model="email" />
</label>
<label>
<span>password</span>
Expand Down
Loading