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
91edda35
Commit
91edda35
authored
Oct 10, 2018
by
Martin Straka
Committed by
Karel Slaný
Nov 15, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to change user name for account
parent
7233124f
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
229 additions
and
9 deletions
+229
-9
qml/pages/PageSettingsAccount.qml
qml/pages/PageSettingsAccount.qml
+4
-2
src/accounts.cpp
src/accounts.cpp
+125
-4
src/accounts.h
src/accounts.h
+18
-3
src/sqlite/account_db.cpp
src/sqlite/account_db.cpp
+46
-0
src/sqlite/account_db.h
src/sqlite/account_db.h
+10
-0
src/sqlite/file_db.cpp
src/sqlite/file_db.cpp
+5
-0
src/sqlite/file_db.h
src/sqlite/file_db.h
+8
-0
src/sqlite/message_db.cpp
src/sqlite/message_db.cpp
+5
-0
src/sqlite/message_db.h
src/sqlite/message_db.h
+8
-0
No files found.
qml/pages/PageSettingsAccount.qml
View file @
91edda35
...
...
@@ -39,6 +39,7 @@ Item {
property
bool
isNewAccount
:
(
userName
==
""
)
property
string
sLoginMethod
:
"
pwd
"
property
string
originUserName
Component.onCompleted
:
{
if
(
!
isNewAccount
)
{
...
...
@@ -101,7 +102,8 @@ Item {
userNameTextField
.
text
.
toString
(),
passwordTextField
.
text
.
toString
(),
testAccount
.
checked
,
rememberPassword
.
checked
,
useLS
.
checked
,
certPathLabelId
.
text
.
toString
()))
{
useLS
.
checked
,
certPathLabelId
.
text
.
toString
(),
originUserName
))
{
settings
.
saveAllSettings
(
accountModel
)
}
pageView
.
pop
(
StackView
.
Immediate
)
...
...
@@ -318,7 +320,7 @@ Item {
useLS
.
checked
=
storeToDisk
certPathLabelId
.
text
=
certPath
loginMethodComboBox
.
selectCurrentKey
(
loginMethod
)
userNameTextField
.
enabled
=
fals
e
originUserName
=
userNam
e
testAccount
.
enabled
=
false
headerBar
.
title
=
qsTr
(
"
Account settings
"
)
}
...
...
src/accounts.cpp
View file @
91edda35
...
...
@@ -32,6 +32,7 @@
#include "src/net/isds_session.h"
#include "src/settings.h"
#include "src/sqlite/account_db.h"
#include "src/sqlite/file_db_container.h"
#include "src/sqlite/message_db_container.h"
Accounts
::
Accounts
(
QObject
*
parent
)
...
...
@@ -190,9 +191,9 @@ bool Accounts::createAccount(const QVariant &acntModelVariant,
}
bool
Accounts
::
updateAccount
(
const
QVariant
&
acntModelVariant
,
const
QString
&
loginMetod
,
const
QString
&
acntName
,
const
QString
&
u
serName
,
const
QString
&
loginMetod
,
const
QString
&
acntName
,
const
QString
&
newU
serName
,
const
QString
&
pwd
,
bool
isTestAccount
,
bool
rememberPwd
,
bool
storeToDisk
,
const
QString
&
certPath
)
const
QString
&
certPath
,
const
QString
&
originUserName
)
{
debugFuncCall
();
...
...
@@ -220,8 +221,19 @@ bool Accounts::updateAccount(const QVariant &acntModelVariant,
return
false
;
}
if
(
!
GlobInstcs
::
acntMapPtr
->
contains
(
userName
))
{
return
false
;
QString
userName
=
newUserName
.
trimmed
();
if
(
userName
!=
originUserName
)
{
bool
success
=
changeAccountUserName
(
originUserName
,
userName
.
trimmed
(),
acntName
);
if
(
!
success
)
{
return
false
;
}
}
else
{
if
(
!
GlobInstcs
::
acntMapPtr
->
contains
(
userName
))
{
return
false
;
}
}
AcntData
&
acntData
((
*
GlobInstcs
::
acntMapPtr
)[
userName
]);
...
...
@@ -406,3 +418,112 @@ void Accounts::loadModelCounters(AccountListModel *accountModel)
msgDb
->
getMessageCountFromDb
(
MessageDb
::
TYPE_SENT
));
}
}
bool
Accounts
::
changeAccountUserName
(
const
QString
&
originUserName
,
const
QString
&
newUserName
,
const
QString
&
acntName
)
{
int
msgResponse
=
Dialogues
::
message
(
Dialogues
::
QUESTION
,
tr
(
"Change user name: %1"
).
arg
(
originUserName
),
tr
(
"Do you want to change user name from '%1' to '%2' of account '%3'?"
).
arg
(
originUserName
).
arg
(
newUserName
).
arg
(
acntName
),
tr
(
"Note: It will also change all related local database names and account information."
),
Dialogues
::
NO
|
Dialogues
::
YES
,
Dialogues
::
NO
);
if
(
msgResponse
==
Dialogues
::
NO
)
{
return
false
;
}
/* Check if new user name has correct length */
if
(
newUserName
.
length
()
!=
6
)
{
logErrorNL
(
"Username '%s' has wrong length!"
,
newUserName
.
toUtf8
().
constData
());
return
false
;
}
/* Check if new user name is not exists in the database */
if
(
GlobInstcs
::
acntMapPtr
->
contains
(
newUserName
))
{
logErrorNL
(
"Username '%s' already exists!"
,
newUserName
.
toUtf8
().
constData
());
return
false
;
}
/* Change user name in the account database */
if
(
!
GlobInstcs
::
accountDbPtr
->
changeUserName
(
originUserName
,
newUserName
))
{
logErrorNL
(
"%s"
,
"Could not change user name in the account database."
);
return
false
;
}
/* Update user name in the account map and settings */
AcntData
&
acntData
((
*
GlobInstcs
::
acntMapPtr
)[
originUserName
]);
acntData
.
setUserName
(
newUserName
);
{
/* Change message database name */
MessageDb
*
msgDb
=
GlobInstcs
::
messageDbsPtr
->
accessMessageDb
(
GlobInstcs
::
setPtr
->
dbsLocation
,
originUserName
,
(
*
GlobInstcs
::
acntMapPtr
)[
originUserName
].
storeToDisk
());
if
(
msgDb
==
Q_NULLPTR
)
{
logErrorNL
(
"Cannot access message database for %s."
,
originUserName
.
toUtf8
().
constData
());
goto
backAccount
;
}
QString
currentDbFileName
=
msgDb
->
fileName
();
currentDbFileName
.
replace
(
originUserName
,
newUserName
);
if
(
!
msgDb
->
moveDb
(
currentDbFileName
))
{
goto
backAccount
;
}
}
{
/* Change file database name */
FileDb
*
fDb
=
GlobInstcs
::
fileDbsPtr
->
accessFileDb
(
GlobInstcs
::
setPtr
->
dbsLocation
,
originUserName
,
(
*
GlobInstcs
::
acntMapPtr
)[
originUserName
].
storeToDisk
());
if
(
fDb
==
Q_NULLPTR
)
{
logErrorNL
(
"Cannot access file database for %s."
,
originUserName
.
toUtf8
().
constData
());
goto
backMessage
;
}
QString
currentDbFileName
=
fDb
->
fileName
();
currentDbFileName
.
replace
(
originUserName
,
newUserName
);
if
(
!
fDb
->
moveDb
(
currentDbFileName
))
{
goto
backMessage
;
}
}
logInfoNL
(
"Username has been changed on '%s'."
,
newUserName
.
toUtf8
().
constData
());
return
true
;
backMessage:
{
/* Change back message database name */
MessageDb
*
msgDb
=
GlobInstcs
::
messageDbsPtr
->
accessMessageDb
(
GlobInstcs
::
setPtr
->
dbsLocation
,
newUserName
,
(
*
GlobInstcs
::
acntMapPtr
)[
newUserName
].
storeToDisk
());
if
(
msgDb
==
Q_NULLPTR
)
{
logErrorNL
(
"Cannot access message database for %s."
,
newUserName
.
toUtf8
().
constData
());
}
QString
currentDbFileName
=
msgDb
->
fileName
();
currentDbFileName
.
replace
(
newUserName
,
originUserName
);
msgDb
->
moveDb
(
currentDbFileName
);
}
backAccount:
/* Change back user name in the account database */
if
(
!
GlobInstcs
::
accountDbPtr
->
changeUserName
(
newUserName
,
originUserName
))
{
logErrorNL
(
"%s"
,
"Could not change user name in the account database."
);
}
Dialogues
::
errorMessage
(
Dialogues
::
CRITICAL
,
tr
(
"User name problem: %1"
).
arg
(
originUserName
),
tr
(
"The new user name '%1' for account '%2' has not been set!"
).
arg
(
newUserName
).
arg
(
acntName
),
tr
(
"Account will use the origin settings."
));
return
false
;
}
src/accounts.h
View file @
91edda35
...
...
@@ -116,19 +116,21 @@ public:
* @param[in,out] acntModelVariant QVariant holding account model.
* @param[in] loginMetod User name identifying account.
* @param[in] acntName Account name.
* @param[in]
u
serName User name identifying account.
* @param[in]
newU
serName User name identifying account.
* @param[in] pwd Password.
* @param[in] isTestAccount True if account is isds test enveiroment.
* @param[in] rememberPwd True if remember password.
* @param[in] storeToDisk True if database store to local storage.
* @param[in] certPath Certificate path (can be null).
* @param[in] originUserName Origin user name of account.
* @return True if success.
*/
Q_INVOKABLE
bool
updateAccount
(
const
QVariant
&
acntModelVariant
,
const
QString
&
loginMetod
,
const
QString
&
acntName
,
const
QString
&
userName
,
const
QString
&
pwd
,
bool
isTestAccount
,
bool
rememberPwd
,
bool
storeToDisk
,
const
QString
&
certPath
);
const
QString
&
newUserName
,
const
QString
&
pwd
,
bool
isTestAccount
,
bool
rememberPwd
,
bool
storeToDisk
,
const
QString
&
certPath
,
const
QString
&
originUserName
);
/*!
* @brief Remove account.
...
...
@@ -172,4 +174,17 @@ signals:
* @param[in] acntName Account name.
*/
void
removeIsdsCtx
(
QString
userName
);
private:
/*!
* @brief Change account user name.
*
* @param[in] originUserName Origin user name of account.
* @param[in] newUserName New user name of account.
* @param[in] acntName Account name.
* @return True if success.
*/
bool
changeAccountUserName
(
const
QString
&
originUserName
,
const
QString
&
newUserName
,
const
QString
&
acntName
);
};
src/sqlite/account_db.cpp
View file @
91edda35
...
...
@@ -608,6 +608,52 @@ fail:
return
Isds
::
DbOwnerInfo
();
}
bool
AccountDb
::
changeUserName
(
const
QString
&
oldUserName
,
const
QString
&
newUserName
)
{
QSqlQuery
query
(
m_db
);
QString
queryStr
;
if
(
!
m_db
.
isOpen
())
{
logErrorNL
(
"%s"
,
"Account database seems not to be open."
);
goto
fail
;
}
queryStr
=
"UPDATE account_info "
"SET key = :newUserName WHERE key = :oldUserName"
;
if
(
!
query
.
prepare
(
queryStr
))
{
logErrorNL
(
"Cannot prepare SQL query: %s"
,
query
.
lastError
().
text
().
toUtf8
().
constData
());
goto
fail
;
}
query
.
bindValue
(
":oldUserName"
,
oldUserName
);
query
.
bindValue
(
":newUserName"
,
newUserName
);
if
(
!
query
.
exec
())
{
logErrorNL
(
"Cannot execute SQL query: %s"
,
query
.
lastError
().
text
().
toUtf8
().
constData
());
goto
fail
;
}
queryStr
=
"UPDATE user_info "
"SET key = :newUserName WHERE key = :oldUserName"
;
if
(
!
query
.
prepare
(
queryStr
))
{
logErrorNL
(
"Cannot prepare SQL query: %s"
,
query
.
lastError
().
text
().
toUtf8
().
constData
());
goto
fail
;
}
query
.
bindValue
(
":oldUserName"
,
oldUserName
);
query
.
bindValue
(
":newUserName"
,
newUserName
);
if
(
query
.
exec
())
{
return
true
;
}
else
{
logErrorNL
(
"Cannot execute SQL query: %s"
,
query
.
lastError
().
text
().
toUtf8
().
constData
());
goto
fail
;
}
fail:
return
false
;
}
QList
<
class
SQLiteTbl
*>
AccountDb
::
listOfTables
(
void
)
const
{
QList
<
class
SQLiteTbl
*>
tables
;
...
...
src/sqlite/account_db.h
View file @
91edda35
...
...
@@ -117,6 +117,16 @@ public:
*/
const
Isds
::
DbOwnerInfo
getOwnerInfo
(
const
QString
&
key
)
const
;
/*!
* @brief Change user name in account db.
*
* @param[in] oldUserName Current account user name.
* @param[in] newUserName New account user name.
* @return True on success.
*/
bool
changeUserName
(
const
QString
&
oldUserName
,
const
QString
&
newUserName
);
protected:
/*!
* @brief Returns list of tables.
...
...
src/sqlite/file_db.cpp
View file @
91edda35
...
...
@@ -96,6 +96,11 @@ bool FileDb::reopenDb(const QString &newFileName)
return
SQLiteDb
::
reopenDb
(
newFileName
,
SQLiteDb
::
CREATE_MISSING
);
}
bool
FileDb
::
moveDb
(
const
QString
&
newFileName
)
{
return
SQLiteDb
::
moveDb
(
newFileName
,
SQLiteDb
::
CREATE_MISSING
);
}
bool
FileDb
::
deleteFilesFromDb
(
qint64
dmId
)
{
QSqlQuery
query
(
m_db
);
...
...
src/sqlite/file_db.h
View file @
91edda35
...
...
@@ -67,6 +67,14 @@ public:
*/
bool
reopenDb
(
const
QString
&
newFileName
);
/*!
* @brief Move db.
*
* @param[in] newFileName New file path.
* @return True on success.
*/
bool
moveDb
(
const
QString
&
newFileName
);
/*!
* @brief Delete all files related to message with given id.
*
...
...
src/sqlite/message_db.cpp
View file @
91edda35
...
...
@@ -68,6 +68,11 @@ bool MessageDb::reopenDb(const QString &newFileName)
return
SQLiteDb
::
reopenDb
(
newFileName
,
SQLiteDb
::
CREATE_MISSING
);
}
bool
MessageDb
::
moveDb
(
const
QString
&
newFileName
)
{
return
SQLiteDb
::
moveDb
(
newFileName
,
SQLiteDb
::
CREATE_MISSING
);
}
bool
MessageDb
::
deleteMessageFromDb
(
qint64
msgId
)
{
QSqlQuery
query
(
m_db
);
...
...
src/sqlite/message_db.h
View file @
91edda35
...
...
@@ -70,6 +70,14 @@ public:
*/
bool
reopenDb
(
const
QString
&
newFileName
);
/*!
* @brief Move db.
*
* @param[in] newFileName New file path.
* @return True on success.
*/
bool
moveDb
(
const
QString
&
newFileName
);
/*!
* @brief Delete message from db.
*
...
...
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