1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-06 14:36:59 +00:00

Frontend authentication working.

This commit is contained in:
2016-04-28 01:13:58 +00:00
parent 84578d89da
commit 425e7f5fc5
18 changed files with 175 additions and 89 deletions

View File

@@ -1,49 +0,0 @@
app.factory('AuthenticationService',
['Base64', '$http', '$cookieStore', '$rootScope', '$timeout',
function (Base64, $http, $cookieStore, $rootScope, $timeout) {
var service = {};
service.Login = function (username, password, callback) {
/* Dummy authentication for testing, uses $timeout to simulate api call
----------------------------------------------*/
// $timeout(function(){
// var response = { success: username === 'test' && password === 'test' };
// if(!response.success) {
// response.message = 'Username or password is incorrect';
// }
// callback(response);
// }, 1000);
/* Use this for real authentication
----------------------------------------------*/
$http.post('/api/authenticate', { username: username, password: password })
.success(function (response) {
callback(response);
});
};
service.SetCredentials = function (username, password) {
var authdata = Base64.encode(username + ':' + password);
$rootScope.globals = {
currentUser: {
username: username,
authdata: authdata
}
};
$http.defaults.headers.common['Authorization'] = 'Basic ' + authdata; // jshint ignore:line
$cookieStore.put('globals', $rootScope.globals);
};
service.ClearCredentials = function () {
$rootScope.globals = {};
$cookieStore.remove('globals');
$http.defaults.headers.common.Authorization = 'Basic ';
};
return service;
}]);

View File

@@ -37,8 +37,8 @@ function tournamentsService($http){
}
function errorCallback(err){
console.log("error log below");
console.log(err);
// console.log("error log below");
// console.log(err);
return err;
}