1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-04 13:43:48 +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

@@ -0,0 +1,51 @@
'use strict';
app.controller("loginController", function($scope, $routeParams, Auth, $rootScope) {
$scope.credentials = {
email: '',
password: ''
};
var config = {
headers: {
'X-HTTP-Method-Override': 'POST'
}
};
$scope.login = function(){
Auth.login($scope.credentials, config).then(function(user) {
console.log(user); // => {id: 1, ect: '...'}
$rootScope.user = user;
$rootScope.alertClass = "alert alert-success";
$rootScope.alertMessage = "Logged in successfully";
}, function(error) {
console.log(error);
$rootScope.alertClass = "alert alert-danger";
$rootScope.alertMessage = "Username and/or password is incorrect";
});
};
$scope.logout = function(){
Auth.logout(config).then(function(oldUser) {
// alert(oldUser.name + "you're signed out now.");
$rootScope.user = null;
$rootScope.alertClass = "alert alert-success";
$rootScope.alertMessage = "Logged out successfully";
}, function(error) {
// An error occurred logging out.
$rootScope.alertClass = "alert alert-danger";
$rootScope.alertMessage = "There was an error logging out";
});
};
Auth.currentUser().then(function(user) {
// User was logged in, or Devise returned
// previously authenticated session.
$rootScope.user = user;
}, function(error) {
// unauthenticated error
$rootScope.user = null;
});
});

View File

@@ -1,7 +1,8 @@
'use strict';
app.controller("tournamentController", function($scope, tournamentsService, $routeParams, Wrestler) {
app.controller("tournamentController", function($scope, tournamentsService, $routeParams, Wrestler, Auth, $rootScope) {
$scope.message = "Test message in scope.";
// $scope.tournamentData = "test";
tournamentsService.tournamentDetails($routeParams.id).then(function(data) {
//this will execute when the
@@ -9,7 +10,43 @@ app.controller("tournamentController", function($scope, tournamentsService, $rou
$scope.tournament = data;
});
// refresh tournament data every 10 seconds
// setInterval(function(){
// tournamentsService.tournamentDetails($routeParams.id).then(function(data) {
// //this will execute when the
// //AJAX call completes.
// $scope.tournament = data;
// });
// }, 10000);
$scope.wrestler = Wrestler;
$scope.showSchools = false;
$scope.toggleSchools = function(){
$scope.showSchools = !$scope.showSchools;
};
$scope.showWeightSeeds = false;
$scope.toggleWeightSeeds = function(){
$scope.showWeightSeeds = !$scope.showWeightSeeds;
};
$scope.showBoutBoard = false;
$scope.toggleBoutBoard = function(){
$scope.showBoutBoard = !$scope.showBoutBoard;
};
$scope.isTournamentOwner = function(tournamentId,userId){
if(userId == tournamentId){
return true;
} else {
return false;
}
};
});