var KrempelAirApp = angular.module('KrempelAirApp', ['ngRoute']);
var uri = "/api"

KrempelAirApp.config(['$locationProvider', function($locationProvider) {
  $locationProvider.hashPrefix('');
}]);


KrempelAirApp.config(function ($routeProvider) {
  $routeProvider
      .when('/', {
        templateUrl: '../views/air.html',
        controller: 'MainCtrl'
      })
      .when('/login', {
        //template: '<form ng-submit="login()" name="loginForm"> username: <input type="text" ng-model="user.username"> <br/> password: <input type="password" ng-model="user.password"><button>login</button></form>',
        templateUrl: '../views/login.html',
        controller: 'LoginCtrl'
      })
      .otherwise({
        redirectTo: '/'
      });
})

KrempelAirApp.factory('Auth', function ($rootScope, $window, $http) {
  return {
    login: function (user, successHandler, errorHandler) {
      if (user.username == 'test' && user.password == 'test') {
        this.setLoggedInUser(user);
        successHandler(user);
      } else {
        alert("please use username/password as test/test to login");
        errorHandler(user);
      }

      // call the server side login restful api
//      $http.post('api/login', user).success(function(user) {
//        this.setLoggedInUser(user);
//        successHandler(user);
//      }).error(errorHandler);
    },
    getLoggedInUser: function () {
      if ($rootScope.user === undefined || $rootScope.user == null) {
        var userStr = $window.sessionStorage.getItem('user');
        if (userStr) {
          $rootScope.user = angular.fromJson(userStr);
        }
      }
      return $rootScope.user;
    },
    isLoggedIn: function () {
      return this.getLoggedInUser() != null;
    },
    setLoggedInUser: function (user) {
      $rootScope.user = user;
      if (user == null) {
        $window.sessionStorage.removeItem('user');
      } else {
        $window.sessionStorage.setItem('user', angular.toJson($rootScope.user));
      }
    }
  };
})

KrempelAirApp.controller('LoginCtrl', function ($scope, Auth, $location, $http) {
  $scope.user = {};

  $scope.login = function () {
    Auth.login($scope.user, function () {
      $location.path('/');
    }, function (e) {
      // do some error handling.
    });
  };
})

KrempelAirApp.controller('MainCtrl', function ($scope, Auth, $location) {

  $scope.logout = function () {
    Auth.setLoggedInUser(null);
    $location.path('/somewhere');
  };
})

KrempelAirApp.run(['$window', '$rootScope', '$location', 'Auth', function ($window, $rootScope, $location, Auth) {

    $rootScope.$on("$routeChangeStart", function (event) {
      if (!Auth.isLoggedIn() &&
          $location.path() !== '/login') {
        $location.path('/login');
      }
    });
}]);


KrempelAirApp.controller('AirFlowController', function AirFlowController($scope, $http, $timeout) {


    $scope.Refresh = function(){
        $http.get(uri+"/").then(function (response) {
            $scope.status = response.data;
        });
        $http.get(uri+"/stoerung").then(function (response) {
            $scope.stoerung = response.data;
        });
        $http.get(uri+"/lueftung/temperatur").then(function (response) {
            $scope.temperatur = response.data;
            if($scope.sollTemp && (parseFloat(parseFloat($scope.sollTemp).toFixed(2)) !== parseFloat(parseFloat(response.data["TempSoll"]).toFixed(2)))){
                $http.get(uri+"/lueftung/temperatur/sollTemp/"+parseFloat($scope.sollTemp));
            }else{
                $scope.sollTemp = response.data["TempSoll"];
            }
            if($scope.sollTempNAK && (parseFloat(parseFloat($scope.sollTempNAK).toFixed(2)) !== parseFloat(parseFloat(response.data["TempSollNAK"]).toFixed(2)))){
                $http.get(uri+"/lueftung/temperatur/sollTempNAK/"+parseFloat($scope.sollTempNAK));
            }else{
                $scope.sollTempNAK = response.data["TempSollNAK"];
            }
        });


        $timeout(function(){
         $scope.Refresh();
        },800);
    }
    $scope.Klick = function(Klick){
        $http.get(uri+"/lueftung/stufe/"+Klick);
        $scope.Refresh();
    }

    $scope.Refresh();
});

@@ -341,24 +341,33 @@
 oller: '
-MainCtrl
+AirFlowController
 '%0A      
@@ -397,224 +397,8 @@
 , %7B%0A
-        //template: '%3Cform ng-submit=%22login()%22 name=%22loginForm%22%3E username: %3Cinput type=%22text%22 ng-model=%22user.username%22%3E %3Cbr/%3E password: %3Cinput type=%22password%22 ng-model=%22user.password%22%3E%3Cbutton%3Elogin%3C/button%3E%3C/form%3E',%0A
     
@@ -1785,32 +1785,338 @@
 %0A    %7D%0A  %7D;%0A%7D)%0A%0A
+KrempelAirApp.run(%5B'$window', '$rootScope', '$location', 'Auth', function ($window, $rootScope, $location, Auth) %7B%0A%0A    $rootScope.$on(%22$routeChangeStart%22, function (event) %7B%0A      if (!Auth.isLoggedIn() &&%0A          $location.path() !== '/login') %7B%0A        $location.path('/login');%0A      %7D%0A    %7D);%0A%7D%5D);%0A%0A
 KrempelAirApp.co
@@ -2560,315 +2560,8 @@
 %7D)%0A%0A
-KrempelAirApp.run(%5B'$window', '$rootScope', '$location', 'Auth', function ($window, $rootScope, $location, Auth) %7B%0A%0A    $rootScope.$on(%22$routeChangeStart%22, function (event) %7B%0A      if (!Auth.isLoggedIn() &&%0A          $location.path() !== '/login') %7B%0A        $location.path('/login');%0A      %7D%0A    %7D);%0A%7D%5D);%0A%0A%0A
 Krem

Update main.js