From 1d7c8f2e94369a4ad918276fc6134253b9f180c7 Mon Sep 17 00:00:00 2001 From: Pushkar Anand Date: Sat, 2 Jun 2018 18:16:52 +0530 Subject: [PATCH] Fixes + Null Check for wallet get. + Key check while login. --- src/app/DALs/WalletDAL.php | 4 ++-- src/app/Services/WalletService.php | 6 ++++++ src/app/Utils/error.php | 2 ++ src/public/js/controllers/registerCtrl.js | 3 +++ src/public/templates/views/public/register.html | 3 ++- 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/app/DALs/WalletDAL.php b/src/app/DALs/WalletDAL.php index 2a9a75d..2d40f55 100644 --- a/src/app/DALs/WalletDAL.php +++ b/src/app/DALs/WalletDAL.php @@ -42,10 +42,10 @@ public static function createWallet(String $address, int $timestamp, int $bcHeig public static function getWallet(String $address) { $wallet = Wallet::where('address', $address)->first(); - if ($wallet->transfers[0] == 'W') { + if ($wallet && $wallet->transfers[0] == 'W') { $wallet->transfers = self::getFile($wallet->transfers); } - if ($wallet->keyImages[0] == 'W') { + if ($wallet && $wallet->keyImages[0] == 'W') { $wallet->keyImages = self::getFile($wallet->keyImages); } Log::debug($wallet); diff --git a/src/app/Services/WalletService.php b/src/app/Services/WalletService.php index 5f53c25..ff825a5 100644 --- a/src/app/Services/WalletService.php +++ b/src/app/Services/WalletService.php @@ -96,6 +96,12 @@ public function setWallet(Request $request) { throw error::getBadRequestException(error::WALLET_NOT_FOUND); } + // Check if wallet address matches the key + $this->rpcService->setWallet(new SetWalletRequest( + $address, $viewKey, $wallet->createTime, $wallet->bcHeight, + $wallet->transfers, $wallet->keyImages + )); + // Generate a new session. $request->session()->regenerate(); diff --git a/src/app/Utils/error.php b/src/app/Utils/error.php index 7baeba9..6fa66ce 100644 --- a/src/app/Utils/error.php +++ b/src/app/Utils/error.php @@ -26,6 +26,7 @@ class error const SESSION_EXPIRED = "sessionExpired"; const REFRESH_LOCKED = "refreshLocked"; const WALLET_ALREADY_RESET = "walletAlreadyReset"; + const WALLET_KEY_MISMATCH = "walletKeyMismatch"; /** * Contains all error code and description for each key. @@ -46,6 +47,7 @@ class error // Wallet erros self::WALLET_ALREADY_RESET => array("code" => 1200, "message" => "Wallet can be reset only once. Contact admins"), + self::WALLET_KEY_MISMATCH => array("code" => 1201, "message" => "Provided key didn't match the address."), // These errors should never happen! // Its over 9000! :P diff --git a/src/public/js/controllers/registerCtrl.js b/src/public/js/controllers/registerCtrl.js index 7b60547..05837ea 100644 --- a/src/public/js/controllers/registerCtrl.js +++ b/src/public/js/controllers/registerCtrl.js @@ -72,6 +72,9 @@ angular.module('aeonPocket').controller('registerCtrl', [ userService.create($scope.viewWallet).then(function(data) { $mdToast.showSimple("Account Created"); $state.go('public.login'); + }, function (data) { + $scope.viewWalletForm.address.$setValidity('validation', false); + $scope.errorMessage = data.message; }); } } diff --git a/src/public/templates/views/public/register.html b/src/public/templates/views/public/register.html index 0529342..ba86384 100644 --- a/src/public/templates/views/public/register.html +++ b/src/public/templates/views/public/register.html @@ -82,13 +82,14 @@

-
+
Required
+
{{errorMessage}}