register: fix token verification part if error in account creation
This commit is contained in:
parent
77fad7ba86
commit
7970cd49f0
6 changed files with 147 additions and 103 deletions
|
|
@ -65,8 +65,11 @@ void RegisterPage::registerNewAccount(const QString &username,
|
||||||
});
|
});
|
||||||
connect(accountManager, &AccountManager::registerNewAccountFailed, this,
|
connect(accountManager, &AccountManager::registerNewAccountFailed, this,
|
||||||
[this, accountManager](const QString &errorMessage) mutable {
|
[this, accountManager](const QString &errorMessage) mutable {
|
||||||
App::postCoreAsync(
|
App::postCoreAsync([this, errorMessage]() {
|
||||||
[this, errorMessage, accountManager]() { emit registerNewAccountFailed(errorMessage); });
|
mLastRegisterAddress.clear();
|
||||||
|
mLastConvertedToken.clear();
|
||||||
|
emit registerNewAccountFailed(errorMessage);
|
||||||
|
});
|
||||||
if (accountManager) {
|
if (accountManager) {
|
||||||
accountManager->deleteLater();
|
accountManager->deleteLater();
|
||||||
accountManager = nullptr;
|
accountManager = nullptr;
|
||||||
|
|
@ -81,8 +84,16 @@ void RegisterPage::registerNewAccount(const QString &username,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connect(accountManager, &AccountManager::tokenConversionSucceed, this,
|
connect(accountManager, &AccountManager::tokenConversionSucceed, this,
|
||||||
[this, accountManager]() { App::postCoreAsync([this]() { emit tokenConversionSucceed(); }); });
|
[this, accountManager, address](QString convertedToken) {
|
||||||
accountManager->registerNewAccount(username, password, registerType, address);
|
App::postCoreAsync([this, convertedToken, address]() {
|
||||||
|
mLastRegisterAddress = address;
|
||||||
|
mLastConvertedToken = convertedToken;
|
||||||
|
emit tokenConversionSucceed();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
accountManager->registerNewAccount(username, password, registerType, address,
|
||||||
|
QString::compare(mLastRegisterAddress, address) ? QString()
|
||||||
|
: mLastConvertedToken);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,7 +103,11 @@ void RegisterPage::linkNewAccountUsingCode(const QString &code,
|
||||||
App::postModelAsync([=]() {
|
App::postModelAsync([=]() {
|
||||||
auto accountManager = new AccountManager();
|
auto accountManager = new AccountManager();
|
||||||
connect(accountManager, &AccountManager::linkingNewAccountWithCodeSucceed, this, [this, accountManager]() {
|
connect(accountManager, &AccountManager::linkingNewAccountWithCodeSucceed, this, [this, accountManager]() {
|
||||||
App::postCoreAsync([this]() { emit linkingNewAccountWithCodeSucceed(); });
|
App::postCoreAsync([this]() {
|
||||||
|
mLastRegisterAddress.clear();
|
||||||
|
mLastConvertedToken.clear();
|
||||||
|
emit linkingNewAccountWithCodeSucceed();
|
||||||
|
});
|
||||||
accountManager->deleteLater();
|
accountManager->deleteLater();
|
||||||
});
|
});
|
||||||
connect(accountManager, &AccountManager::linkingNewAccountWithCodeFailed, this,
|
connect(accountManager, &AccountManager::linkingNewAccountWithCodeFailed, this,
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,10 @@ private:
|
||||||
QSharedPointer<SafeConnection<RegisterPage, AccountManager>> mAccountManagerConnection;
|
QSharedPointer<SafeConnection<RegisterPage, AccountManager>> mAccountManagerConnection;
|
||||||
std::shared_ptr<AccountManager> mAccountManager;
|
std::shared_ptr<AccountManager> mAccountManager;
|
||||||
QString mErrorMessage;
|
QString mErrorMessage;
|
||||||
|
// Usefull to skip token verification part if the account
|
||||||
|
// creation failed for an existing username
|
||||||
|
QString mLastRegisterAddress;
|
||||||
|
QString mLastConvertedToken;
|
||||||
|
|
||||||
DECLARE_ABSTRACT_OBJECT
|
DECLARE_ABSTRACT_OBJECT
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,8 @@ bool AccountManager::login(QString username,
|
||||||
void AccountManager::registerNewAccount(const QString &username,
|
void AccountManager::registerNewAccount(const QString &username,
|
||||||
const QString &password,
|
const QString &password,
|
||||||
RegisterType type,
|
RegisterType type,
|
||||||
const QString ®isterAddress) {
|
const QString ®isterAddress,
|
||||||
|
QString lastToken) {
|
||||||
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
|
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
|
||||||
if (!mAccountManagerServicesModel) {
|
if (!mAccountManagerServicesModel) {
|
||||||
auto core = CoreModel::getInstance()->getCore();
|
auto core = CoreModel::getInstance()->getCore();
|
||||||
|
|
@ -163,7 +164,7 @@ void AccountManager::registerNewAccount(const QString &username,
|
||||||
} else if (request->getType() == linphone::AccountManagerServicesRequest::Type::
|
} else if (request->getType() == linphone::AccountManagerServicesRequest::Type::
|
||||||
AccountCreationTokenFromAccountCreationRequestToken) {
|
AccountCreationTokenFromAccountCreationRequestToken) {
|
||||||
qDebug() << "[AccountManager] request token conversion succeed" << data;
|
qDebug() << "[AccountManager] request token conversion succeed" << data;
|
||||||
emit tokenConversionSucceed();
|
emit tokenConversionSucceed(Utils::coreStringToAppString(data));
|
||||||
timer.stop();
|
timer.stop();
|
||||||
mAccountManagerServicesModel->createAccountUsingToken(Utils::appStringToCoreString(username),
|
mAccountManagerServicesModel->createAccountUsingToken(Utils::appStringToCoreString(username),
|
||||||
Utils::appStringToCoreString(password), data);
|
Utils::appStringToCoreString(password), data);
|
||||||
|
|
@ -253,7 +254,14 @@ void AccountManager::registerNewAccount(const QString &username,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mAccountManagerServicesModel->requestToken();
|
if (lastToken.isEmpty()) {
|
||||||
|
mAccountManagerServicesModel->requestToken();
|
||||||
|
} else {
|
||||||
|
emit tokenConversionSucceed(lastToken);
|
||||||
|
mAccountManagerServicesModel->createAccountUsingToken(Utils::appStringToCoreString(username),
|
||||||
|
Utils::appStringToCoreString(password),
|
||||||
|
Utils::appStringToCoreString(lastToken));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountManager::linkNewAccountUsingCode(const QString &code,
|
void AccountManager::linkNewAccountUsingCode(const QString &code,
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,8 @@ public:
|
||||||
void registerNewAccount(const QString &username,
|
void registerNewAccount(const QString &username,
|
||||||
const QString &password,
|
const QString &password,
|
||||||
RegisterType type,
|
RegisterType type,
|
||||||
const QString ®isterAddress);
|
const QString ®isterAddress,
|
||||||
|
QString lastToken = QString());
|
||||||
|
|
||||||
void linkNewAccountUsingCode(const QString &code, RegisterType registerType, const QString &sipAddress);
|
void linkNewAccountUsingCode(const QString &code, RegisterType registerType, const QString &sipAddress);
|
||||||
|
|
||||||
|
|
@ -61,7 +62,7 @@ signals:
|
||||||
void registrationStateChanged(linphone::RegistrationState state);
|
void registrationStateChanged(linphone::RegistrationState state);
|
||||||
void newAccountCreationSucceed(QString sipAddress, RegisterType registerType, const QString ®isterAddress);
|
void newAccountCreationSucceed(QString sipAddress, RegisterType registerType, const QString ®isterAddress);
|
||||||
void registerNewAccountFailed(const QString &error);
|
void registerNewAccountFailed(const QString &error);
|
||||||
void tokenConversionSucceed();
|
void tokenConversionSucceed(QString convertedToken);
|
||||||
void errorInField(const QString &field, const QString &error);
|
void errorInField(const QString &field, const QString &error);
|
||||||
void linkingNewAccountWithCodeSucceed();
|
void linkingNewAccountWithCodeSucceed();
|
||||||
void linkingNewAccountWithCodeFailed(const QString &error);
|
void linkingNewAccountWithCodeFailed(const QString &error);
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ Text {
|
||||||
}
|
}
|
||||||
Timer {
|
Timer {
|
||||||
id: autoHideErrorMessage
|
id: autoHideErrorMessage
|
||||||
interval: 2500
|
interval: 5000
|
||||||
onTriggered: mainItem.text = ""
|
onTriggered: mainItem.text = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,10 @@ LoginLayout {
|
||||||
else if (field == "password") pwdItem.errorMessage = errorMessage
|
else if (field == "password") pwdItem.errorMessage = errorMessage
|
||||||
else if (field == "phone") phoneNumberInput.errorMessage = errorMessage
|
else if (field == "phone") phoneNumberInput.errorMessage = errorMessage
|
||||||
else if (field == "email") emailItem.errorMessage = errorMessage
|
else if (field == "email") emailItem.errorMessage = errorMessage
|
||||||
|
else otherErrorText.text = errorMessage
|
||||||
|
}
|
||||||
|
function onRegisterNewAccountFailed(errorMessage) {
|
||||||
|
otherErrorText.text = errorMessage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -142,36 +146,47 @@ LoginLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RowLayout {
|
ColumnLayout {
|
||||||
spacing: 16 * DefaultStyle.dp
|
spacing: 0
|
||||||
ColumnLayout {
|
Layout.preferredHeight: rowlayout.height
|
||||||
spacing: 5 * DefaultStyle.dp
|
clip: false
|
||||||
FormItemLayout {
|
RowLayout {
|
||||||
id: passwordItem
|
id: rowlayout
|
||||||
label: qsTr("Mot de passe")
|
spacing: 16 * DefaultStyle.dp
|
||||||
mandatory: true
|
ColumnLayout {
|
||||||
enableErrorText: true
|
spacing: 5 * DefaultStyle.dp
|
||||||
contentItem: TextField {
|
FormItemLayout {
|
||||||
id: pwdInput
|
id: passwordItem
|
||||||
hidden: true
|
label: qsTr("Mot de passe")
|
||||||
Layout.preferredWidth: 346 * DefaultStyle.dp
|
mandatory: true
|
||||||
backgroundBorderColor: passwordItem.errorMessage.length > 0 ? DefaultStyle.danger_500main : DefaultStyle.grey_200
|
enableErrorText: true
|
||||||
|
contentItem: TextField {
|
||||||
|
id: pwdInput
|
||||||
|
hidden: true
|
||||||
|
Layout.preferredWidth: 346 * DefaultStyle.dp
|
||||||
|
backgroundBorderColor: passwordItem.errorMessage.length > 0 ? DefaultStyle.danger_500main : DefaultStyle.grey_200
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ColumnLayout {
|
||||||
|
spacing: 5 * DefaultStyle.dp
|
||||||
|
FormItemLayout {
|
||||||
|
label: qsTr("Confirmation mot de passe")
|
||||||
|
mandatory: true
|
||||||
|
enableErrorText: true
|
||||||
|
contentItem: TextField {
|
||||||
|
id: confirmPwdInput
|
||||||
|
hidden: true
|
||||||
|
Layout.preferredWidth: 346 * DefaultStyle.dp
|
||||||
|
backgroundBorderColor: passwordItem.errorMessage.length > 0 ? DefaultStyle.danger_500main : DefaultStyle.grey_200
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ColumnLayout {
|
ErrorText {
|
||||||
spacing: 5 * DefaultStyle.dp
|
id: otherErrorText
|
||||||
FormItemLayout {
|
Layout.fillWidth: true
|
||||||
label: qsTr("Confirmation mot de passe")
|
Layout.topMargin: 5 * DefaultStyle.dp
|
||||||
mandatory: true
|
|
||||||
enableErrorText: true
|
|
||||||
contentItem: TextField {
|
|
||||||
id: confirmPwdInput
|
|
||||||
hidden: true
|
|
||||||
Layout.preferredWidth: 346 * DefaultStyle.dp
|
|
||||||
backgroundBorderColor: passwordItem.errorMessage.length > 0 ? DefaultStyle.danger_500main : DefaultStyle.grey_200
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -194,80 +209,81 @@ LoginLayout {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
RowLayout {
|
|
||||||
spacing: 10 * DefaultStyle.dp
|
|
||||||
CheckBox {
|
|
||||||
id: termsCheckBox
|
|
||||||
}
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
spacing: 0
|
spacing: 10 * DefaultStyle.dp
|
||||||
Layout.fillWidth: true
|
CheckBox {
|
||||||
Text {
|
id: termsCheckBox
|
||||||
text: qsTr("J'accepte les ")
|
|
||||||
font {
|
|
||||||
pixelSize: 14 * DefaultStyle.dp
|
|
||||||
weight: 400 * DefaultStyle.dp
|
|
||||||
}
|
|
||||||
MouseArea {
|
|
||||||
anchors.fill: parent
|
|
||||||
onClicked: termsCheckBox.toggle()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Text {
|
RowLayout {
|
||||||
activeFocusOnTab: true
|
spacing: 0
|
||||||
font {
|
Layout.fillWidth: true
|
||||||
underline: true
|
Text {
|
||||||
pixelSize: 14 * DefaultStyle.dp
|
text: qsTr("J'accepte les ")
|
||||||
weight: 400 * DefaultStyle.dp
|
font {
|
||||||
bold: activeFocus
|
pixelSize: 14 * DefaultStyle.dp
|
||||||
}
|
weight: 400 * DefaultStyle.dp
|
||||||
text: qsTr("conditions d’utilisation")
|
}
|
||||||
Keys.onPressed: (event)=> {
|
MouseArea {
|
||||||
if (event.key == Qt.Key_Space || event.key == Qt.Key_Enter || event.key == Qt.Key_Return) {
|
anchors.fill: parent
|
||||||
cguMouseArea.clicked(undefined)
|
onClicked: termsCheckBox.toggle()
|
||||||
event.accepted = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MouseArea {
|
Text {
|
||||||
id: cguMouseArea
|
activeFocusOnTab: true
|
||||||
anchors.fill: parent
|
font {
|
||||||
hoverEnabled: true
|
underline: true
|
||||||
cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor
|
pixelSize: 14 * DefaultStyle.dp
|
||||||
onClicked: Qt.openUrlExternally(ConstantsCpp.CguUrl)
|
weight: 400 * DefaultStyle.dp
|
||||||
}
|
bold: activeFocus
|
||||||
}
|
}
|
||||||
Text {
|
text: qsTr("conditions d’utilisation")
|
||||||
text: qsTr(" et la ")
|
Keys.onPressed: (event)=> {
|
||||||
font {
|
if (event.key == Qt.Key_Space || event.key == Qt.Key_Enter || event.key == Qt.Key_Return) {
|
||||||
pixelSize: 14 * DefaultStyle.dp
|
cguMouseArea.clicked(undefined)
|
||||||
weight: 400 * DefaultStyle.dp
|
event.accepted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Text {
|
MouseArea {
|
||||||
activeFocusOnTab: true
|
id: cguMouseArea
|
||||||
font {
|
anchors.fill: parent
|
||||||
underline: true
|
hoverEnabled: true
|
||||||
pixelSize: 14 * DefaultStyle.dp
|
cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor
|
||||||
weight: 400 * DefaultStyle.dp
|
onClicked: Qt.openUrlExternally(ConstantsCpp.CguUrl)
|
||||||
bold: activeFocus
|
|
||||||
}
|
|
||||||
text: qsTr("politique de confidentialité.")
|
|
||||||
Keys.onPressed: (event)=> {
|
|
||||||
if (event.key == Qt.Key_Space || event.key == Qt.Key_Enter || event.key == Qt.Key_Return) {
|
|
||||||
privateMouseArea.clicked(undefined)
|
|
||||||
event.accepted = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MouseArea {
|
Text {
|
||||||
id: privateMouseArea
|
text: qsTr(" et la ")
|
||||||
anchors.fill: parent
|
font {
|
||||||
hoverEnabled: true
|
pixelSize: 14 * DefaultStyle.dp
|
||||||
cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor
|
weight: 400 * DefaultStyle.dp
|
||||||
onClicked: Qt.openUrlExternally(ConstantsCpp.PrivatePolicyUrl)
|
}
|
||||||
|
}
|
||||||
|
Text {
|
||||||
|
activeFocusOnTab: true
|
||||||
|
font {
|
||||||
|
underline: true
|
||||||
|
pixelSize: 14 * DefaultStyle.dp
|
||||||
|
weight: 400 * DefaultStyle.dp
|
||||||
|
bold: activeFocus
|
||||||
|
}
|
||||||
|
text: qsTr("politique de confidentialité.")
|
||||||
|
Keys.onPressed: (event)=> {
|
||||||
|
if (event.key == Qt.Key_Space || event.key == Qt.Key_Enter || event.key == Qt.Key_Return) {
|
||||||
|
privateMouseArea.clicked(undefined)
|
||||||
|
event.accepted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MouseArea {
|
||||||
|
id: privateMouseArea
|
||||||
|
anchors.fill: parent
|
||||||
|
hoverEnabled: true
|
||||||
|
cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor
|
||||||
|
onClicked: Qt.openUrlExternally(ConstantsCpp.PrivatePolicyUrl)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// }
|
// }
|
||||||
Button {
|
Button {
|
||||||
enabled: termsCheckBox.checked
|
enabled: termsCheckBox.checked
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue