making it better
This commit is contained in:
parent
a7d93827d1
commit
ff8d740da1
|
@ -18,7 +18,7 @@ app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider
|
||||||
views: {
|
views: {
|
||||||
'header': {
|
'header': {
|
||||||
templateUrl: '/templates/partials/header.html',
|
templateUrl: '/templates/partials/header.html',
|
||||||
controller: 'HomeController',
|
controller: 'SignInController',
|
||||||
controllerAs: 'vm'
|
controllerAs: 'vm'
|
||||||
},
|
},
|
||||||
'menu': {
|
'menu': {
|
||||||
|
@ -34,7 +34,7 @@ app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider
|
||||||
views: {
|
views: {
|
||||||
'content@': {
|
'content@': {
|
||||||
templateUrl: 'templates/home.html',
|
templateUrl: 'templates/home.html',
|
||||||
controller: 'HomeController',
|
controller: 'SignInController',
|
||||||
controllerAs: 'vm'
|
controllerAs: 'vm'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,4 +17,5 @@ app.controller('HomeController', [
|
||||||
return profile.email;
|
return profile.email;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
throw new Error('loaded home controller');
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -9,10 +9,22 @@ app.controller('SignInController', [
|
||||||
vm.timers = {};
|
vm.timers = {};
|
||||||
vm.defaultIssuer = 'provider.' + location.host.replace(/^cloud\./, '');
|
vm.defaultIssuer = 'provider.' + location.host.replace(/^cloud\./, '');
|
||||||
|
|
||||||
|
vm.session = Auth.session;
|
||||||
|
vm.sessions = Auth.sessions;
|
||||||
|
|
||||||
|
vm.showAdvanced = true;
|
||||||
vm.toggleAdvanced = function () {
|
vm.toggleAdvanced = function () {
|
||||||
|
vm.showAdvanced = !vm.showAdvanced;
|
||||||
vm.independentIssuer = !vm.independentIssuer;
|
vm.independentIssuer = !vm.independentIssuer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vm.notification = true;
|
||||||
|
|
||||||
|
vm.signOut = function () {
|
||||||
|
Auth.signOut();
|
||||||
|
$location.path('/splash-page');
|
||||||
|
};
|
||||||
|
|
||||||
vm._setSubject = function (subject) {
|
vm._setSubject = function (subject) {
|
||||||
vm.currentSubject = vm.newSubject;
|
vm.currentSubject = vm.newSubject;
|
||||||
subject = subject || vm.newSubject;
|
subject = subject || vm.newSubject;
|
||||||
|
@ -69,14 +81,14 @@ app.controller('SignInController', [
|
||||||
};
|
};
|
||||||
|
|
||||||
vm.selectSession = function (session) {
|
vm.selectSession = function (session) {
|
||||||
|
vm.session = session;
|
||||||
vm.oauth3.init({
|
vm.oauth3.init({
|
||||||
location: location
|
location: location
|
||||||
, issuer: vm.currentIssuer
|
, issuer: session.issuer
|
||||||
, audience: vm.currentIssuer
|
, audience: session.audience || session.issuer
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
vm.oauth3.sessions = vm.oauth3.sessions || [];
|
|
||||||
vm.instaauth = function () {
|
vm.instaauth = function () {
|
||||||
return vm._setSubject().then(function () {
|
return vm._setSubject().then(function () {
|
||||||
return vm._setIssuer().then(function () {
|
return vm._setIssuer().then(function () {
|
||||||
|
@ -91,11 +103,9 @@ app.controller('SignInController', [
|
||||||
subject: subject
|
subject: subject
|
||||||
, scope: [ 'domains@oauth3.org', 'domains', 'dns@oauth3.org', 'dns', 'www@daplie.com' ]
|
, scope: [ 'domains@oauth3.org', 'domains', 'dns@oauth3.org', 'dns', 'www@daplie.com' ]
|
||||||
}).then(function (session) {
|
}).then(function (session) {
|
||||||
console.log('session', session);
|
|
||||||
vm.hasSession = session;
|
|
||||||
session.subject = subject;
|
session.subject = subject;
|
||||||
session.issuer = issuer;
|
session.issuer = issuer;
|
||||||
vm.oauth3.sessions.push(session);
|
Auth.add(session);
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
console.log('auth error');
|
console.log('auth error');
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
@ -106,13 +116,7 @@ app.controller('SignInController', [
|
||||||
vm.setIssuer(vm.defaultIssuer);
|
vm.setIssuer(vm.defaultIssuer);
|
||||||
|
|
||||||
vm.signIn = function () {
|
vm.signIn = function () {
|
||||||
vm.auth().then(function () {
|
vm.auth();
|
||||||
var userInfo = {
|
|
||||||
email: vm.currentSubject,
|
|
||||||
name: 'Johnny Cash'
|
|
||||||
};
|
|
||||||
Auth.setUser(userInfo);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
app.controller('WebsiteController', [ 'azp@oauth3.org', function ($scope, Oauth3) {
|
app.controller('WebsiteController', [ '$scope', 'azp@oauth3.org', function ($scope, Oauth3) {
|
||||||
var vm = this;
|
var vm = this;
|
||||||
|
|
||||||
vm.oauth3 = Oauth3.oauth3;
|
vm.oauth3 = Oauth3.oauth3;
|
||||||
|
|
|
@ -1,26 +1,66 @@
|
||||||
app.factory('Auth', [
|
app.factory('Auth', [
|
||||||
'$rootScope', 'localStorageService', '$location', 'azp@oauth3.org'
|
'$rootScope', 'localStorageService', '$location', 'azp@oauth3.org'
|
||||||
, function($rootScope, localStorageService, $location, Oauth3) {
|
, function($rootScope, localStorageService, $location, Oauth3) {
|
||||||
var user;
|
|
||||||
|
|
||||||
return {
|
var dapSession = 'dap-session';
|
||||||
|
var dapSessions = 'dap-sessions';
|
||||||
|
|
||||||
|
var Auth = {
|
||||||
setUser: function (currentUser) {
|
setUser: function (currentUser) {
|
||||||
user = currentUser;
|
|
||||||
if (redirectedURL === '/splash-page') {
|
if (redirectedURL === '/splash-page') {
|
||||||
$location.path('/home');
|
$location.path('/home');
|
||||||
} else {
|
} else {
|
||||||
$location.path('/' + redirectedURL);
|
$location.path('/' + redirectedURL);
|
||||||
}
|
}
|
||||||
user = localStorageService.set('userAuth', JSON.stringify(currentUser));
|
localStorageService.set('userAuth', JSON.stringify(currentUser));
|
||||||
},
|
},
|
||||||
isLoggedIn: function () {
|
isLoggedIn: function () {
|
||||||
// TODO check sessions instead
|
Auth.restore();
|
||||||
user = JSON.parse(localStorageService.get('userAuth'));
|
|
||||||
return (user) ? user : false;
|
return Auth.session || false;
|
||||||
},
|
},
|
||||||
getProfile: function (profile) {
|
getProfile: function (profile) {
|
||||||
profile = user;
|
Auth.restore();
|
||||||
return profile;
|
|
||||||
|
return Auth.session || false;
|
||||||
}
|
}
|
||||||
|
, add: function (session) {
|
||||||
|
var obj = JSON.parse(localStorage.getItem(dapSessions) || 'null') || {};
|
||||||
|
var dapName = 'dap-' + session.subject + '|' + session.issuer;
|
||||||
|
|
||||||
|
console.log('session', session);
|
||||||
|
|
||||||
|
Auth.session = session;
|
||||||
|
Auth.sessions.push(session);
|
||||||
|
|
||||||
|
localStorage.setItem(dapName, JSON.stringify(session));
|
||||||
|
localStorage.setItem(dapSession, dapName);
|
||||||
|
obj[dapName] = true;
|
||||||
|
localStorage.setItem(dapSessions, JSON.stringify(obj));
|
||||||
|
}
|
||||||
|
, restore: function () {
|
||||||
|
var dapName = localStorage.getItem(dapSession);
|
||||||
|
Auth.sessions.length = 0; // don't overwrite with a new array, keep original references
|
||||||
|
|
||||||
|
(Object.keys(JSON.parse(localStorage.getItem(dapSessions) || 'null') || {})).forEach(function (name) {
|
||||||
|
var session = JSON.parse(localStorage.getItem(name) || 'null');
|
||||||
|
|
||||||
|
if (session) {
|
||||||
|
session.email = session.subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dapName === name) {
|
||||||
|
Auth.session = session;
|
||||||
|
}
|
||||||
|
|
||||||
|
Auth.sessions.push(session);
|
||||||
|
});
|
||||||
|
|
||||||
|
return Auth.session;
|
||||||
|
}
|
||||||
|
, sessions: []
|
||||||
|
, session: null
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return Auth;
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -19,13 +19,28 @@
|
||||||
</form>
|
</form>
|
||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
<li class="dropdown">
|
<li class="dropdown">
|
||||||
<a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{{ vm.userName() }} <i class="fa fa-user" aria-hidden="true"></i> <span class="caret"></span></a>
|
<a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span ng-bind="vm.session.subject">me@example.com</span>
|
||||||
|
<i class="fa fa-user" aria-hidden="true"></i> <span class="caret"></span>
|
||||||
|
<br><small ng-bind="vm.session.issuer">example.com</small></a>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<li><a href="feed.html" target="_blank">Preview My Public Site</a></li>
|
<li><a href="feed.html" target="_blank">Preview My Public Site</a></li>
|
||||||
<li><a>Account Settings</a></li>
|
<li><a>Account Settings</a></li>
|
||||||
|
|
||||||
<li role="separator" class="divider"></li>
|
<li role="separator" class="divider"></li>
|
||||||
<li><a>Switch User</a></li>
|
|
||||||
<li ng-click="vm.signOut()"><a>Logout</a></li>
|
<li ng-if="vm.sessions.length">Switch User</li>
|
||||||
|
<li ng-repeat="session in vm.sessions"><a ng-click="vm.selectSession(session)"><span ng-bind="session.subject">me@example.com</span> <i class="fa fa-user" aria-hidden="true"></i>
|
||||||
|
<br><small ng-bind="session.issuer">example.com</small></a></li>
|
||||||
|
|
||||||
|
<li ng-if="vm.sessions.length" role="separator" class="divider"></li>
|
||||||
|
|
||||||
|
<li>Add User <i class="fa fa-cog" aria-hidden="true" ng-click="vm.toggleAdvanced()"></i>
|
||||||
|
<br><input class="input" type="text" ng-model="vm.newSubject" ng-change="vm.setSubject()" />
|
||||||
|
<br><input class="input" type="text" ng-if="vm.showAdvanced" ng-model="vm.newIssuer" ng-change="vm.setIssuer()" />
|
||||||
|
<br><button class="btn btn-default" type="button" ng-click="vm.auth()" >Add</button>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li ng-click="vm.signOut()"><a>Logout <i class="fa fa-sign-out" aria-hidden="true"></i></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
Loading…
Reference in New Issue