From 895b3cb59252a92a619e4d3291b6504b47bed97f Mon Sep 17 00:00:00 2001 From: Steven Myers Date: Wed, 10 Feb 2016 16:32:08 -0700 Subject: [PATCH] working on a login service --- .../app/controllers/loginDialogController.js | 8 +++- frontend/web/app/module.js | 2 +- frontend/web/app/services/loginService.js | 39 +++++++++++++++++++ frontend/web/bower.json | 3 +- frontend/web/index.html | 7 +++- 5 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 frontend/web/app/services/loginService.js diff --git a/frontend/web/app/controllers/loginDialogController.js b/frontend/web/app/controllers/loginDialogController.js index 2989dbe..12b4862 100644 --- a/frontend/web/app/controllers/loginDialogController.js +++ b/frontend/web/app/controllers/loginDialogController.js @@ -1,10 +1,14 @@ angular.module('chemGeno') -.controller('loginDialogController', ['$scope', '$mdDialog', function($scope, $mdDialog) { +.controller('loginDialogController', ['$scope', '$mdDialog', 'loginService', +function($scope, $mdDialog, loginService) { + $scope.master = {}; + $scope.submit = function(user) { - console.log(user); + loginService.login(user); }; $scope.cancel = function() { $mdDialog.cancel(); + $scope.user = angular.copy($scope.master); }; }]); diff --git a/frontend/web/app/module.js b/frontend/web/app/module.js index bb4b362..2f51194 100644 --- a/frontend/web/app/module.js +++ b/frontend/web/app/module.js @@ -1,4 +1,4 @@ -var app = angular.module('chemGeno', ['ngMaterial', 'ui.router']) +var app = angular.module('chemGeno', ['ngMaterial', 'ui.router', 'angular-storage']) .config(function($mdThemingProvider) { $mdThemingProvider.theme('default') .primaryPalette('indigo') diff --git a/frontend/web/app/services/loginService.js b/frontend/web/app/services/loginService.js new file mode 100644 index 0000000..fa94b53 --- /dev/null +++ b/frontend/web/app/services/loginService.js @@ -0,0 +1,39 @@ +angular.module('chemGeno') +.service('loginService', function(store, $q) { + var loggedIn = false; + + var userLoggedIn = function() { + return loggedIn; + }; + + var loginPromise = function(user) { + var deferred = $q.defer(); + + setTimeout(function() { + deferred.notify('About to login ' + user + '.'); + + if (user.username && user.password) { + deferred.resolve('Hello, ' + user.username + ' with password: ' + user.password + '!'); + loggedIn = true; + } else { + deferred.reject('Greeting ' + user.username + ' with ' + user.password + ' is not allowed.'); + } + }, 1000); + + return deferred.promise; + }; + + var login = function(user) { + var promise = loginPromise(user); + promise.then(function(greeting) { + alert('Success: ' + greeting + ' loggedIn === ' + loggedIn); + }, function(reason) { + alert('Failed: ' + reason); + }); + } + + return { + userLoggedIn: userLoggedIn, + login: login + }; +}); diff --git a/frontend/web/bower.json b/frontend/web/bower.json index 079c643..b046ebc 100644 --- a/frontend/web/bower.json +++ b/frontend/web/bower.json @@ -13,7 +13,8 @@ "dependencies": { "angular": "~1.4.9", "angular-material": "~1.0.4", - "angular-ui-router": "~0.2.18" + "angular-ui-router": "~0.2.18", + "a0-angular-storage": "~0.0.13" }, "resolutions": { "angular": "1.5.0" diff --git a/frontend/web/index.html b/frontend/web/index.html index 63a0168..ed79f00 100644 --- a/frontend/web/index.html +++ b/frontend/web/index.html @@ -15,6 +15,7 @@ + @@ -25,6 +26,9 @@ + + + Chemistry Genealogy @@ -32,8 +36,7 @@ +
- -