Skip to content

Commit 1877bae

Browse files
author
Timothy E. Johansson
committed
Added PhoneGap specific features
1 parent 4cf7748 commit 1877bae

3 files changed

Lines changed: 39 additions & 24 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ AngularJS module that adds user authentication to your app with [UserApp](https:
1616
* [Services](#services)
1717
* [Directives](#directives)
1818
* [Events](#events)
19+
* [PhoneGap](#phonegap)
1920
* [Example](#example)
2021
* [Help](#help)
2122
* [License](#license)
@@ -519,6 +520,12 @@ To connect your AngularJS app to a back-end API, perform the AJAX requests on th
519520
});
520521
```
521522

523+
## PhoneGap
524+
525+
This module works perfectly out of the box with [PhoneGap](http://phonegap.com/).
526+
But if you want persistent sessions (like the Facebook, Twitter, and Instagram apps has), you need to include [userapp-phonegap](https://github.com/userapp-io/userapp-phonegap) into your project.
527+
It will automatically extend the AngularJS module with functionality that sets up persistent sessions.
528+
522529
## Example
523530

524531
See [example/](https://github.com/userapp-io/userapp-angular/tree/master/example) for a demo app based on [angular-seed](https://github.com/angular/angular-seed).

angularjs.userapp.js

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,19 @@ var userappModule = angular.module('UserApp', []);
142142
// If a UserApp token is present, use that for authentication
143143
var remoteToken;
144144
if (!token && (remoteToken = $location.search().ua_token)) {
145-
token = remoteToken;
145+
this.activate(remoteToken, function() {
146+
if (UserApp.setupPersistentToken) {
147+
UserApp.setupPersistentToken(function(error, token) {
148+
if (token) {
149+
that.token(token.value);
150+
}
151+
});
152+
}
153+
});
154+
} else if (token) {
155+
this.activate(token);
146156
}
147157

148-
token && this.activate(token);
149-
150158
// Listen for route changes
151159
if ($state) {
152160
$rootScope.$on('$stateChangeStart', function(ev, toState) {
@@ -324,7 +332,7 @@ var userappModule = angular.module('UserApp', []);
324332

325333
UserApp.User.save(user, function(error, result) {
326334
if (!error) {
327-
// check lock
335+
// Check locks
328336
if (result.locks && result.locks.length > 0 && result.locks[0].type == 'EMAIL_NOT_VERIFIED') {
329337
callback && callback({ name: 'EMAIL_NOT_VERIFIED' }, result);
330338
return;
@@ -364,15 +372,16 @@ var userappModule = angular.module('UserApp', []);
364372
callback && callback({ name: 'LOCKED', message: 'Your account has been locked.' }, result);
365373
} else {
366374
that.activate(result.token, function() {
367-
/*if (UserApp.setupPersistentToken) {
368-
UserApp.setupPersistentToken(function(token) {
369-
that.token(token.value);
375+
if (UserApp.setupPersistentToken) {
376+
UserApp.setupPersistentToken(function(error, token) {
377+
if (token) {
378+
that.token(token.value);
379+
}
370380
callback && callback(error, result);
371381
});
372-
console.log("Create persistent connection");
373-
} else {*/
382+
} else {
374383
callback && callback(error, result);
375-
//}
384+
}
376385
});
377386
}
378387
} else {
@@ -385,20 +394,19 @@ var userappModule = angular.module('UserApp', []);
385394
logout: function(callback) {
386395
var that = this;
387396

388-
/*if (UserApp.removePersistentToken) {
389-
UserApp.removePersistentToken(function(success) {
397+
if (UserApp.removePersistentToken) {
398+
UserApp.removePersistentToken(function(error) {
390399
that.reset();
400+
$rootScope.$broadcast('user.logout');
401+
callback && callback(error);
391402
});
392-
} else {*/
403+
} else {
393404
UserApp.User.logout(function(error) {
394-
that.reset();
395-
$rootScope.$broadcast('user.logout');
396-
callback && callback(error);
405+
that.reset();
406+
$rootScope.$broadcast('user.logout');
407+
callback && callback(error);
397408
});
398-
//}
399-
400-
//$rootScope.$broadcast('user.logout');
401-
//callback && callback(error);
409+
}
402410
},
403411

404412
// Send reset password email
@@ -500,9 +508,9 @@ var userappModule = angular.module('UserApp', []);
500508
startHeartbeat: function(interval) {
501509
var that = this;
502510

503-
if (interval != undefined && interval < 10000) {
504-
return;
505-
}
511+
if (interval != undefined && interval < 10000) {
512+
return;
513+
}
506514

507515
clearInterval(heartBeatInterval);
508516
heartBeatInterval = setInterval(function() {

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "userapp-angular",
3-
"version": "1.5.1",
3+
"version": "1.6.0",
44
"main": "./angularjs.userapp.js",
55
"dependencies": {
66
"userapp": "latest"

0 commit comments

Comments
 (0)