Advertisement
Guest User

Untitled

a guest
Mar 27th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. var app = angular.module('webApp.controller.LoginCtrl', []);
  2. app.controller('LoginCtrl', function($rootScope, $scope, $http, $state, urlFactory) {
  3. var backendUrl = urlFactory.getValue();
  4. this.state = $state;
  5. delete $rootScope.userRole;
  6.  
  7. $scope.getCredentials = function(username,password){
  8. $http({
  9. method : 'POST',
  10. url : backendUrl + '/api/v1/authorization',
  11. data : {
  12. username: username,
  13. password: password
  14. }
  15. }).then(function successCallback(response){
  16. if (response.status === 200){
  17. var result = response.data;
  18. if(result !== undefined && result.length !== 0){
  19. $scope.errSMSLogIn = null;
  20. var userRole = response.data[0].role;
  21. var userName = response.data[0].username;
  22. $rootScope.userRole = userRole;
  23. $rootScope.userName = userName;
  24. $state.transitionTo('main');
  25. }else{
  26. $scope.errSMSLogIn = 'Incorrect username or password'
  27. }
  28. }else {
  29. $scope.errSMSLogIn = 'Incorrect username or password'
  30. }
  31. }, function errorCallback(response){
  32. console.log("connection error: ", JSON.stringify(response))
  33. });
  34. };
  35. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement