function LoginControllerUUID($injector, $scope, $http, $location, $modalInstance, $q, userService, uuid) {
  $scope.login = {
    uuid: uuid
  }

  Login($injector, $scope, $http, $location, $modalInstance, $q, userService);
}

function LoginController($injector, $scope, $http, $location, $modalInstance, $q, userService) {
  Login($injector, $scope, $http, $location, $modalInstance, $q, userService);
}

// Helper (Not sure if this can be fixed with providers)
function Login($injector, $scope, $http, $location, $modalInstance, $q, userService) {
  $scope.dismiss = $modalInstance.dismiss;
  
  $scope.loginInProgress = false;
  $scope.login.title == undefined ? $scope.login.title = 'Login' : $scope.login.title;
  $scope.login.button == undefined ? $scope.login.button = 'Open Wallet' : $scope.login.button;
  
  $scope.open = function(login) {
    var uuid = login.uuid;
    if ( verifyUUID(uuid) == false ) {
      $scope.missingUUID = true;
      return 0;
    }

    var asymKey = {};
    var walletKey = '';
    var nonce = 0;
    $scope.loginInProgress = true;
    $scope.missingUUID = false;
    $scope.badPassword = false;
    $scope.serverError = false;

    $http.get('/v1/user/wallet/challenge?uuid=' + uuid)
      .then(function(result) {
        var data = result.data;
        var asyncCrypto = $q.defer();

        // daisy chain several async crypto calls into a promise
        CryptUtilAsync.generateNonceForDifficulty(data.pow_challenge, function(result) {
          nonce = result;
          CryptUtilAsync.generateSymmetricKey(login.password, data.salt, function(result) {
            walletKey = result;
            CryptUtilAsync.generateAsymmetricPair(function(result) {
              asymKey = result;
              encodedPub = window.btoa(asymKey.pubPem);
              $scope.$apply(function() {
                asyncCrypto.resolve();
              });
            });
          });
        });

        return asyncCrypto.promise;
      })
      .then(function(result) {
        return $http({
          url: '/v1/user/wallet/login',
          method: 'GET',
          params: {
            nonce: nonce,
            public_key: encodedPub,
            uuid: uuid
          }
        });
      })
      .then(function(result) {
      var data = result.data;
      try {
        var wallet = CryptUtil.decryptObject(data, walletKey);
        userService.login(wallet, walletKey, asymKey);
        if( $scope.login != undefined && $scope.login.action == 'verify' ) {
          $modalInstance.close(wallet) //pass wallet as verification
        } else {
          console.log('after')
          userService.login(wallet, walletKey, asymKey);
          $modalInstance.close()
          $location.path('/wallet');
        }
      } catch (e) {
        $scope.badPassword = true;
        $scope.loginInProgress = false;
      }
    }, function(result) {
      if (result.status == 403) {
        $scope.missingUUID = true;
      } else {
        $scope.serverError = true;
      }
      $scope.loginInProgress = false;
    });
  };
}


@@ -79,27 +79,23 @@
 ce, $q, 
-userService
+Account
 , uuid) 
@@ -196,35 +196,31 @@
 stance, $q, 
-userService
+Account
 );%0A%7D%0A%0Afuncti
@@ -291,35 +291,31 @@
 stance, $q, 
-userService
+Account
 ) %7B%0A  Login(
@@ -371,27 +371,23 @@
 ce, $q, 
-userService
+Account
 );%0A%7D%0A%0A//
@@ -513,27 +513,23 @@
 ce, $q, 
-userService
+Account
 ) %7B%0A  $s
@@ -832,40 +832,21 @@
     
-var uuid = login.uuid;%0A    if ( 
+if ( Account.
 veri
@@ -931,73 +931,8 @@
  %7D%0A%0A
-    var asymKey = %7B%7D;%0A    var walletKey = '';%0A    var nonce = 0;%0A
     
@@ -1067,1259 +1067,73 @@
     
-$http.get('/v1/user/wallet/challenge?uuid=' + uuid)%0A      .then(function(result) %7B%0A        var data = result.data;%0A        var asyncCrypto = $q.defer();%0A%0A        // daisy chain several async crypto calls into a promise%0A        CryptUtilAsync.generateNonceForDifficulty(data.pow_challenge, function(result) %7B%0A          nonce = result;%0A          CryptUtilAsync.generateSymmetricKey(login.password, data.salt, function(result) %7B%0A            walletKey = result;%0A            CryptUtilAsync.generateAsymmetricPair(function(result) %7B%0A              asymKey = result;%0A              encodedPub = window.btoa(asymKey.pubPem);%0A              $scope.$apply(function() %7B%0A                asyncCrypto.resolve();%0A              %7D);%0A            %7D);%0A          %7D);%0A        %7D);%0A%0A        return asyncCrypto.promise;%0A      %7D)%0A      .then(function(result) %7B%0A        return $http(%7B%0A          url: '/v1/user/wallet/login',%0A          method: 'GET',%0A          params: %7B%0A            nonce: nonce,%0A            public_key: encodedPub,%0A            uuid: uuid%0A          %7D%0A        %7D);%0A      %7D)%0A      .then(function(resul
+Account.login(login.uuid,login.password).then(function(accoun
 t)
- 
 %7B%0A
-      var data = result.data;%0A      try %7B%0A        var wallet = CryptUtil.decryptObject(data, walletKey);%0A        userService.login(wallet, walletKey, asymKey);%0A  
     
@@ -1203,34 +1203,32 @@
 fy' ) %7B%0A        
-  
 $modalInstance.c
@@ -1232,21 +1232,22 @@
 e.close(
-walle
+accoun
 t) //pas
@@ -1273,26 +1273,24 @@
 ation%0A      
-  
 %7D else %7B%0A   
@@ -1290,98 +1290,8 @@
 e %7B%0A
-          console.log('after')%0A          userService.login(wallet, walletKey, asymKey);%0A  
     
@@ -1325,18 +1325,16 @@
         
- 
- 
 $locatio
@@ -1356,113 +1356,8 @@
 ');%0A
-        %7D%0A      %7D catch (e) %7B%0A        $scope.badPassword = true;%0A        $scope.loginInProgress = false;%0A
     
@@ -1366,17 +1366,16 @@
 %7D%0A    %7D,
- 
 function
@@ -1379,195 +1379,70 @@
 ion(
-result) %7B%0A      if (result.status == 403) %7B%0A        $scope.missingUUID = true;%0A      %7D else %7B%0A        $scope.serverError = true
+error)%7B%0A      angular.extend($scope,error)
 ;%0A    
- 
- 
 %7D
+)
 %0A      
-$scope.loginInProgress = false;%0A    %7D);
+  
 %0A  %7D;%0A%7D
-%0A%0A

Refactor - implement Account and Wallet services on LoginController