missing file from previous commit
This commit is contained in:
parent
5ace0dd892
commit
d7b6f76191
1 changed files with 24 additions and 1 deletions
|
@ -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 &passwordSha512, 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
|
||||||
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
|
||||||
|
|
||||||
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,
|
||||||
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,
|
||||||
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) {
|
||||||
|
|
Loading…
Reference in a new issue