-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
99 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,59 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
//Wrapper for satellizer | ||
//Basically only exists so we have somewhere to keep the user data | ||
angular.module('AuthService', ['satellizer', 'ui-notification']) | ||
|
||
.service('authService', ['$auth', '$http', 'Notification', function($auth, $http, Notification) { | ||
|
||
var user; | ||
|
||
// On startup, if authed, get the user data | ||
if($auth.isAuthenticated()){ | ||
$http.get('/api/user/getCurrentUser') | ||
.then(function(response){ | ||
user = response.data; | ||
}, function(response){ | ||
//Something went wrong | ||
Notification.error(response.message); | ||
}); | ||
} | ||
|
||
var authenticate = function(provider){ | ||
return $auth.authenticate(provider) | ||
.then(function(response){ | ||
//Success! Logged in with provider | ||
Notification.success('Logged in'); | ||
user = response.data.user; | ||
return user; | ||
}, function(response){ | ||
//Failure. Something went wrong | ||
Notification.error(response.message); | ||
}); | ||
}; | ||
|
||
var logout = function() { | ||
$auth.logout(); | ||
user = null; | ||
Notification.primary('Logged out'); | ||
}; | ||
|
||
return { | ||
authenticate: authenticate, | ||
logout: logout, | ||
isAuthenticated: $auth.isAuthenticated, | ||
getUser: function () { return user; }, | ||
}; | ||
}]); | ||
}()); | ||
'use strict'; | ||
|
||
//Wrapper for satellizer | ||
//Basically only exists so we have somewhere to keep the user data | ||
angular.module('AuthService', ['satellizer', 'ui-notification']) | ||
|
||
.service('authService', ['$auth', '$http', 'Notification', function($auth, $http, Notification) { | ||
|
||
var user; | ||
|
||
// On startup, if authed, get the user data | ||
if($auth.isAuthenticated()){ | ||
$http.get('/api/user/getCurrentUser') | ||
.then(function(response){ | ||
user = response.data; | ||
}, function(response){ | ||
//Something went wrong | ||
Notification.error(response.message); | ||
}); | ||
} | ||
|
||
var authenticate = function(provider){ | ||
return $auth.authenticate(provider) | ||
.then(function(response){ | ||
//Success! Logged in with provider | ||
Notification.success('Logged in'); | ||
user = response.data.user; | ||
return user; | ||
}, function(response){ | ||
//Failure. Something went wrong | ||
Notification.error(response.message); | ||
}); | ||
}; | ||
|
||
var logout = function() { | ||
$auth.logout(); | ||
user = null; | ||
Notification.primary('Logged out'); | ||
}; | ||
|
||
var updateData = function(userData) { | ||
return $http.post('/api/user/update', userData) | ||
.then(function(response){ | ||
Notification.success('Update Completed'); | ||
user = response.data; | ||
return user; | ||
}, function(response){ | ||
Notification.error(response.message); | ||
}); | ||
}; | ||
|
||
return { | ||
authenticate: authenticate, | ||
logout: logout, | ||
isAuthenticated: $auth.isAuthenticated, | ||
getUser: function () { return user; }, | ||
updateData: updateData | ||
}; | ||
}]); |