Skip to content

Commit

Permalink
Added PhoneGap specific features
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy E. Johansson committed Apr 25, 2014
1 parent 4cf7748 commit 1877bae
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 24 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ AngularJS module that adds user authentication to your app with [UserApp](https:
* [Services](#services)
* [Directives](#directives)
* [Events](#events)
* [PhoneGap](#phonegap)
* [Example](#example)
* [Help](#help)
* [License](#license)
Expand Down Expand Up @@ -519,6 +520,12 @@ To connect your AngularJS app to a back-end API, perform the AJAX requests on th
});
```

## PhoneGap

This module works perfectly out of the box with [PhoneGap](http://phonegap.com/).
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.
It will automatically extend the AngularJS module with functionality that sets up persistent sessions.

## Example

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).
Expand Down
54 changes: 31 additions & 23 deletions angularjs.userapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,19 @@ var userappModule = angular.module('UserApp', []);
// If a UserApp token is present, use that for authentication
var remoteToken;
if (!token && (remoteToken = $location.search().ua_token)) {
token = remoteToken;
this.activate(remoteToken, function() {
if (UserApp.setupPersistentToken) {
UserApp.setupPersistentToken(function(error, token) {
if (token) {
that.token(token.value);
}
});
}
});
} else if (token) {
this.activate(token);
}

token && this.activate(token);

// Listen for route changes
if ($state) {
$rootScope.$on('$stateChangeStart', function(ev, toState) {
Expand Down Expand Up @@ -324,7 +332,7 @@ var userappModule = angular.module('UserApp', []);

UserApp.User.save(user, function(error, result) {
if (!error) {
// check lock
// Check locks
if (result.locks && result.locks.length > 0 && result.locks[0].type == 'EMAIL_NOT_VERIFIED') {
callback && callback({ name: 'EMAIL_NOT_VERIFIED' }, result);
return;
Expand Down Expand Up @@ -364,15 +372,16 @@ var userappModule = angular.module('UserApp', []);
callback && callback({ name: 'LOCKED', message: 'Your account has been locked.' }, result);
} else {
that.activate(result.token, function() {
/*if (UserApp.setupPersistentToken) {
UserApp.setupPersistentToken(function(token) {
that.token(token.value);
if (UserApp.setupPersistentToken) {
UserApp.setupPersistentToken(function(error, token) {
if (token) {
that.token(token.value);
}
callback && callback(error, result);
});
console.log("Create persistent connection");
} else {*/
} else {
callback && callback(error, result);
//}
}
});
}
} else {
Expand All @@ -385,20 +394,19 @@ var userappModule = angular.module('UserApp', []);
logout: function(callback) {
var that = this;

/*if (UserApp.removePersistentToken) {
UserApp.removePersistentToken(function(success) {
if (UserApp.removePersistentToken) {
UserApp.removePersistentToken(function(error) {
that.reset();
$rootScope.$broadcast('user.logout');
callback && callback(error);
});
} else {*/
} else {
UserApp.User.logout(function(error) {
that.reset();
$rootScope.$broadcast('user.logout');
callback && callback(error);
that.reset();
$rootScope.$broadcast('user.logout');
callback && callback(error);
});
//}

//$rootScope.$broadcast('user.logout');
//callback && callback(error);
}
},

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

if (interval != undefined && interval < 10000) {
return;
}
if (interval != undefined && interval < 10000) {
return;
}

clearInterval(heartBeatInterval);
heartBeatInterval = setInterval(function() {
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "userapp-angular",
"version": "1.5.1",
"version": "1.6.0",
"main": "./angularjs.userapp.js",
"dependencies": {
"userapp": "latest"
Expand Down

0 comments on commit 1877bae

Please sign in to comment.