Created
September 23, 2014 17:11
-
-
Save cerkit/7f19e63935f8a5b23238 to your computer and use it in GitHub Desktop.
AngularJS Client for Basic authentication - Credentials Controller
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
function CredentialsController($scope, $http, $cookieStore, Base64) { | |
$scope.login = function (userName, password) { | |
var encodedUserNameAndPassword = Base64.encode(userName + ':' + password); | |
$http.defaults.headers.common['Authorization'] = 'Basic ' + encodedUserNameAndPassword; | |
$cookieStore.put('basicCredentials', encodedUserNameAndPassword); | |
$http.get(baseUrl + '/Values') | |
.success(function() { | |
$scope.$broadcast('event:auth-loginConfirmed'); | |
$scope.password = ''; | |
}) | |
.error(function() { | |
$scope.error = 'Invalid Login'; | |
} ); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment