Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
d7b6f761
Commit
d7b6f761
authored
May 23, 2015
by
Fabio Bas
Browse files
missing file from previous commit
parent
5ace0dd8
Changes
1
Hide whitespace changes
Inline
Side-by-side
servatrice/src/servatrice_database_interface.cpp
View file @
d7b6f761
...
@@ -111,11 +111,13 @@ bool Servatrice_DatabaseInterface::getRequireRegistration()
...
@@ -111,11 +111,13 @@ bool Servatrice_DatabaseInterface::getRequireRegistration()
return
settingsCache
->
value
(
"authentication/regonly"
,
0
).
toBool
();
return
settingsCache
->
value
(
"authentication/regonly"
,
0
).
toBool
();
}
}
bool
Servatrice_DatabaseInterface
::
registerUser
(
const
QString
&
userName
,
const
QString
&
realName
,
ServerInfo_User_Gender
const
&
gender
,
const
QString
&
password
Sha512
,
const
QString
&
emailAddress
,
const
QString
&
country
,
bool
active
)
bool
Servatrice_DatabaseInterface
::
registerUser
(
const
QString
&
userName
,
const
QString
&
realName
,
ServerInfo_User_Gender
const
&
gender
,
const
QString
&
password
,
const
QString
&
emailAddress
,
const
QString
&
country
,
bool
active
)
{
{
if
(
!
checkSql
())
if
(
!
checkSql
())
return
false
;
return
false
;
QString
passwordSha512
=
PasswordHasher
::
computeHash
(
password
,
PasswordHasher
::
generateRandomSalt
());
QSqlQuery
*
query
=
prepareQuery
(
"insert into {prefix}_users "
QSqlQuery
*
query
=
prepareQuery
(
"insert into {prefix}_users "
"(name, realname, gender, password_sha512, email, country, registrationDate, active) "
"(name, realname, gender, password_sha512, email, country, registrationDate, active) "
"values "
"values "
...
@@ -171,6 +173,7 @@ AuthenticationResult Servatrice_DatabaseInterface::checkUserPassword(Server_Prot
...
@@ -171,6 +173,7 @@ AuthenticationResult Servatrice_DatabaseInterface::checkUserPassword(Server_Prot
if
(
checkUserIsBanned
(
handler
->
getAddress
(),
user
,
reasonStr
,
banSecondsLeft
))
if
(
checkUserIsBanned
(
handler
->
getAddress
(),
user
,
reasonStr
,
banSecondsLeft
))
return
UserIsBanned
;
return
UserIsBanned
;
QSqlQuery
*
passwordQuery
=
prepareQuery
(
"select password_sha512, active from {prefix}_users where name = :name"
);
passwordQuery
->
bindValue
(
":name"
,
user
);
passwordQuery
->
bindValue
(
":name"
,
user
);
if
(
!
execSqlQuery
(
passwordQuery
))
{
if
(
!
execSqlQuery
(
passwordQuery
))
{
qDebug
(
"Login denied: SQL error"
);
qDebug
(
"Login denied: SQL error"
);
...
@@ -179,6 +182,11 @@ AuthenticationResult Servatrice_DatabaseInterface::checkUserPassword(Server_Prot
...
@@ -179,6 +182,11 @@ AuthenticationResult Servatrice_DatabaseInterface::checkUserPassword(Server_Prot
if
(
passwordQuery
->
next
())
{
if
(
passwordQuery
->
next
())
{
const
QString
correctPassword
=
passwordQuery
->
value
(
0
).
toString
();
const
QString
correctPassword
=
passwordQuery
->
value
(
0
).
toString
();
const
bool
userIsActive
=
passwordQuery
->
value
(
1
).
toBool
();
if
(
!
userIsActive
)
{
qDebug
(
"Login denied: user not active"
);
return
UserIsInactive
;
}
if
(
correctPassword
==
PasswordHasher
::
computeHash
(
password
,
correctPassword
.
left
(
16
)))
{
if
(
correctPassword
==
PasswordHasher
::
computeHash
(
password
,
correctPassword
.
left
(
16
)))
{
qDebug
(
"Login accepted: password right"
);
qDebug
(
"Login accepted: password right"
);
return
PasswordRight
;
return
PasswordRight
;
...
@@ -268,6 +276,7 @@ bool Servatrice_DatabaseInterface::checkUserIsIpBanned(const QString &ipAddress,
...
@@ -268,6 +276,7 @@ bool Servatrice_DatabaseInterface::checkUserIsIpBanned(const QString &ipAddress,
return
false
;
return
false
;
}
}
bool
Servatrice_DatabaseInterface
::
activeUserExists
(
const
QString
&
user
)
{
{
if
(
server
->
getAuthenticationMethod
()
==
Servatrice
::
AuthenticationSql
)
{
if
(
server
->
getAuthenticationMethod
()
==
Servatrice
::
AuthenticationSql
)
{
checkSql
();
checkSql
();
...
@@ -281,6 +290,20 @@ bool Servatrice_DatabaseInterface::checkUserIsIpBanned(const QString &ipAddress,
...
@@ -281,6 +290,20 @@ bool Servatrice_DatabaseInterface::checkUserIsIpBanned(const QString &ipAddress,
return
false
;
return
false
;
}
}
bool
Servatrice_DatabaseInterface
::
userExists
(
const
QString
&
user
)
{
if
(
server
->
getAuthenticationMethod
()
==
Servatrice
::
AuthenticationSql
)
{
checkSql
();
QSqlQuery
*
query
=
prepareQuery
(
"select 1 from {prefix}_users where name = :name"
);
query
->
bindValue
(
":name"
,
user
);
if
(
!
execSqlQuery
(
query
))
return
false
;
return
query
->
next
();
}
return
false
;
}
int
Servatrice_DatabaseInterface
::
getUserIdInDB
(
const
QString
&
name
)
int
Servatrice_DatabaseInterface
::
getUserIdInDB
(
const
QString
&
name
)
{
{
if
(
server
->
getAuthenticationMethod
()
==
Servatrice
::
AuthenticationSql
)
{
if
(
server
->
getAuthenticationMethod
()
==
Servatrice
::
AuthenticationSql
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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