Skip to content
This repository was archived by the owner on Aug 25, 2018. It is now read-only.

Commit d8b9fd3

Browse files
committed
Merge remote-tracking branch 'upstream/master'
Upgraded to AngularFire 1.0.0 and SDK 2.2.2 Renamed fbutil service to Ref Renamed simpleLogin service to Auth Removed waitForAuth service (use Auth.$waitForAuth()) Conflicts: CHANGELOG.md app/index.js package.json readme.md templates/coffeescript/app.coffee templates/common/app/index.html templates/common/root/.jshintrc templates/common/root/_bower.json templates/common/root/_package.json test/test-apppath.js test/test-file-creation.js
1 parent d03daa5 commit d8b9fd3

File tree

20 files changed

+204
-287
lines changed

20 files changed

+204
-287
lines changed

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
2+
<a name="1.0.0"></a>
3+
### 1.0.0 (2015-03-27)
4+
5+
### Features
6+
7+
* **app**
8+
* Upgraded AngularFire to 1.0.0
9+
* Upgraded Firebase SDK to 2.2.3
10+
* **auth**
11+
* renamed `simpleLogin` service to `Auth` and the module is now `firebase.auth`
12+
* removed `authRequired` service (part of `$firebaseAuth` now)
13+
* removed `createProfile` service (part of `Auth` now)
14+
*
15+
* **release** merged latest changes from generator-angular upstream branch
16+
17+
### Breaking Changes
18+
19+
* Requires Firebase SDK 2.x
20+
* Requires AngularFire 1.x
21+
22+
<a name="0.9.4"></a>
23+
### 0.9.4 (2015-01-15)
24+
25+
### Features
26+
27+
* merge latest changes to generator-angular
28+
* upgraded Firebase SDK to 2.1.0
29+
* upgraded AngularFire to 0.9.1
30+
131
<a name="0.8.2"></a>
232
### 0.8.2 (2014-09-04)
333

angularfire/config.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"bower": {
3-
"firebase": "2.1.x",
4-
"angularfire": "0.9.1",
5-
"mockfirebase": "0.8.x"
3+
"firebase": "2.2.2",
4+
"angularfire": "1.0.0",
5+
"mockfirebase": "0.11.0"
66
},
77

88
"authProviders": [
@@ -12,9 +12,5 @@
1212
{ "name": "Google", "value": "google" },
1313
{ "name": "Twitter", "value": "twitter" },
1414
{ "name": "GitHub", "value": "github" }
15-
],
16-
17-
"specialRoutes": {
18-
"chat": true, "login": true, "account": true
19-
}
15+
]
2016
}

app/index.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -155,25 +155,27 @@ var Generator = module.exports = function Generator(args, options) {
155155
callback: this._injectDependencies.bind(this)
156156
});
157157

158+
//angularfire
158159
if (this.env.options.ngRoute) {
159-
// this will not create controller or html because
160-
// "chat" exists in config.json::specialRoutes
161160
this.invoke('angularfire:route', {
162-
//angularfire
163-
args: ['chat']
161+
args: ['chat'],
162+
options: { skipController: true, skipView: true, authRequired: false }
164163
});
165-
}
166164

167-
//angularfire
168-
if(this.env.options.loginModule) {
169-
if( this.env.options.ngRoute ) {
170-
// this will not create controller or html because
171-
// "login" exists in config.json::specialRoutes
165+
if(this.env.options.loginModule) {
172166
this.invoke('angularfire:route', {
173-
args: ['login']
167+
args: ['login'],
168+
options: { skipController: true, skipView: true, authRequired: false }
174169
});
170+
171+
this.invoke('angularfire:route', {
172+
args: ['account'],
173+
options: { skipController: true, skipView: true, authRequired: true }
174+
})
175175
}
176176
}
177+
178+
//angularfire
177179
});
178180

