Skip to content

Instantly share code, notes, and snippets.

@nilswloka
Forked from corkupine/controllers.js
Created May 5, 2013 17:23
Show Gist options
  • Save nilswloka/5521470 to your computer and use it in GitHub Desktop.
Save nilswloka/5521470 to your computer and use it in GitHub Desktop.
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