1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-24 14:53:18 +00:00

Created basic viewing pages in angular

Can now search and view tournaments. Can now view team scores, weights and seeds, mats and bout board
This commit is contained in:
2016-04-12 21:11:18 +00:00
parent 8f07bc2f82
commit 5b9f64b3f9
16 changed files with 423 additions and 62 deletions

View File

@@ -0,0 +1,49 @@
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

@@ -0,0 +1,47 @@
app.factory('tournamentsService', tournamentsService);
function tournamentsService($http){
var service = {};
service.getAllTournaments = function(){
return $http({
url: '/api/tournaments/',
method: "GET"
}).then(successResponse, errorCallback);
};
service.searchTournaments = function(search){
return $http({
method: 'GET',
url: '/api/tournaments/',
params: {
search: search
}
}).then(successResponse, errorCallback);
};
service.tournamentDetails = function(tournamentId){
return $http({
url: '/api/tournaments/' + tournamentId,
method: "GET"
}).then(successResponse, errorCallback);
};
function successResponse(response){
console.log("success log below");
console.log(response);
return response.data;
}
function errorCallback(err){
console.log("error log below");
console.log(err);
return err;
}
return service;
}