Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var app = angular.module('webApp.controller.LoginCtrl', []);
- app.controller('LoginCtrl', function($rootScope, $scope, $http, $state, urlFactory) {
- var backendUrl = urlFactory.getValue();
- this.state = $state;
- delete $rootScope.userRole;
- $scope.getCredentials = function(username,password){
- $http({
- method : 'POST',
- url : backendUrl + '/api/v1/authorization',
- data : {
- username: username,
- password: password
- }
- }).then(function successCallback(response){
- if (response.status === 200){
- var result = response.data;
- if(result !== undefined && result.length !== 0){
- $scope.errSMSLogIn = null;
- var userRole = response.data[0].role;
- var userName = response.data[0].username;
- $rootScope.userRole = userRole;
- $rootScope.userName = userName;
- $state.transitionTo('main');
- }else{
- $scope.errSMSLogIn = 'Incorrect username or password'
- }
- }else {
- $scope.errSMSLogIn = 'Incorrect username or password'
- }
- }, function errorCallback(response){
- console.log("connection error: ", JSON.stringify(response))
- });
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement