Skip to content
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
9 changes: 8 additions & 1 deletion client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
<body>

<div ng-controller="HelloWorldCtrl">
<button ng-if="!authenticated" ng-click="login()">Login</button>
<div ng-if="!authenticated">
<button ng-click="anonLogin()">Anon Login</button>
<button ng-click="cookieLogin()">Cookie Login</button>
<button ng-click="googleLogin()">Google Login</button>

<input ng-model="creds.username" placeholder="username" /><input ng-model="creds.password" type="password" placeholder="password" />
<button ng-click="userPassLogin()">U/P Login</button>
</div>
<div ng-if="authenticated">
<p>User: {{ user.firstName }} {{ user.lastName }}</p>
<button ng-click="addBlock()">Add Block</button>
Expand Down
2 changes: 1 addition & 1 deletion client/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ angular.module('Percero.Config', [], function($provide) {
gatewayPort: "8080",
// The OAuth provider used for authentication
oauthProviders: {
"Google": {
"googleoauth": {
redirectUri: "http://localhost:8081/oauth2callback.html",
appKey: "426306336879-m3ffk6mqt63pot5pg1kq52b7rmf2lnfo.apps.googleusercontent.com",
displayName: "Google"
Expand Down
100 changes: 72 additions & 28 deletions client/js/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,86 @@ app.controller('HelloWorldCtrl', function ($scope, percero) {
$scope.authenticated = false;
$scope.percero = percero;

$scope.login = function(){
percero.api.authenticate('Google')
$scope.anonLogin = function(){
percero.api.authenticateAnonymously()
.then(
function(userToken){
console.log("onLoginResult");
if(!userToken){
console.log("token falsey")
}else{
/**
* Successful auth... now pull down the person object so
* we know who we are
*/
console.log("OAuth Success!")
$scope.authenticated = true;

/**
* Now do a lookup for our user object
*/
var example = new percero.domain.User();
example.userId = userToken.user.ID;
percero.api.findByExample(example, function(message) {
var user = message.result[0];
$scope.$apply(function(){
// This also gets hit when the server sends down a person object
$scope.user = user;
console.log(user);
});
});
}
onLoginComplete,
function(error){
console.log(error);
},
function(progress) {
console.log(progress);
});
};

$scope.cookieLogin = function(){
percero.api.authenticateFromCookie()
.then(
onLoginComplete,
function(error){
console.log(error);
},
function(progress) {
console.log(progress);
});

};

$scope.googleLogin = function(){
percero.api.authenticateWithOAuth('googleoauth')
.then(
onLoginComplete,
function(error){
console.log(error);
},
function(progress) {
console.log(progress);
});

};

$scope.creds = {}
$scope.userPassLogin = function(){
percero.api.authenticateWithUserPass($scope.creds.username, $scope.creds.password, 'jsonfile')
.then(
onLoginComplete,
function(error){
console.log(error);
},
function(progress) {
console.log(progress);
});

};

function onLoginComplete(userToken){
console.log("onLoginResult");
if(!userToken){
console.log("token falsey")
}else{
/**
* Successful auth... now pull down the person object so
* we know who we are
*/
console.log("Auth Success!")
$scope.authenticated = true;

/**
* Now do a lookup for our user object
*/
var example = new percero.domain.User();
example.userId = userToken.user.ID;
console.log("UserID: "+userToken.user.ID);
percero.api.findByExample(example, function(message) {
console.log(message);
$scope.user = message.result[0];
//$scope.$apply(function(){
// // This also gets hit when the server sends down a person object
// $scope.user = user;
// console.log(user);
//});
});
}
}

$scope.percero = percero;
Expand Down
2 changes: 1 addition & 1 deletion client/js/model/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ angular.module('HelloWorld.Domain.User',

}
,doLoad: function(){
if (this.isShell && !this.isLoading) {
if (this.isShell && !this.isLoading && this.ID) {
this.isLoading = true;
var that = this;
this.api.findById(this.cn, this.ID, function() {
Expand Down
Loading