Skip to content

Commit

Permalink
Implemented new auth methods. Upgraded to AngularFire 0.9.1. Can't ta…
Browse files Browse the repository at this point in the history
…g/release this until AngularFire is pushed to bower/npm.
  • Loading branch information
katowulf committed Dec 22, 2014
1 parent 6498ec4 commit 7116024
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 194 deletions.
15 changes: 9 additions & 6 deletions angularfire/config.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"bower": {
"firebase": "1.0.x",
"angularfire": "0.8.x",
"mockfirebase": "0.2.x",
"simplelogin": "1.6.x"
"firebase": "2.0.x",
"angularfire": "0.9.1",
"mockfirebase": "0.8.x"
},

"simpleLoginProviders": [
"authProviders": [
{ "name": "Email/Password", "value": "password", "checked": true },
{ "name": "Anonymous", "value": "anonymous" },
{ "name": "Facebook", "value": "facebook" },
{ "name": "Google", "value": "google" },
{ "name": "Twitter", "value": "twitter" },
{ "name": "GitHub", "value": "github" }
]
],

"specialRoutes": {
"chat": true, "login": true, "account": true
}
}
29 changes: 13 additions & 16 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var FIREBASE_PROMPTS = [
type: 'checkbox',
name: 'providers',
message: 'Which providers shall I install?',
choices: afconfig.simpleLoginProviders,
choices: afconfig.authProviders,
when: function(answers) {
return answers.loginModule;
},
Expand All @@ -55,6 +55,7 @@ var Generator = module.exports = function Generator(args, options) {

//angularfire
this.afconfig = afconfig;
this.env.options.afconfig = afconfig;
this.angularFireSourceFiles = [];

this.option('app-suffix', {
Expand Down Expand Up @@ -194,25 +195,21 @@ var Generator = module.exports = function Generator(args, options) {
});

if (this.env.options.ngRoute) {
// this will not create controller or html because
// "chat" exists in config.json::specialRoutes
this.invoke('angularfire:route', {
//angularfire
args: ['chat', true]
args: ['chat']
});
}

//angularfire
if(this.env.options.loginModule) {
if( this.env.options.ngRoute ) {
// this will not create controller or html because
// "login" exists in config.json::specialRoutes
this.invoke('angularfire:route', {
args: ['login', true]
});
}
else {
this.invoke('angularfire:controller', {
args: ['login', true]
});
this.invoke('angularfire.view', {
args: ['login', true]
args: ['login']
});
}
}
Expand Down Expand Up @@ -248,12 +245,12 @@ Generator.prototype.welcome = function welcome() {
Generator.prototype.askFirebaseQuestions = function askForCompass() {
this.firebaseName = null;
this.loginModule = false;
this.simpleLoginProviders = [];
this.authProviders = [];
this.hasOauthProviders = false;
this.hasPasswordProvider = false;

// allow firebase instance to be set on command line
this._defaultNamespace(this.options['instance'], FIREBASE_PROMPTS);
this._defaultNamespace(this.options.instance, FIREBASE_PROMPTS);

var cb = this.async();
this.prompt(FIREBASE_PROMPTS, function (props) {
Expand Down Expand Up @@ -531,15 +528,15 @@ Generator.prototype._tpl = function(src, dest) {

//angularfire
Generator.prototype._processProviders = function(list) {
var providerMap = {}, i = afconfig.simpleLoginProviders.length, p;
var providerMap = {}, i = afconfig.authProviders.length, p;
while(i--) {
p = afconfig.simpleLoginProviders[i];
p = afconfig.authProviders[i];
providerMap[p.value] = {name: p.name, value: p.value};
}
list.forEach(function(p) {
if( p === 'password' ) { this.hasPasswordProvider = true; }
else { this.hasOauthProviders = true; }
this.simpleLoginProviders.push(providerMap[p]);
this.authProviders.push(providerMap[p]);
}, this);
};

Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Available generators:
**Note: Generators are to be run from the root directory of your app.**

### App
Sets up a new AngularJS + Firebase app, generating all the boilerplate you need to get started. The app generator also optionally installs FirebaseSimpleLogin, Bootstrap and additional AngularJS modules, such as angular-resource (installed by default).
Sets up a new AngularJS + Firebase app, generating all the boilerplate you need to get started. The app generator also optionally installs Firebase authentication and account management, Bootstrap and additional AngularJS modules, such as angular-resource (installed by default).

Example:
```bash
Expand Down
7 changes: 3 additions & 4 deletions route/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var ScriptBase = require('../script-base.js');
var angularUtils = require('../util.js');


var Generator = module.exports = function Generator(name, skipFiles) {
var Generator = module.exports = function Generator(name) {
ScriptBase.apply(this, arguments);
this.option('uri', {
desc: 'Allow a custom uri for routing',
Expand All @@ -28,7 +28,7 @@ var Generator = module.exports = function Generator(name, skipFiles) {
this.foundWhenForRoute = true;
}

if( skipFiles !== true ) {
if( this.env.options.afconfig.specialRoutes[name] !== true) {
this.hookFor('angularfire:controller');
this.hookFor('angularfire:view');
}
Expand All @@ -37,7 +37,7 @@ var Generator = module.exports = function Generator(name, skipFiles) {
util.inherits(Generator, ScriptBase);

//angularFire
Generator.prototype.rewriteAppJs = function () {
Generator.prototype.rewriteRoutesJs = function () {
var coffee = this.env.options.coffee;

if (!this.foundWhenForRoute) {
Expand Down Expand Up @@ -69,7 +69,6 @@ Generator.prototype.rewriteAppJs = function () {


var whenMethod = this.env.options.authRequired || this.options['auth-required']? 'whenAuthenticated' : 'when';
console.log(whenMethod, this.options);

if (coffee) {
config.splicable.unshift("." + whenMethod + " '/" + this.uri + "',");
Expand Down
8 changes: 5 additions & 3 deletions templates/coffeescript/controllers/account.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ angular.module("<%= scriptAppName %>").controller "AccountCtrl", ($scope, user,
return

<% } %>loadProfile = (user) ->
$scope.profile.$destroy() if $scope.profile
fbutil.syncObject("users/" + user.uid).$bindTo $scope, "profile"
profile.$destroy() if profile
profile = fbutil.syncObject("users/" + user.uid);
profile.$bindTo $scope, "profile"
return

$scope.user = user
$scope.logout = simpleLogin.logout
$scope.messages = []
profile = null
loadProfile user
<% if( hasPasswordProvider ) { %>
$scope.changePassword = (oldPass, newPass, confirm) ->
Expand All @@ -43,7 +45,7 @@ angular.module("<%= scriptAppName %>").controller "AccountCtrl", ($scope, user,
else if newPass isnt confirm
error "Passwords do not match"
else
simpleLogin.changePassword(user.email, oldPass, newPass).then (->
simpleLogin.changePassword(profile.email, oldPass, newPass).then (->
success "Password changed"
return
), error
Expand Down
2 changes: 1 addition & 1 deletion templates/coffeescript/controllers/chat.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ angular.module("<%= scriptAppName %>").controller "ChatCtrl", ($scope, fbutil, $
), 5000

# synchronize a read-only, synchronized array of messages, limit to most recent 10
$scope.messages = fbutil.syncArray("messages", limit: 10)
$scope.messages = fbutil.syncArray("messages", limitToLast: 10)

# display any errors
$scope.messages.$loaded().then null, alert
Expand Down
4 changes: 2 additions & 2 deletions templates/coffeescript/routes.with.login.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# routes.js
Configure routes for use with Angular, and apply authentication security
Add new routes to the ROUTES constant or use yo angularfire:route to create them
Add new routes using `yo angularfire:route` with the optional --auth-required flag.
Any controller can be secured so that it will only load if user is logged in by
using `whenAuthenticated()` in place of `when()`. This requires the user to
Expand Down Expand Up @@ -115,4 +115,4 @@ angular.module("<%= scriptAppName %>").config([
$location.path loginRedirectPath if angular.isObject(err) and err.authRequired
return

]).constant "SECURED_ROUTES", {}
]).constant "SECURED_ROUTES", {}
4 changes: 2 additions & 2 deletions templates/common/app/scripts/angularfire/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ angular.module('firebase.config', [])
.constant('FBURL', 'https://<%= firebaseName %>.firebaseio.com')<%
if( loginModule ) {
%>
.constant('SIMPLE_LOGIN_PROVIDERS', ['<%= _.map(simpleLoginProviders, function(p) {
.constant('SIMPLE_LOGIN_PROVIDERS', ['<%= _.map(authProviders, function(p) {
return p.value;
}).join("','") %>'])

.constant('loginRedirectPath', '/login')<% }
%>;
%>;
4 changes: 2 additions & 2 deletions templates/common/app/scripts/angularfire/firebase.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ angular.module('firebase.utils', ['firebase', 'firebase.config'])
function syncData(path, props) {
var ref = firebaseRef(path);
props = angular.extend({}, props);
angular.forEach(['limit', 'startAt', 'endAt'], function(k) {
angular.forEach(['limitToFirst', 'limitToLast', 'orderByKey', 'orderByChild', 'orderByPriority', 'startAt', 'endAt'], function(k) {
if( props.hasOwnProperty(k) ) {
var v = props[k];
ref = ref[k].apply(ref, angular.isArray(v)? v : [v]);
Expand All @@ -84,4 +84,4 @@ angular.module('firebase.utils', ['firebase', 'firebase.config'])
});
return $firebase(ref, props);
}
}]);
}]);
Loading

0 comments on commit 7116024

Please sign in to comment.