Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
mobile Datovka
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
14
Issues
14
List
Boards
Labels
Service Desk
Milestones
Merge Requests
4
Merge Requests
4
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Datovka projects
mobile Datovka
Commits
80dcdb66
Commit
80dcdb66
authored
Oct 24, 2018
by
Martin Straka
Committed by
Karel Slaný
Nov 15, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code refactoring
parent
ed2608bc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
19 deletions
+46
-19
qml/pages/PageSettingsAccount.qml
qml/pages/PageSettingsAccount.qml
+5
-0
src/accounts.cpp
src/accounts.cpp
+29
-16
src/accounts.h
src/accounts.h
+12
-3
No files found.
qml/pages/PageSettingsAccount.qml
View file @
80dcdb66
...
...
@@ -98,12 +98,14 @@ Item {
}
else
{
// Change account user name.
if
(
userNameTextField
.
text
.
toString
()
!==
oldUserName
)
{
// Create temporary account with a new user name.
if
(
accounts
.
prepareChangeUserName
(
accountModel
,
sLoginMethod
,
accountNameTextField
.
text
.
toString
(),
userNameTextField
.
text
.
toString
(),
passwordTextField
.
text
.
toString
(),
testAccount
.
checked
,
rememberPassword
.
checked
,
useLS
.
checked
,
certPathLabelId
.
text
.
toString
(),
oldUserName
))
{
// Login to idsd with the new user name.
isds
.
doIsdsAction
(
"
changeUserName
"
,
userNameTextField
.
text
.
toString
())
}
}
else
{
...
...
@@ -137,7 +139,10 @@ Item {
isds
.
getAccountInfo
(
userName
)
}
onRunChangeUserNameSig
:
{
// Login to isds with new user name has been succeeded.
// Get databox ID of new user name.
var
dbId
=
isds
.
getAccountDbId
(
userName
)
// Change username and rename databases.
if
(
accounts
.
changeAccountUserName
(
accountModel
,
accountNameTextField
.
text
.
toString
(),
userNameTextField
.
text
.
toString
(),
...
...
src/accounts.cpp
View file @
80dcdb66
...
...
@@ -170,7 +170,7 @@ bool Accounts::createAccount(const QVariant &acntModelVariant,
goto
fail
;
}
if
(
!
check
CorrectLengthUserName
(
newUserName
))
{
if
(
!
has
CorrectLengthUserName
(
newUserName
))
{
errTxt
=
tr
(
"User name '%1' has wrong length."
).
arg
(
newUserName
);
goto
fail
;
}
...
...
@@ -423,6 +423,7 @@ bool Accounts::prepareChangeUserName(const QVariant &acntModelVariant,
const
QString
&
pwd
,
bool
isTestAccount
,
bool
rememberPwd
,
bool
storeToDisk
,
const
QString
&
certPath
,
const
QString
&
oldUserName
)
{
debugFuncCall
();
/* Show confirm dialogue about use name changing */
int
msgResponse
=
Dialogues
::
message
(
Dialogues
::
QUESTION
,
...
...
@@ -443,6 +444,8 @@ bool Accounts::changeAccountUserName(const QVariant &acntModelVariant,
const
QString
&
acntName
,
const
QString
&
newUserName
,
bool
storeToDisk
,
const
QString
&
oldUserName
,
const
QString
&
newDbId
)
{
debugFuncCall
();
QString
errTxt
;
AccountListModel
*
accountModel
=
Q_NULLPTR
;
...
...
@@ -462,7 +465,7 @@ bool Accounts::changeAccountUserName(const QVariant &acntModelVariant,
}
/* Check if new user name corresponds with databox id */
if
(
!
isRelevantUserName
(
oldUserName
,
newDbId
))
{
if
(
!
isRelevantUserName
ToDbId
(
oldUserName
,
newDbId
))
{
errTxt
=
tr
(
"New user name '%1' not corresponds with databox ID."
).
arg
(
newUserName
);
goto
fail
;
}
...
...
@@ -483,12 +486,8 @@ bool Accounts::changeAccountUserName(const QVariant &acntModelVariant,
goto
rollbackFilesChanges
;
}
/* Remove old account */
accountModel
->
deleteAccount
(
oldUserName
);
/* Delete isds session context of old account */
emit
removeIsdsCtx
(
oldUserName
);
/* Load message counters of new account */
loadModelCounters
(
accountModel
);
/* Last: Delete original/old account from model and settings */
deleteAccountFromModel
(
accountModel
,
oldUserName
);
logInfoNL
(
"Username has been changed on '%s'."
,
newUserName
.
toUtf8
().
constData
());
...
...
@@ -510,24 +509,21 @@ rollbackFilesChanges:
rollbackAccountChanges:
/* Change back user name in the account database */
/* Change back
origial
user name in the account database */
if
(
!
GlobInstcs
::
accountDbPtr
->
changeUserName
(
newUserName
,
oldUserName
))
{
logErrorNL
(
"%s"
,
"Cannot change back user name in the account database."
);
}
fail:
/* Show error dialog with message what happened */
Dialogues
::
errorMessage
(
Dialogues
::
CRITICAL
,
tr
(
"User name problem: %1"
).
arg
(
oldUserName
),
tr
(
"The new user name '%1' for account '%2' has not been set!"
).
arg
(
newUserName
).
arg
(
acntName
),
errTxt
+
" "
+
tr
(
"Account will use the original settings."
));
exit:
/* Remove new account */
accountModel
->
deleteAccount
(
newUserName
);
/* Delete isds session context of new account */
emit
removeIsdsCtx
(
newUserName
);
deleteAccountFromModel
(
accountModel
,
newUserName
);
return
false
;
}
...
...
@@ -535,6 +531,8 @@ exit:
bool
Accounts
::
changeFileDbName
(
const
QString
&
oldUserName
,
const
QString
&
newUserName
,
bool
storeToDisk
,
QString
&
errTxt
)
{
debugFuncCall
();
FileDb
*
fDb
=
GlobInstcs
::
fileDbsPtr
->
accessFileDb
(
GlobInstcs
::
setPtr
->
dbsLocation
,
oldUserName
,
storeToDisk
);
if
(
fDb
==
Q_NULLPTR
)
{
...
...
@@ -542,6 +540,7 @@ bool Accounts::changeFileDbName(const QString &oldUserName,
return
false
;
}
/* Rename file database */
QString
currentDbFileName
=
fDb
->
fileName
();
currentDbFileName
.
replace
(
oldUserName
,
newUserName
);
if
(
!
fDb
->
moveDb
(
currentDbFileName
))
{
...
...
@@ -555,6 +554,8 @@ bool Accounts::changeFileDbName(const QString &oldUserName,
bool
Accounts
::
changeMessageDbName
(
const
QString
&
oldUserName
,
const
QString
&
newUserName
,
bool
storeToDisk
,
QString
&
errTxt
)
{
debugFuncCall
();
MessageDb
*
msgDb
=
GlobInstcs
::
messageDbsPtr
->
accessMessageDb
(
GlobInstcs
::
setPtr
->
dbsLocation
,
oldUserName
,
storeToDisk
);
if
(
msgDb
==
Q_NULLPTR
)
{
...
...
@@ -562,6 +563,7 @@ bool Accounts::changeMessageDbName(const QString &oldUserName,
return
false
;
}
/* Rename message database */
QString
currentDbFileName
=
msgDb
->
fileName
();
currentDbFileName
.
replace
(
oldUserName
,
newUserName
);
if
(
!
msgDb
->
moveDb
(
currentDbFileName
))
{
...
...
@@ -572,14 +574,25 @@ bool Accounts::changeMessageDbName(const QString &oldUserName,
return
true
;
}
bool
Accounts
::
check
CorrectLengthUserName
(
const
QString
&
userName
)
bool
Accounts
::
has
CorrectLengthUserName
(
const
QString
&
userName
)
{
/* Check if new user name has correct length */
return
(
userName
.
length
()
==
6
);
}
bool
Accounts
::
isRelevantUserName
(
const
QString
&
userName
,
const
QString
&
dbId
)
bool
Accounts
::
isRelevantUserName
ToDbId
(
const
QString
&
userName
,
const
QString
&
dbId
)
{
/* Check if new user corresponds with databox id */
return
(
dbId
==
GlobInstcs
::
accountDbPtr
->
dbId
(
userName
));
}
void
Accounts
::
deleteAccountFromModel
(
AccountListModel
*
accountModel
,
const
QString
&
userName
)
{
/* Remove old account from model */
accountModel
->
deleteAccount
(
userName
);
/* Delete isds session context of old account */
emit
removeIsdsCtx
(
userName
);
/* Load message counters of all accounts */
loadModelCounters
(
accountModel
);
}
src/accounts.h
View file @
80dcdb66
...
...
@@ -238,13 +238,13 @@ private:
const
QString
&
newUserName
,
bool
storeToDisk
,
QString
&
errTxt
);
/*!
* @brief Check
correct length of user name
.
* @brief Check
if user name has correct length
.
*
* @param[in] userName New user name identifying account.
* @return True if length is correct.
*/
static
bool
check
CorrectLengthUserName
(
const
QString
&
userName
);
bool
has
CorrectLengthUserName
(
const
QString
&
userName
);
/*!
* @brief Check if new user name is relevant to databox id.
...
...
@@ -253,6 +253,15 @@ private:
* @param[in] dbId Databox ID obtained from isds.
* @return True if user name is relevant to databox id.
*/
bool
isRelevantUserName
(
const
QString
&
userName
,
bool
isRelevantUserName
ToDbId
(
const
QString
&
userName
,
const
QString
&
dbId
);
/*!
* @brief Delete account from model.
*
* @param[in,out] accountModel Model whose counters should be updated.
* @param[in] userName User name identifying account.
*/
void
deleteAccountFromModel
(
AccountListModel
*
accountModel
,
const
QString
&
userName
);
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment