Created
August 14, 2012 17:52
-
-
Save corkupine/3351232 to your computer and use it in GitHub Desktop.
Controller that makes use of angular-auth
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
var mod = {}; | |
mod.AuthCtrl = [ | |
'$scope', 'requests401', '$http', 'Ping', '$location', function($scope, requests401, $http, Ping, $location) { | |
var fadespeed = 300; | |
$scope.user = { | |
"username": "test", | |
"password": "test" | |
}; | |
$scope.$on('event:angular-auth-loginRequired', function() { | |
return $scope.showLogin(); | |
}); | |
$scope.loginConfirmed = function() { | |
requests401.retryAll(); | |
$('#login').fadeOut(fadespeed); | |
return $('#fade').fadeOut(fadespeed); | |
}; | |
$scope.logout = function() { | |
$.cookie('ss-id', null, { | |
path: '/' | |
}); | |
$.cookie('ss-pid', null, { | |
path: '/' | |
}); | |
$.cookie('ss-opt', null, { | |
path: '/' | |
}); | |
return Ping(); | |
}; | |
$scope.login = function(user) { | |
user.provider = "credentials"; | |
return $http.post('http://' + $location.host() + '/services/Auth', user).error(function(result) { | |
return alert(result.responseStatus.errorCode); | |
}).success(function() { | |
return $scope.loginConfirmed(); | |
}); | |
}; | |
$scope.showLogin = function() { | |
$('#login').fadeIn(fadespeed); | |
return $('#fade').fadeIn(fadespeed); | |
}; | |
return Ping(); | |
} | |
]; | |
angular.module('myApp.controllers', []).controller(mod); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment