Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I got assigned to fix a problem left by another developer who just changed jobs, and I'm not having very much luck with it.

The application is a time entry site that allows users to log in with their existing Windows credentials to manage their time. I can pass their username and password in JSON via Postman to the login page and it will authenticate, however, when the same credentials are entered into the form via browser, it fails.

I've posted some screenshots and code behind the login page below. If there's anything else you need to see, just let me know.

http://delorean.cisng888.csa/

Album hosted on sli.mg[^]

JavaScript
(function() {
  angular.module('Thunderdome').controller('LoginController', function($http, $scope, $rootScope, $location, $cookieStore, $state, loggedInUser, Logout, RetrieveSystemStatus) {
	RetrieveSystemStatus.retrieveStatus()
		.then(function(data){
			if(data[1].Value == "0")
			{
				$rootScope.systemStatus = data[1].Value;
				$rootScope.systemMessage = "";
				executeController()
			}
			else if(data[1].Value == "-1")
			{
			
				$rootScope.systemMessage = data[0].Value;
				$scope.message = $rootScope.systemMessage;
				$rootScope.systemStatus = data[1].Value;
			}
			else
			{
				$rootScope.systemMessage = data[0].Value;
				$scope.message = $rootScope.systemMessage;
				$rootScope.systemStatus = data[1].Value;
				executeController();
			}				
		},
		function(error){
		});
		
	function executeController()
	{
		//////////////////////////////////////////////////////////////////////////////
		//Initial Information
		$scope.message = ($rootScope.systemMessage == "" ? "Welcome to Time Entry." : $rootScope.systemMessage);
		$scope.username = "";
		$scope.password = "";
		$scope.returnedData = {};
		$scope.userAlreadyLoggedIn = false;
		$scope.showModal = false;
		
		if(!loggedInUser.getProfile().init)
		{
			if(!loggedInUser.getProfile().errors.length)
			{
				$state.go('home.main');
			}
			else
			{
				$scope.message = loggedInUser.getProfile().errors[0].message;
			}
		}
		/////////////////////////////////////////////////////////////////////////////////
		//Function: login()
		//Upon the user submisssion, perform the service call to build the user/employee's information for usage throughout the application.
		$scope.login = function()
		{
			var data = {
							"userName": $scope.username,
							"password": $scope.password,
							"browserString": navigator.appName
					}
			$http({
				  method: 'post',
				  url: 'http://10.1.150.174:8002/TimeEntry.svc/Login', 
				  headers: {'Content-Type':'application/json; charset=UTF-8; charset-uf8'},
				  data: data
				})
			.success(function(data, status, headers, config) {
				$scope.returnedData = data;
				evaluateSuccessfulRetrieval();
			})
			.error(function(data, status, headers, config) {
				$scope.message = "Oops, there has been issue.";
			});
				
		}
		
		/////////////////////////////////////////////////////////////////////////////////
		//Function: evaluateSuccessfulRetrieval(data)
		//Takes the information and evaluates for any errors that may have been returned.
		function evaluateSuccessfulRetrieval()
		{
			
			if($scope.returnedData.errors.length > 0)
				handleReturnedError($scope.returnedData.errors);
			else
			{
				$cookieStore.put("FunStuff", $scope.returnedData.auth);
				loggedInUser.setProfile($scope.returnedData);
				$state.go('home.main');
			}
			
		}
		
		/////////////////////////////////////////////////////////////////////////////////
		//Function: handleReturnedError(errors)
		//Handle any returned errors from the service call.
		function handleReturnedError(errors)
		{
			if(errors[0].code != 2)
				$scope.message = errors[0].message;
			else
				handleUserAlreadyLoggedIn();
		}
		
		/////////////////////////////////////////////////////////////////////////////////
		//Function: handleUserAlreadyLoggedIn()
		//Display the modal and remove the ability of the user to access the form elements.
		function handleUserAlreadyLoggedIn()
		{
			$scope.userAlreadyLoggedIn = true;
			$scope.showModal = true;
		}
		
		/////////////////////////////////////////////////////////////////////////////////
		//Function: handleUserAlreadyLoggedIn()
		//Handles the exception when a user is logged in elsewhere ro their session is still active.
		$scope.logout = function(code)
		{
			$scope.showModal = false;
			
			if(code == '2')
				logOutOtherLocation();
			else
				$scope.userAlreadyLoggedIn = false;
		}
		
		/////////////////////////////////////////////////////////////////////////////////
		//Function: logOutOtherLocation()
		//Log out the user's other session and proceed to log in this session.
		function logOutOtherLocation()
		{
			var logoutdata = {
							"Auth": "",
							"EmployeeID": $scope.username,
							"LogoutType": "2"
							}
			
			Logout.logout(logoutdata)
			.then(function(data){
				$scope.login();
			},
			function(error){
				$scope.message = "Oops, there has been issue.";
				$scope.userAlreadyLoggedIn = false;
			});
		}
	}
	
	
    });
}());


What I have tried:

Checked the code and tinkered with setting in IIS manager
Posted
Updated 22-Jun-16 9:22am
Comments
ZurdoDev 22-Jun-16 10:47am    
What does failed mean? And why don't you just debug the code?
Member 12598238 22-Jun-16 14:49pm    
It returns a "failed to authenticate user" message. See the images linked.
ZurdoDev 22-Jun-16 14:58pm    
But how would we know why your code isn't working? You need to debug it. We can't run it.

1 solution

The problem with a HOSTNAME variable in a configuration file that pointed to the wrong server. Once I changed it to the server where the files were currently being hosted, everything worked fine!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900