Skip to content

Instantly share code, notes, and snippets.

@niisar
Created February 8, 2016 14:25
Show Gist options
  • Save niisar/9c127c3329d7e2068776 to your computer and use it in GitHub Desktop.
Save niisar/9c127c3329d7e2068776 to your computer and use it in GitHub Desktop.
AngularJSAuthentication.WEB
define(['app'], function (app) {
app.controller("loginCtrl", function ($scope, $http, $localStorage, $state, cnst) {
$scope.loginData = {
userName: "",
password: ""
}
$scope.message = "";
$scope.login = function () {
delete $localStorage.authorizationData;
var data = "grant_type=password&username=" + $scope.loginData.userName + "&password=" + $scope.loginData.password;
$http.post(cnst.serviceBase + 'token', data, {
headers: { 'Content-type': 'application/x-www-form-urlencoded' }
}).success(function (response) {
$localStorage.authorizationData = { token: response.access_token, userName: $scope.loginData.userName };
$scope.authentication = {
isAuth: true,
userName: $scope.loginData.userName
};
$scope.$emit('emitauthentication', { message: $scope.authentication });
$state.go('home')
}).error(function (err) {
$scope.authentication = {
isAuth: false,
userName: ""
};
});
}
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment