'use strict';

function LoginCtrl($scope, auth) {
	var credentials = {
		username: "",
		password: ""
    };
    
    $scope.credentials = credentials;
    $scope.restricted = window.restrictedMode;
    $scope.needpass = function(){
        var val = $scope.restricted && $scope.credentials.username=="admin";
        return val || auth.getLdap();
    };
	$scope.login = function() {

        if($scope.credentials.username.length<1 ){
            alert("Username is required!");
            return false;
        }

        if( $scope.needpass() && $scope.credentials.password.length<1 ) {
            alert("Password is required!");
            return false;
        }

		auth.login($scope.credentials.username, $scope.credentials.password, true);
	};
}