Skip to content

Commit

Permalink
move assets into app folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Shigawire committed Mar 26, 2017
1 parent 0d1d9f2 commit ef7fa6b
Show file tree
Hide file tree
Showing 26 changed files with 103,849 additions and 26 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# face-auth
# Face Auth App

# Assets
- Libraries werden über bower geladen (siehe bower.json)
- Frontend-Logik wird in CoffeeScript implementiert

Die bower-libraries und CoffeeScript Dateien werden mit Hilfe von gulp gulp (```gulp build```) in das /app-Verzeichnis kopiert und übersetzt.

In der index.html werden dann die von gulp erstellten Dateien referenziert.
4 changes: 4 additions & 0 deletions app/assets/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(function() {
this.FaceAuthApp = angular.module('FaceAuthApp', ['ui.router', 'ngResource', 'ngMaterial', 'ngAnimate', 'webcam', 'ngStorage']);

}).call(this);
19 changes: 19 additions & 0 deletions app/assets/js/configs/error_interceptor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(function() {
this.FaceAuthApp.config([
'$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push([
'$q', '$injector', function($q, $injector) {
return {
responseError: function(rejection) {
var mdToastService;
mdToastService = $injector.get('$mdToast');
mdToastService.show(mdToastService.simple().textContent(rejection.data.error.message).position('right').hideDelay(15000));
return $q.reject(rejection);
}
};
}
]);
}
]);

}).call(this);
20 changes: 20 additions & 0 deletions app/assets/js/configs/routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(function() {
this.FaceAuthApp.config([
'$stateProvider', '$urlRouterProvider', '$locationProvider', function($stateProvider, $urlRouterProvider, $locationProvider) {
$urlRouterProvider.otherwise('/dashboard');
$stateProvider.state('dashboard', {
url: '/dashboard',
templateUrl: 'templates/views/dashboard.html',
controller: 'DashboardController',
controllerAs: 'vm'
});
$stateProvider.state('settings', {
url: '/settings',
templateUrl: 'templates/views/settings.html',
controller: 'SettingsController',
controllerAs: 'vm'
});
}
]);

}).call(this);
13 changes: 13 additions & 0 deletions app/assets/js/controllers/app.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(function() {
this.FaceAuthApp.controller('AppController', [
'$localStorage', function($localStorage) {
if (!$localStorage.settings) {
$localStorage.settings = {};
}
if (!$localStorage.users) {
return $localStorage.users = [];
}
}
]);

}).call(this);
34 changes: 34 additions & 0 deletions app/assets/js/controllers/dashboard.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(function() {
this.FaceAuthApp.controller('DashboardController', [
'$scope', '$mdDialog', 'Person', '$localStorage', function($scope, $mdDialog, Person, $localStorage) {
var vm;
vm = this;
vm.isLocked = true;
vm.settings = $localStorage.settings;
vm.showSignUpDialog = function(ev) {
$mdDialog.show({
controller: 'SignUpController',
controllerAs: 'vm',
templateUrl: 'templates/views/sign_up.html',
parent: angular.element(document.body),
targetEvent: ev,
clickOutsideToClose: false
});
};
vm.showSignInDialog = function(ev) {
$mdDialog.show({
controller: 'SignInController',
controllerAs: 'vm',
templateUrl: 'templates/views/sign_in.html',
parent: angular.element(document.body),
targetEvent: ev,
clickOutsideToClose: false
}).then(function(result) {
return vm.currentUser = result;
});
};
return vm;
}
]);

}).call(this);
49 changes: 49 additions & 0 deletions app/assets/js/controllers/settings.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
(function() {
this.FaceAuthApp.controller('SettingsController', [
'$scope', '$mdDialog', '$localStorage', '$http', 'Person', function($scope, $mdDialog, $localStorage, $http, Person) {
var vm;
vm = this;
if (!$localStorage.settings) {
$localStorage.settings = {};
}
vm.settings = $localStorage.settings;
vm.editApiKey = function(ev) {
var confirm;
confirm = $mdDialog.prompt().title('Bitte gib deinen Microsoft Cognitive Services API Key an').placeholder('API Key').ariaLabel('API Key').initialValue(vm.settings.apiKey).targetEvent(ev).ok('Speichern').cancel('Abbrechen');
$mdDialog.show(confirm).then((function(result) {
vm.settings.apiKey = result;
location.reload();
}));
};
vm.editPersonGroup = function(ev) {
var confirm;
confirm = $mdDialog.prompt().title('Bitte gib eine personGroup an.').textContent('Die Microsoft API benutzt personGroups um Gesichter innerhalb eines Benutzerpools zuzuordnen.\n\nBitte beachte die Hinweise in den Einstellungen!').placeholder('Person group').ariaLabel('Person group').initialValue(vm.settings.personGroup).targetEvent(ev).ok('Speichern').cancel('Abbrechen');
$mdDialog.show(confirm).then((function(result) {
if (result === '') {
return;
}
$http.put('https://westus.api.cognitive.microsoft.com/face/v1.0/persongroups/' + result, {
name: result
}, {
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': $localStorage.settings.apiKey
}
}).then((function(response) {
vm.settings.personGroup = result;
Person.trainFaces({
personGroup: result
});
}), function(response) {
if (response.status === 409) {
vm.settings.personGroup = result;
}
console.log(response);
});
}));
};
return vm;
}
]);

}).call(this);
38 changes: 38 additions & 0 deletions app/assets/js/controllers/sign_in.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(function() {
this.FaceAuthApp.controller('SignInController', [
'$scope', 'WebcamService', 'FaceSnapshotService', '$localStorage', '$mdDialog', function($scope, WebcamService, FaceSnapshotService, $localStorage, $mdDialog) {
var vm;
vm = this;
vm.webcam = WebcamService.webcam;
vm.closeSignInDialog = function() {
return $mdDialog.hide(vm.identifiedUser);
};
vm.cancelSignInDialog = function() {
return $mdDialog.hide(void 0);
};
vm.doAuthSnapshot = function() {
vm.snapshot = {
data: vm.webcam.makeSnapshot(),
identified: false,
inProgress: true
};
return FaceSnapshotService.identifyUser(vm.snapshot.data).then(function(userData) {
if (!userData.success) {
vm.failureReason = userData.errorMessage;
vm.snapshot.identified = false;
return;
}
vm.identifiedUser = ($localStorage.users.filter(function(user) {
return user.personId === userData.data.person.personId;
}))[0];
vm.snapshot.identified = true;
return vm.snapshot.withLandmarks = FaceSnapshotService.addLandmarks(vm.snapshot.data, userData.data.face);
})["finally"](function() {
return vm.snapshot.inProgress = false;
});
};
return vm;
}
]);

}).call(this);
106 changes: 106 additions & 0 deletions app/assets/js/controllers/sign_up.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
(function() {
this.FaceAuthApp.controller('SignUpController', [
'$scope', '$mdDialog', 'WebcamService', 'FaceSnapshotService', '$localStorage', 'Person', '$q', '$interval', function($scope, $mdDialog, WebcamService, FaceSnapshotService, $localStorage, Person, $q, $interval) {
var vm;
vm = this;
vm.user = '';
vm.snapshotList = [];
vm.selectedIndex = 0;
vm.webcam = WebcamService.webcam;
vm.addSnapshot = function() {
var snapshot;
snapshot = {
data: vm.webcam.makeSnapshot(),
accepted: void 0,
inProgress: true
};
vm.snapshotList.push(snapshot);
vm.snapshotVerifying = true;
return FaceSnapshotService.verifyFacePresence(snapshot.data).then(function(faceData) {
if (!faceData.success) {
snapshot.errorMessage = faceData.errorMessage;
return;
}
return FaceSnapshotService.identifyUser(snapshot.data).then(function(userData) {
console.log(userData);
if (userData.success && userData.data.person) {
snapshot.accepted = false;
snapshot.errorMessage = 'Dieses Gesicht wurde bereits einem Nutzer zugeordnet.';
return;
}
snapshot.accepted = true;
return snapshot.withLandmarks = FaceSnapshotService.addLandmarks(snapshot.data, faceData.data[0]);
});
})["finally"](function() {
snapshot.inProgress = false;
return vm.snapshotVerifying = false;
});
};
vm.createUser = function() {
var user;
vm.stepsFinished = [false, false, false, false];
vm.selectedIndex = 2;
user = new Person({
personGroup: $localStorage.settings.personGroup,
name: vm.name
});
return user.$save(function(data) {
var i, len, ref, snapshot, uploadPromises;
vm.stepsFinished[0] = true;
user.personId = data.personId;
uploadPromises = [];
ref = vm.snapshotList;
for (i = 0, len = ref.length; i < len; i++) {
snapshot = ref[i];
uploadPromises.push(Person.addFace({
personGroup: $localStorage.settings.personGroup,
personId: user.personId
}, FaceSnapshotService.dataURItoBlob(snapshot.data)));
}
return $q.all(uploadPromises).then(function() {
vm.stepsFinished[1] = true;
return Person.trainFaces({
personGroup: $localStorage.settings.personGroup
}, function() {
var checkTrainingInterval;
vm.stepsFinished[2] = true;
return checkTrainingInterval = $interval((function() {
return Person.trainingStatus({
personGroup: $localStorage.settings.personGroup
}, function(data) {
if (data.status === 'succeeded') {
$interval.cancel(checkTrainingInterval);
vm.stepsFinished[3] = true;
return $localStorage.users.push({
personId: user.personId,
name: vm.name,
secret: vm.secret
});
} else if (data.status === 'failed') {
$interval.cancel(checkTrainingInterval);
return vm.stepsFinished[3] = true;
}
});
}), 2000);
});
});
});
};
vm.removeSnapshot = function(snapshot) {
return vm.snapshotList = vm.snapshotList.filter(function(item) {
return item.data !== snapshot.data;
});
};
vm.acceptedSnapshots = function() {
return (vm.snapshotList.filter(function(snapshot) {
return snapshot.accepted === true;
})).length;
};
vm.closeSignUpDialog = function() {
$mdDialog.hide();
};
return vm;
}
]);

}).call(this);
75 changes: 75 additions & 0 deletions app/assets/js/factories/face_api.factories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
(function() {
this.FaceAuthApp.factory('Face', [
'$resource', '$localStorage', function($resource, $localStorage) {
return $resource('https://westus.api.cognitive.microsoft.com/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=true', {}, {
detect: {
method: 'POST',
isArray: true,
transformRequest: angular.identity,
headers: {
'Content-Type': 'application/octet-stream; charset=binary',
'Ocp-Apim-Subscription-Key': $localStorage.settings.apiKey
}
},
identify: {
method: 'POST',
isArray: true,
url: 'https://westus.api.cognitive.microsoft.com/face/v1.0/identify',
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': $localStorage.settings.apiKey
}
}
});
}
]);

this.FaceAuthApp.factory('Person', [
'$resource', '$localStorage', function($resource, $localStorage) {
return $resource('https://westus.api.cognitive.microsoft.com/face/v1.0/persongroups/:personGroup/persons', {
personGroup: '@personGroup',
personId: '@personId'
}, {
save: {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': $localStorage.settings.apiKey
}
},
get: {
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': $localStorage.settings.apiKey
}
},
addFace: {
method: 'POST',
url: 'https://westus.api.cognitive.microsoft.com/face/v1.0/persongroups/:personGroup/persons/:personId/persistedFaces',
transformRequest: angular.identity,
headers: {
'Content-Type': 'application/octet-stream; charset=binary',
'Ocp-Apim-Subscription-Key': $localStorage.settings.apiKey
}
},
trainFaces: {
method: 'POST',
url: 'https://westus.api.cognitive.microsoft.com/face/v1.0/persongroups/:personGroup/train',
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': $localStorage.settings.apiKey
}
},
trainingStatus: {
method: 'GET',
url: 'https://westus.api.cognitive.microsoft.com/face/v1.0/persongroups/:personGroup/training',
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': $localStorage.settings.apiKey
}
}
});
}
]);

}).call(this);
Loading

0 comments on commit ef7fa6b

Please sign in to comment.