2017-07-03 09:30:10 +02:00
|
|
|
/*!
|
2018-03-28 15:10:51 +02:00
|
|
|
* \copyright Copyright (c) 2016-2018 Governikus GmbH & Co. KG, Germany
|
2017-07-03 09:30:10 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "NumberModel.h"
|
2017-07-03 09:33:28 +02:00
|
|
|
|
2017-07-03 09:30:10 +02:00
|
|
|
#include "context/ChangePinContext.h"
|
2018-03-28 15:10:51 +02:00
|
|
|
#include "context/RemoteServiceContext.h"
|
2017-07-03 09:30:10 +02:00
|
|
|
#include "context/WorkflowContext.h"
|
2017-09-15 10:23:30 +02:00
|
|
|
#include "ReaderManager.h"
|
2017-07-03 09:30:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
using namespace governikus;
|
|
|
|
|
|
|
|
|
|
|
|
NumberModel::NumberModel(QObject* pParent)
|
|
|
|
: QObject(pParent)
|
|
|
|
{
|
2017-07-03 09:33:28 +02:00
|
|
|
connect(&ReaderManager::getInstance(), &ReaderManager::fireReaderPropertiesUpdated, this, &NumberModel::onReaderInfoChanged);
|
|
|
|
connect(&ReaderManager::getInstance(), &ReaderManager::fireCardRetryCounterChanged, this, &NumberModel::onReaderInfoChanged);
|
|
|
|
connect(&ReaderManager::getInstance(), &ReaderManager::fireReaderRemoved, this, &NumberModel::onReaderInfoChanged);
|
|
|
|
connect(&ReaderManager::getInstance(), &ReaderManager::fireCardRemoved, this, &NumberModel::onReaderInfoChanged);
|
2017-12-20 14:54:05 +01:00
|
|
|
connect(&ReaderManager::getInstance(), &ReaderManager::fireCardInserted, this, &NumberModel::onReaderInfoChanged);
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NumberModel::~NumberModel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-03 09:33:28 +02:00
|
|
|
void NumberModel::resetContext(const QSharedPointer<WorkflowContext>& pContext)
|
2017-07-03 09:30:10 +02:00
|
|
|
{
|
|
|
|
mContext = pContext;
|
|
|
|
if (mContext)
|
|
|
|
{
|
|
|
|
connect(mContext.data(), &WorkflowContext::fireCanChanged, this, &NumberModel::fireCanChanged);
|
|
|
|
connect(mContext.data(), &WorkflowContext::firePinChanged, this, &NumberModel::firePinChanged);
|
2018-06-20 13:59:17 +02:00
|
|
|
connect(mContext.data(), &WorkflowContext::fireCanAllowedModeChanged, this, &NumberModel::fireCanAllowedModeChanged);
|
2017-07-03 09:30:10 +02:00
|
|
|
|
2017-07-03 09:33:28 +02:00
|
|
|
const auto changePinContext = mContext.objectCast<ChangePinContext>();
|
2017-07-03 09:30:10 +02:00
|
|
|
if (changePinContext)
|
|
|
|
{
|
|
|
|
connect(changePinContext.data(), &ChangePinContext::fireNewPinChanged, this, &NumberModel::fireNewPinChanged);
|
|
|
|
connect(changePinContext.data(), &ChangePinContext::firePukChanged, this, &NumberModel::firePukChanged);
|
|
|
|
}
|
|
|
|
|
2017-07-03 09:33:28 +02:00
|
|
|
connect(mContext.data(), &WorkflowContext::fireCardConnectionChanged, this, &NumberModel::onCardConnectionChanged);
|
|
|
|
connect(mContext.data(), &WorkflowContext::fireReaderNameChanged, this, &NumberModel::fireReaderInfoChanged);
|
|
|
|
connect(mContext.data(), &WorkflowContext::fireLastPaceResultChanged, this, &NumberModel::fireInputErrorChanged);
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Q_EMIT fireCanChanged();
|
|
|
|
Q_EMIT firePinChanged();
|
|
|
|
Q_EMIT fireNewPinChanged();
|
|
|
|
Q_EMIT firePukChanged();
|
|
|
|
Q_EMIT fireInputErrorChanged();
|
2017-07-03 09:33:28 +02:00
|
|
|
Q_EMIT fireReaderInfoChanged();
|
2018-06-20 13:59:17 +02:00
|
|
|
Q_EMIT fireCanAllowedModeChanged();
|
2017-07-03 09:33:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NumberModel::continueWorkflow()
|
|
|
|
{
|
|
|
|
if (mContext)
|
|
|
|
{
|
|
|
|
mContext->setStateApproved();
|
|
|
|
}
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString NumberModel::getCan() const
|
|
|
|
{
|
|
|
|
return mContext ? mContext->getCan() : QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NumberModel::setCan(const QString& pCan)
|
|
|
|
{
|
|
|
|
if (mContext)
|
|
|
|
{
|
|
|
|
mContext->setCan(pCan);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString NumberModel::getPin() const
|
|
|
|
{
|
|
|
|
return mContext ? mContext->getPin() : QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NumberModel::setPin(const QString& pPin)
|
|
|
|
{
|
|
|
|
if (mContext)
|
|
|
|
{
|
|
|
|
mContext->setPin(pPin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString NumberModel::getNewPin() const
|
|
|
|
{
|
2017-07-03 09:33:28 +02:00
|
|
|
const auto changePinContext = mContext.objectCast<ChangePinContext>();
|
2017-07-03 09:30:10 +02:00
|
|
|
|
|
|
|
return changePinContext ? changePinContext->getNewPin() : QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NumberModel::setNewPin(const QString& pNewPin)
|
|
|
|
{
|
2017-07-03 09:33:28 +02:00
|
|
|
const auto changePinContext = mContext.objectCast<ChangePinContext>();
|
2017-07-03 09:30:10 +02:00
|
|
|
if (changePinContext)
|
|
|
|
{
|
|
|
|
changePinContext->setNewPin(pNewPin);
|
|
|
|
}
|
2018-03-28 15:10:51 +02:00
|
|
|
|
|
|
|
const auto remoteServiceContext = mContext.objectCast<RemoteServiceContext>();
|
|
|
|
if (remoteServiceContext)
|
|
|
|
{
|
|
|
|
remoteServiceContext->setNewPin(pNewPin);
|
|
|
|
}
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString NumberModel::getPuk() const
|
|
|
|
{
|
2017-07-03 09:33:28 +02:00
|
|
|
const auto changePinContext = mContext.objectCast<ChangePinContext>();
|
2017-07-03 09:30:10 +02:00
|
|
|
return changePinContext ? changePinContext->getPuk() : QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NumberModel::setPuk(const QString& pPuk)
|
|
|
|
{
|
2017-07-03 09:33:28 +02:00
|
|
|
const auto changePinContext = mContext.objectCast<ChangePinContext>();
|
2017-07-03 09:30:10 +02:00
|
|
|
if (changePinContext)
|
|
|
|
{
|
|
|
|
changePinContext->setPuk(pPuk);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-20 13:59:17 +02:00
|
|
|
bool NumberModel::hasError()
|
|
|
|
{
|
|
|
|
return !getInputError().isEmpty() || isExtendedLengthApdusUnsupported() || isPinDeactivated();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-03 09:30:10 +02:00
|
|
|
QString NumberModel::getInputError() const
|
|
|
|
{
|
2017-07-03 09:33:28 +02:00
|
|
|
if (mContext.isNull()
|
|
|
|
|| mContext->getLastPaceResult() == CardReturnCode::OK
|
|
|
|
|| mContext->getLastPaceResult() == CardReturnCode::CANCELLATION_BY_USER
|
|
|
|
|| mContext->getCardConnection().isNull())
|
2017-07-03 09:30:10 +02:00
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2017-07-03 09:33:28 +02:00
|
|
|
CardReturnCode paceResult = mContext->getLastPaceResult();
|
|
|
|
if (paceResult == CardReturnCode::INVALID_PIN)
|
2017-07-03 09:30:10 +02:00
|
|
|
{
|
|
|
|
int oldRetryCounter = mContext->getOldRetryCounter();
|
|
|
|
if (oldRetryCounter > 2)
|
|
|
|
{
|
2017-12-20 14:54:05 +01:00
|
|
|
return tr("The given PIN is not correct. You have 2 tries to enter the correct PIN.");
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
if (oldRetryCounter == 2)
|
|
|
|
{
|
2017-07-03 09:33:28 +02:00
|
|
|
return tr("You have entered the wrong PIN twice. "
|
2017-12-20 14:54:05 +01:00
|
|
|
"Prior to a third attempt, you have to enter your six-digit card access number first. "
|
2017-07-03 09:33:28 +02:00
|
|
|
"You can find your card access number on the front of your ID card.");
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
if (oldRetryCounter == 1)
|
|
|
|
{
|
|
|
|
return tr("You have entered a wrong PIN three times. "
|
|
|
|
"Your PIN is now blocked. "
|
2017-07-03 09:33:28 +02:00
|
|
|
"You have to enter the PUK now for unblocking.");
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-03 09:33:28 +02:00
|
|
|
if (paceResult == CardReturnCode::INVALID_CAN)
|
2017-07-03 09:30:10 +02:00
|
|
|
{
|
|
|
|
return tr("You have entered a wrong CAN, please try again.");
|
|
|
|
}
|
2017-07-03 09:33:28 +02:00
|
|
|
if (paceResult == CardReturnCode::INVALID_PUK)
|
2017-07-03 09:30:10 +02:00
|
|
|
{
|
|
|
|
return tr("You have entered a wrong PUK. "
|
|
|
|
"Please try again.");
|
|
|
|
}
|
2017-07-03 09:33:28 +02:00
|
|
|
return CardReturnCodeUtil::toGlobalStatus(paceResult).toErrorDescription(true);
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NumberModel::onCardConnectionChanged()
|
|
|
|
{
|
|
|
|
Q_ASSERT(mContext);
|
|
|
|
if (auto cardConnection = mContext->getCardConnection())
|
|
|
|
{
|
2017-07-03 09:33:28 +02:00
|
|
|
connect(cardConnection.data(), &CardConnection::fireReaderInfoChanged, this, &NumberModel::fireReaderInfoChanged);
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
2017-07-03 09:33:28 +02:00
|
|
|
Q_EMIT fireReaderInfoChanged();
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int NumberModel::getRetryCounter() const
|
|
|
|
{
|
|
|
|
if (mContext.isNull() || mContext->getCardConnection().isNull())
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return mContext->getCardConnection()->getReaderInfo().getRetryCounter();
|
|
|
|
}
|
|
|
|
}
|
2017-07-03 09:33:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
bool NumberModel::isExtendedLengthApdusUnsupported() const
|
|
|
|
{
|
|
|
|
if (mContext && !mContext->getReaderName().isEmpty())
|
|
|
|
{
|
|
|
|
ReaderInfo readerInfo = ReaderManager::getInstance().getReaderInfo(mContext->getReaderName());
|
2017-12-20 14:54:05 +01:00
|
|
|
return !readerInfo.sufficientApduLength();
|
2017-07-03 09:33:28 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool NumberModel::isPinDeactivated() const
|
|
|
|
{
|
|
|
|
if (mContext && !mContext->getReaderName().isEmpty())
|
|
|
|
{
|
|
|
|
return ReaderManager::getInstance().getReaderInfo(mContext->getReaderName()).isPinDeactivated();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool NumberModel::isCardConnected() const
|
|
|
|
{
|
|
|
|
if (mContext && !mContext->getReaderName().isEmpty())
|
|
|
|
{
|
2017-12-20 14:54:05 +01:00
|
|
|
return ReaderManager::getInstance().getReaderInfo(mContext->getReaderName()).hasCard();
|
2017-07-03 09:33:28 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-20 13:59:17 +02:00
|
|
|
bool NumberModel::isCanAllowedMode()
|
|
|
|
{
|
|
|
|
if (mContext)
|
|
|
|
{
|
|
|
|
return mContext->isCanAllowedMode();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-03 09:33:28 +02:00
|
|
|
void NumberModel::onReaderInfoChanged(const QString& pReaderName)
|
|
|
|
{
|
|
|
|
if (mContext && pReaderName == mContext->getReaderName())
|
|
|
|
{
|
|
|
|
Q_EMIT fireReaderInfoChanged();
|
|
|
|
}
|
|
|
|
}
|