Created
February 8, 2016 14:25
-
-
Save niisar/9c127c3329d7e2068776 to your computer and use it in GitHub Desktop.
AngularJSAuthentication.WEB
This file contains hidden or 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
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