Skip to content
This repository has been archived by the owner on Aug 12, 2018. It is now read-only.

Commit

Permalink
working on a login service
Browse files Browse the repository at this point in the history
  • Loading branch information
slmyers committed Feb 10, 2016
1 parent fa12d67 commit 895b3cb
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
8 changes: 6 additions & 2 deletions frontend/web/app/controllers/loginDialogController.js
Original file line number Diff line number Diff line change
@@ -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);
};
}]);
2 changes: 1 addition & 1 deletion frontend/web/app/module.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
39 changes: 39 additions & 0 deletions frontend/web/app/services/loginService.js
Original file line number Diff line number Diff line change
@@ -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
};
});
3 changes: 2 additions & 1 deletion frontend/web/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 5 additions & 2 deletions frontend/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<script src="bower_components/angular-animate/angular-animate.js"></script>
<script src="bower_components/angular-messages/angular-messages.js"></script>
<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="bower_components/a0-angular-storage/dist/angular-storage.js"></script>

<!-- our code -->
<!-- app level -->
Expand All @@ -25,15 +26,17 @@
<script src="app/controllers/loginDialogController.js"></script>
<script src="app/controllers/loginController.js"></script>

<!-- services -->
<script src="app/services/loginService.js"></script>


<title>Chemistry Genealogy</title>

<!-- for 'html5Mode' -->
<base href='/'>
</head>
<body>
<!-- view is rendered via ui-router -->
<div ui-view></div>


</body>
</html>

0 comments on commit 895b3cb

Please sign in to comment.