Various cleanup.

This commit is contained in:
James Cole
2017-08-18 23:02:29 +02:00
parent 684c9773c9
commit ca0f09c8f7
2 changed files with 38 additions and 20 deletions

View File

@@ -20,10 +20,13 @@ use Session;
class BankController extends Controller class BankController extends Controller
{ {
/**
*
*/
public function form() public function form()
{ {
} }
/** /**
@@ -40,14 +43,12 @@ class BankController extends Controller
$object = app($class); $object = app($class);
$object->setUser(auth()->user()); $object->setUser(auth()->user());
if (!$object->hasPrerequisites()) { if (!$object->hasPrerequisites()) {
//Log::debug(sprintf('No more prerequisites for %s, move to form.', $bank)); Log::debug(sprintf('No more prerequisites for %s, move to form.', $bank));
//return redirect(route('import.bank.form', [$bank])); return redirect(route('import.bank.form', [$bank]));
} }
Log::debug('Going to store entered preprerequisites.'); Log::debug('Going to store entered preprerequisites.');
// store post data // store post data
$result = $object->storePrerequisites($request); $result = $object->storePrerequisites($request);
echo 'done with prereq';
exit;
if ($result->count() > 0) { if ($result->count() > 0) {
Session::flash('error', $result->first()); Session::flash('error', $result->first());
@@ -70,12 +71,12 @@ class BankController extends Controller
$object = app($class); $object = app($class);
$object->setUser(auth()->user()); $object->setUser(auth()->user());
//if ($object->hasPrerequisites()) { if ($object->hasPrerequisites()) {
$view = $object->getView(); $view = $object->getView();
$parameters = $object->getViewParameters(); $parameters = $object->getViewParameters();
return view($view, $parameters); return view($view, $parameters);
//} }
if (!$object->hasPrerequisites()) { if (!$object->hasPrerequisites()) {
return redirect(route('import.bank.form', [$bank])); return redirect(route('import.bank.form', [$bank]));

View File

@@ -28,7 +28,7 @@ use Requests;
use Requests_Exception; use Requests_Exception;
/** /**
* Class BunqPrerequisites * This class contains all the routines necessary to connect to Bunq.
* *
* @package FireflyIII\Support\Import\Prerequisites * @package FireflyIII\Support\Import\Prerequisites
*/ */
@@ -38,7 +38,7 @@ class BunqPrerequisites implements PrerequisitesInterface
private $user; private $user;
/** /**
* Returns view name that allows user to fill in prerequisites. * Returns view name that allows user to fill in prerequisites. Currently asks for the API key.
* *
* @return string * @return string
*/ */
@@ -59,7 +59,8 @@ class BunqPrerequisites implements PrerequisitesInterface
/** /**
* Returns if this import method has any special prerequisites such as config * Returns if this import method has any special prerequisites such as config
* variables or other things. * variables or other things. The only thing we verify is the presence of the API key. Everything else
* tumbles into place: no installation token? Will be requested. No device server? Will be created. Etc.
* *
* @return bool * @return bool
*/ */
@@ -83,6 +84,9 @@ class BunqPrerequisites implements PrerequisitesInterface
} }
/** /**
* This method responds to the user's submission of an API key. It tries to register this instance as a new Firefly III device.
* If this fails, the error is returned in a message bag and the user is notified (this is fairly friendly).
*
* @param Request $request * @param Request $request
* *
* @return MessageBag * @return MessageBag
@@ -93,14 +97,22 @@ class BunqPrerequisites implements PrerequisitesInterface
Log::debug('Storing bunq API key'); Log::debug('Storing bunq API key');
Preferences::setForUser($this->user, 'bunq_api_key', $apiKey); Preferences::setForUser($this->user, 'bunq_api_key', $apiKey);
// register Firefly III as a new device. // register Firefly III as a new device.
$serverId = $this->registerDevice(); $serverId = null;
$messages = new MessageBag;
try {
$serverId = $this->registerDevice();
Log::debug(sprintf('Found device server with id %d', $serverId->getId()));
} catch (FireflyException $e) {
$messages->add('error', $e->getMessage());
}
return $messages;
return new MessageBag;
} }
/** /**
* * This method creates a new public/private keypair for the user. This isn't really secure, since the key is generated on the fly with
* no regards for HSM's, smart cards or other things. It would require some low level programming to get this right. But the private key
* is stored encrypted in the database so it's something.
*/ */
private function createKeyPair(): void private function createKeyPair(): void
{ {
@@ -129,7 +141,8 @@ class BunqPrerequisites implements PrerequisitesInterface
} }
/** /**
* Get a list of servers and return the one that is this FF instance, if one can be found. * When the device server cannot be registered for some reason (when previous attempts failed to be stored) this method can be used
* to try and detect the server ID for this firefly instance.
* *
* @return DeviceServerId * @return DeviceServerId
* @throws FireflyException * @throws FireflyException
@@ -185,7 +198,7 @@ class BunqPrerequisites implements PrerequisitesInterface
Preferences::setForUser($this->user, 'bunq_installation_id', $installationId); Preferences::setForUser($this->user, 'bunq_installation_id', $installationId);
Preferences::setForUser($this->user, 'bunq_server_public_key', $serverPublicKey); Preferences::setForUser($this->user, 'bunq_server_public_key', $serverPublicKey);
exit; return $installationToken;
} }
/** /**
@@ -229,7 +242,10 @@ class BunqPrerequisites implements PrerequisitesInterface
} }
/** /**
* Let's assume this value will not change any time soon. * Request users server remote IP. Let's assume this value will not change any time soon.
*
* @return string
* @throws FireflyException
*/ */
private function getRemoteIp(): string private function getRemoteIp(): string
{ {
@@ -253,6 +269,8 @@ class BunqPrerequisites implements PrerequisitesInterface
} }
/** /**
* Get the public key of the server, necessary to verify server signature.
*
* @return ServerPublicKey * @return ServerPublicKey
*/ */
private function getServerPublicKey(): ServerPublicKey private function getServerPublicKey(): ServerPublicKey
@@ -304,9 +322,8 @@ class BunqPrerequisites implements PrerequisitesInterface
Preferences::setForUser($this->user, 'bunq_device_server_id', $deviceServerId); Preferences::setForUser($this->user, 'bunq_device_server_id', $deviceServerId);
Log::debug(sprintf('Server ID: %s', serialize($deviceServerId))); Log::debug(sprintf('Server ID: %s', serialize($deviceServerId)));
var_dump($deviceServerId);
var_dump($installationToken); return $deviceServerId;
exit;
} }
} }