179181
this.pkg = require('../package.json');
@@ -187,7 +189,7 @@ Generator.prototype.welcome = function welcome() {
187189
this.log(yosay());
188190
this.log(
189191
chalk.magenta(
190-
'Out of the box I include Bootstrap and some AngularJS recommended modules, AngularFire, and Firebase Simple Login.' +
192+
'Out of the box I include Bootstrap and some AngularJS recommended modules, AngularFire, and Firebase authentication.' +
191193
'\n'
192194
)
193195
);
@@ -358,10 +360,10 @@ Generator.prototype.askForModules = function askForModules() {
358360

359361
//angularfire
360362
angMods.push("'firebase'");
361-
angMods.push("'firebase.utils'");
363+
angMods.push("'firebase.ref'");
362364
if( this.loginModule ) {
363-
this.env.options.simpleLogin = true;
364-
angMods.push("'simpleLogin'");
365+
this.env.options.loginModule = true;
366+
angMods.push("'firebase.auth'");
365367
}
366368

367369
if (angMods.length) {
@@ -389,13 +391,13 @@ Generator.prototype.bootstrapFiles = function bootstrapFiles() {
389391
//angularfire
390392
Generator.prototype.copyAngularFireFiles = function() {
391393
this._common('scripts/angularfire/config.js');
392-
this._common('scripts/angularfire/firebase.utils.js');
394+
this._common('scripts/angularfire/firebase.ref.js');
393395
this._tpl('controllers/chat');
394396
this._htmlTpl('views/chat.html');
395397
this._tpl('filters/reverse');
396398

397399
if( this.loginModule ) {
398-
this._common('scripts/angularfire/simpleLogin.js');
400+
this._common('scripts/angularfire/auth.js');
399401
this._tpl('controllers/login');
400402
this._tpl('controllers/account');
401403
this._htmlTpl('views/login.html');

route/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ var Generator = module.exports = function Generator(name) {
1414
required: false
1515
});
1616

17+
console.log('options', this.options);
18+
console.log('env', this.env.options);
19+
1720
var bower = require(path.join(process.cwd(), 'bower.json'));
1821
var match = require('fs').readFileSync(path.join(
1922
this.env.options.appPath,
@@ -28,8 +31,10 @@ var Generator = module.exports = function Generator(name) {
2831
this.foundWhenForRoute = true;
2932
}
3033

31-
if( this.env.options.afconfig.specialRoutes[name] !== true) {
34+
if( !this.options.skipController ) {
3235
this.hookFor('angularfire:controller');
36+
}
37+
if( !this.options.skipView ) {
3338
this.hookFor('angularfire:view');
3439
}
3540
};
@@ -68,7 +73,7 @@ Generator.prototype.rewriteRoutesJs = function () {
6873
};
6974

7075

71-
var whenMethod = this.env.options.authRequired || this.options['auth-required']? 'whenAuthenticated' : 'when';
76+
var whenMethod = this.options['authRequired']? 'whenAuthenticated' : 'when';
7277

7378
if (coffee) {
7479
config.splicable.unshift("." + whenMethod + " '/" + this.uri + "',");

templates/coffeescript/controllers/account.coffee

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# AccountCtrl
88
Provides rudimentary account management functions.
99
###
10-
angular.module("<%= scriptAppName %>").controller "AccountCtrl", ($scope, user, simpleLogin, fbutil, $timeout) ->
10+
angular.module("<%= scriptAppName %>").controller "AccountCtrl", ($scope, user, Auth, Ref, $firebaseObject, $timeout) ->
1111
<% if( hasPasswordProvider ) { %>error = (err) ->
1212
alert err, "danger"
1313
return
@@ -26,17 +26,14 @@ angular.module("<%= scriptAppName %>").controller "AccountCtrl", ($scope, user,
2626
), 10000
2727
return
2828

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

31+
profile = $firebaseObject(Ref.child("users/" + user.uid))
32+
profile.$bindTo $scope, "profile"
3533
$scope.user = user
36-
$scope.logout = simpleLogin.logout
34+
$scope.logout = () -> Auth.$unauth()
3735
$scope.messages = []
38-
profile = null
39-
loadProfile user
36+
4037
<% if( hasPasswordProvider ) { %>
4138
$scope.changePassword = (oldPass, newPass, confirm) ->
4239
$scope.err = null
@@ -45,15 +42,15 @@ angular.module("<%= scriptAppName %>").controller "AccountCtrl", ($scope, user,
4542
else if newPass isnt confirm
4643
error "Passwords do not match"
4744
else
48-
simpleLogin.changePassword(profile.email, oldPass, newPass).then (->
45+
Auth.$changePassword({email: profile.email, oldPassword: oldPass, newPassword: newPass}).then (->
4946
success "Password changed"
5047
return
5148
), error
5249
return
5350

5451
$scope.changeEmail = (pass, newEmail) ->
5552
$scope.err = null
56-
simpleLogin.changeEmail(pass, newEmail, profile.email).then ((user) ->
53+
Auth.$changeEmail({password: pass, oldEmail: profile.email, newEmail: newEmail}).then ((user) ->
5754
profile.email = newEmail
5855
profile.$save()
5956
success "Email changed"

templates/coffeescript/controllers/chat.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
# ChatCtrl
88
A demo of using AngularFire to manage a synchronized list.
99
###
10-
angular.module("<%= scriptAppName %>").controller "ChatCtrl", ($scope, fbutil, $timeout) ->
10+
angular.module("<%= scriptAppName %>").controller "ChatCtrl", ($scope, Ref, $firebaseArray, $timeout) ->
1111
alert = (msg) ->
1212
$scope.err = msg
1313
$timeout (->
1414
$scope.err = null
1515
), 5000
1616

1717
# synchronize a read-only, synchronized array of messages, limit to most recent 10
18-
$scope.messages = fbutil.syncArray("messages", limitToLast: 10)
18+
$scope.messages = $firebaseArray(Ref.child("messages").limitToLast(10));
1919

2020
# display any errors
2121
$scope.messages.$loaded().then null, alert

templates/coffeescript/controllers/login.coffee

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# LoginCtrl
88
Manages authentication to any active providers.
99
###
10-
angular.module("<%= scriptAppName %>").controller "LoginCtrl", ($scope, simpleLogin, $location) ->
10+
angular.module("<%= scriptAppName %>").controller "LoginCtrl", ($scope, Auth, $location<% if( hasPasswordProvider ) { %>, $q, Ref, $timeout<% } %>) ->
1111
redirect = ->
1212
$location.path "/account"
1313
return
@@ -17,36 +17,67 @@ angular.module("<%= scriptAppName %>").controller "LoginCtrl", ($scope, simpleLo
1717

1818
<% if( hasOauthProviders ) { %>$scope.oauthLogin = (provider) ->
1919
$scope.err = null
20-
simpleLogin.login(provider,
20+
Auth.$authWithOAuthPopup(provider,
2121
rememberMe: true
2222
).then redirect, showError
2323
return
2424

2525
$scope.anonymousLogin = ->
26-
simpleLogin.anonymousLogin(rememberMe: true).then redirect, showError
26+
Auth.$authAnonymously(rememberMe: true).then redirect, showError
2727
return
2828
<% } %><% if( hasPasswordProvider ) { %>
2929
$scope.passwordLogin = (email, pass) ->
3030
$scope.err = null
31-
simpleLogin.passwordLogin(
31+
Auth.$authWithPassword(
3232
email: email
3333
password: pass
3434
,
3535
rememberMe: true
3636
).then redirect, showError
3737
return
3838

39+
firstPartOfEmail = (email) ->
40+
ucfirst email.substr(0, email.indexOf('@')) or ''
41+
42+
ucfirst = (str) ->
43+
# inspired by: http://kevin.vanzonneveld.net
44+
str += ''
45+
f = str.charAt(0).toUpperCase()
46+
f + str.substr(1)
47+
3948
$scope.createAccount = (email, pass, confirm) ->
49+
50+
createProfile = (user) ->
51+
ref = Ref.child('users', user.uid)
52+
def = $q.defer()
53+
ref.set {
54+
email: email
55+
name: firstPartOfEmail(email)
56+
}, (err) ->
57+
$timeout ->
58+
if err
59+
def.reject err
60+
else
61+
def.resolve ref
62+
return
63+
return
64+
def.promise
65+
4066
$scope.err = null
41-
unless pass
42-
$scope.err = "Please enter a password"
43-
else if pass isnt confirm
44-
$scope.err = "Passwords do not match"
67+
if !pass
68+
$scope.err = 'Please enter a password'
69+
else if pass != confirm
70+
$scope.err = 'Passwords do not match'
4571
else
46-
simpleLogin.createAccount(email, pass,
47-
rememberMe: true
48-
).then redirect, showError
49-
72+
Auth.$createUser(
73+
email: email
74+
password: pass).then(->
75+
# authenticate so we have permission to write to Firebase
76+
Auth.$authWithPassword {
77+
email: email
78+
password: pass
79+
}, rememberMe: true
80+
).then(createProfile).then redirect, showError
5081
return
5182
<% } %>
5283
return

0 commit comments

Comments
 (0)