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
4c273040
Commit
4c273040
authored
Jun 29, 2015
by
Fabio Bas
Browse files
publish username rules in registration failure
parent
9947af7b
Changes
5
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/window_main.cpp
View file @
4c273040
...
@@ -30,6 +30,10 @@
...
@@ -30,6 +30,10 @@
#include
<QDateTime>
#include
<QDateTime>
#include
<QSystemTrayIcon>
#include
<QSystemTrayIcon>
#include
<QApplication>
#include
<QApplication>
#if QT_VERSION < 0x050000
// for Qt::escape()
#include
<QtGui/qtextdocument.h>
#endif
#include
"main.h"
#include
"main.h"
#include
"window_main.h"
#include
"window_main.h"
...
@@ -359,8 +363,37 @@ void MainWindow::registerError(Response::ResponseCode r, QString reasonStr, quin
...
@@ -359,8 +363,37 @@ void MainWindow::registerError(Response::ResponseCode r, QString reasonStr, quin
break
;
break
;
}
}
case
Response
::
RespUsernameInvalid
:
case
Response
::
RespUsernameInvalid
:
QMessageBox
::
critical
(
this
,
tr
(
"Error"
),
tr
(
"Invalid username.
\n
You may only use A-Z, a-z, 0-9, _, ., and - in your username."
));
{
QString
error
=
tr
(
"Invalid username."
)
+
"<br/>"
;
QStringList
rules
=
reasonStr
.
split
(
QChar
(
'|'
));
if
(
rules
.
size
()
==
7
)
{
error
+=
tr
(
"The username must respect these rules:"
)
+
"<br/><ul>"
+
"<li>"
+
tr
(
"length between %1 and %2 characters"
).
arg
(
rules
.
at
(
0
)).
arg
(
rules
.
at
(
1
))
+
"</li>"
;
if
(
rules
.
at
(
2
).
toInt
()
>
0
)
error
+=
"<li>"
+
tr
(
"it can contain lowercase characters"
)
+
"</li>"
;
if
(
rules
.
at
(
3
).
toInt
()
>
0
)
error
+=
"<li>"
+
tr
(
"it can contain uppercase characters"
)
+
"</li>"
;
if
(
rules
.
at
(
4
).
toInt
()
>
0
)
error
+=
"<li>"
+
tr
(
"it can contain numeric characters"
)
+
"</li>"
;
if
(
rules
.
at
(
6
).
size
()
>
0
)
error
+=
"<li>"
+
tr
(
"it can contain the following punctuation: %1"
).
arg
(
#if QT_VERSION < 0x050000
Qt
::
escape
(
rules
.
at
(
6
))
#else
rules
.
at
(
6
).
toHtmlEscaped
()
#endif
)
+
"</li>"
;
if
(
rules
.
at
(
5
).
toInt
()
>
0
)
error
+=
"<li>"
+
tr
(
"the first character can't be a punctuation"
)
+
"</li>"
;
error
+=
"</ul>"
;
}
else
{
error
+=
tr
(
"You may only use A-Z, a-z, 0-9, _, ., and - in your username."
);
}
QMessageBox
::
critical
(
this
,
tr
(
"Error"
),
error
);
break
;
break
;
}
case
Response
::
RespRegistrationFailed
:
case
Response
::
RespRegistrationFailed
:
QMessageBox
::
critical
(
this
,
tr
(
"Error"
),
tr
(
"Registration failed for a technical problem on the server."
));
QMessageBox
::
critical
(
this
,
tr
(
"Error"
),
tr
(
"Registration failed for a technical problem on the server."
));
break
;
break
;
...
...
common/server_database_interface.h
View file @
4c273040
...
@@ -25,7 +25,7 @@ public:
...
@@ -25,7 +25,7 @@ public:
virtual
DeckList
*
getDeckFromDatabase
(
int
/* deckId */
,
int
/* userId */
)
{
return
0
;
}
virtual
DeckList
*
getDeckFromDatabase
(
int
/* deckId */
,
int
/* userId */
)
{
return
0
;
}
virtual
qint64
startSession
(
const
QString
&
/* userName */
,
const
QString
&
/* address */
)
{
return
0
;
}
virtual
qint64
startSession
(
const
QString
&
/* userName */
,
const
QString
&
/* address */
)
{
return
0
;
}
virtual
bool
usernameIsValid
(
const
QString
&
/*userName */
)
{
return
true
;
};
virtual
bool
usernameIsValid
(
const
QString
&
/*userName
*/
,
QString
&
/* error
*/
)
{
return
true
;
};
public
slots
:
public
slots
:
virtual
void
endSession
(
qint64
/* sessionId */
)
{
}
virtual
void
endSession
(
qint64
/* sessionId */
)
{
}
public:
public:
...
...
servatrice/src/servatrice_database_interface.cpp
View file @
4c273040
...
@@ -118,24 +118,29 @@ bool Servatrice_DatabaseInterface::execSqlQuery(QSqlQuery *query)
...
@@ -118,24 +118,29 @@ bool Servatrice_DatabaseInterface::execSqlQuery(QSqlQuery *query)
return
false
;
return
false
;
}
}
bool
Servatrice_DatabaseInterface
::
usernameIsValid
(
const
QString
&
user
)
bool
Servatrice_DatabaseInterface
::
usernameIsValid
(
const
QString
&
user
,
QString
&
error
)
{
{
int
maxNameLength
=
settingsCache
->
value
(
"users/maxnamelength"
,
12
).
toInt
();
int
minNameLength
=
settingsCache
->
value
(
"users/minnamelength"
,
6
).
toInt
();
int
minNameLength
=
settingsCache
->
value
(
"users/minnamelength"
,
6
).
toInt
();
int
maxNameLength
=
settingsCache
->
value
(
"users/maxnamelength"
,
12
).
toInt
();
bool
allowLowercase
=
settingsCache
->
value
(
"users/allowlowercase"
,
true
).
toBool
();
bool
allowUppercase
=
settingsCache
->
value
(
"users/allowuppercase"
,
true
).
toBool
();
bool
allowNumerics
=
settingsCache
->
value
(
"users/allownumerics"
,
true
).
toBool
();
bool
allowPunctuationPrefix
=
settingsCache
->
value
(
"users/allowpunctuationprefix"
,
false
).
toBool
();
QString
allowedPunctuation
=
settingsCache
->
value
(
"users/allowedpunctuation"
,
"_"
).
toString
();
error
=
QString
(
"%1|%2|%3|%4|%5|%6|%7"
).
arg
(
minNameLength
).
arg
(
maxNameLength
).
arg
(
allowLowercase
).
arg
(
allowUppercase
).
arg
(
allowNumerics
).
arg
(
allowPunctuationPrefix
).
arg
(
allowedPunctuation
);
if
(
user
.
length
()
<
minNameLength
||
user
.
length
()
>
maxNameLength
)
if
(
user
.
length
()
<
minNameLength
||
user
.
length
()
>
maxNameLength
)
return
false
;
return
false
;
bool
allowPunctuationPrefix
=
settingsCache
->
value
(
"users/allowpunctuationprefix"
,
false
).
toBool
();
QString
allowedPunctuation
=
settingsCache
->
value
(
"users/allowedpunctuation"
,
"_"
).
toString
();
if
(
!
allowPunctuationPrefix
&&
allowedPunctuation
.
contains
(
user
.
at
(
0
)))
if
(
!
allowPunctuationPrefix
&&
allowedPunctuation
.
contains
(
user
.
at
(
0
)))
return
false
;
return
false
;
QString
regEx
(
"["
);
QString
regEx
(
"["
);
if
(
settingsCache
->
value
(
"users/
allow
l
owercase
"
,
true
).
toBool
()
)
if
(
allow
L
owercase
)
regEx
.
append
(
"a-z"
);
regEx
.
append
(
"a-z"
);
if
(
settingsCache
->
value
(
"users/
allow
u
ppercase
"
,
true
).
toBool
()
)
if
(
allow
U
ppercase
)
regEx
.
append
(
"A-Z"
);
regEx
.
append
(
"A-Z"
);
if
(
settingsCache
->
value
(
"users/
allow
n
umerics
"
,
true
).
toBool
()
)
if
(
allow
N
umerics
)
regEx
.
append
(
"0-9"
);
regEx
.
append
(
"0-9"
);
regEx
.
append
(
QRegExp
::
escape
(
allowedPunctuation
));
regEx
.
append
(
QRegExp
::
escape
(
allowedPunctuation
));
regEx
.
append
(
"]+"
);
regEx
.
append
(
"]+"
);
...
@@ -242,7 +247,8 @@ AuthenticationResult Servatrice_DatabaseInterface::checkUserPassword(Server_Prot
...
@@ -242,7 +247,8 @@ AuthenticationResult Servatrice_DatabaseInterface::checkUserPassword(Server_Prot
if
(
!
checkSql
())
if
(
!
checkSql
())
return
UnknownUser
;
return
UnknownUser
;
if
(
!
usernameIsValid
(
user
))
QString
error
;
if
(
!
usernameIsValid
(
user
,
error
))
return
UsernameInvalid
;
return
UsernameInvalid
;
if
(
checkUserIsBanned
(
handler
->
getAddress
(),
user
,
reasonStr
,
banSecondsLeft
))
if
(
checkUserIsBanned
(
handler
->
getAddress
(),
user
,
reasonStr
,
banSecondsLeft
))
...
...
servatrice/src/servatrice_database_interface.h
View file @
4c273040
...
@@ -62,7 +62,7 @@ public:
...
@@ -62,7 +62,7 @@ public:
void
lockSessionTables
();
void
lockSessionTables
();
void
unlockSessionTables
();
void
unlockSessionTables
();
bool
userSessionExists
(
const
QString
&
userName
);
bool
userSessionExists
(
const
QString
&
userName
);
bool
usernameIsValid
(
const
QString
&
user
);
bool
usernameIsValid
(
const
QString
&
user
,
QString
&
error
);
bool
checkUserIsBanned
(
const
QString
&
ipAddress
,
const
QString
&
userName
,
QString
&
banReason
,
int
&
banSecondsRemaining
);
bool
checkUserIsBanned
(
const
QString
&
ipAddress
,
const
QString
&
userName
,
QString
&
banReason
,
int
&
banSecondsRemaining
);
bool
getRequireRegistration
();
bool
getRequireRegistration
();
...
...
servatrice/src/serversocketinterface.cpp
View file @
4c273040
...
@@ -788,8 +788,14 @@ Response::ResponseCode ServerSocketInterface::cmdRegisterAccount(const Command_R
...
@@ -788,8 +788,14 @@ Response::ResponseCode ServerSocketInterface::cmdRegisterAccount(const Command_R
}
}
// TODO: Move this method outside of the db interface
// TODO: Move this method outside of the db interface
if
(
!
sqlInterface
->
usernameIsValid
(
userName
))
QString
errorString
;
if
(
!
sqlInterface
->
usernameIsValid
(
userName
,
errorString
))
{
Response_Register
*
re
=
new
Response_Register
;
re
->
set_denied_reason_str
(
errorString
.
toStdString
());
rc
.
setResponseExtension
(
re
);
return
Response
::
RespUsernameInvalid
;
return
Response
::
RespUsernameInvalid
;
}
if
(
sqlInterface
->
userExists
(
userName
))
if
(
sqlInterface
->
userExists
(
userName
))
return
Response
::
RespUserAlreadyExists
;
return
Response
::
RespUserAlreadyExists
;
...
...
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