Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Review errorCodes
Browse files Browse the repository at this point in the history
  • Loading branch information
kahverengi committed Dec 9, 2020
1 parent 7cfccb1 commit c33eb29
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
23 changes: 12 additions & 11 deletions src/main/kotlin/com/parnote/ErrorCode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ enum class ErrorCode {
UNKNOWN_ERROR_62,
UNKNOWN_ERROR_63,
UNKNOWN_ERROR_64,
UNKNOWN_ERROR_65,

REGISTER_NAME_EMPTY,
REGISTER_NAME_SHORT,
Expand All @@ -86,27 +87,27 @@ enum class ErrorCode {

RESET_PASSWORD_USERNAME_OR_EMAIL_INVALID,

LOGIN_IS_INVALID,
LOGIN_LOGIN_IS_INVALID,
LOGIN_EMAIL_NOT_VERIFIED,

EMAIL_VERIFICATION_INVALID_TOKEN,

TAKEN_EMAIL_ERROR,
TAKEN_USERNAME_ERROR,
REGISTER_TAKEN_EMAIL_ERROR,
REGISTER_TAKEN_USERNAME_ERROR,

RECAPTCHA_NOT_VALID,

EXPIRED_TOKEN_VALIDATION,
EXPIRED_TOKEN_VALIDATION, // system message

NEW_PASSWORD_EMPTY,
NEW_PASSWORD_INVALID,
NEW_PASSWORD_DOESNT_MATCH,
NEW_PASSWORD_REPEAT_EMPTY,
NEW_PASSWORD_REPEAT_INVALID,
RESET_PASSWORD_NEW_PASSWORD_EMPTY,
RESET_PASSWORD_NEW_PASSWORD_INVALID,
RESET_PASSWORD_NEW_PASSWORD_DOESNT_MATCH,
RESET_PASSWORD_NEW_PASSWORD_REPEAT_EMPTY,
RESET_PASSWORD_NEW_PASSWORD_REPEAT_INVALID,

TOKEN_IS_INVALID,
RESET_PASSWORD_INVALID_TOKEN,

NOT_LOGGED_IN,
NOT_LOGGED_IN, // system message

SETTINGS_CHANGE_PASSWORD_INVALID_PASSWORD,
SETTINGS_CHANGE_PASSWORD_NEW_PASSWORD_EMPTY,
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/com/parnote/route/api/LoginAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class LoginAPI : Api() {

if (!exists) {
databaseManager.closeConnection(sqlConnection) {
handler.invoke(Error(ErrorCode.LOGIN_IS_INVALID))
handler.invoke(Error(ErrorCode.LOGIN_LOGIN_IS_INVALID))
}

return@isExistsByUsernameOrEmail
Expand Down Expand Up @@ -137,7 +137,7 @@ class LoginAPI : Api() {
if (isLoggedIn)
handler.invoke(Successful())
else
handler.invoke(Error(ErrorCode.LOGIN_IS_INVALID))
handler.invoke(Error(ErrorCode.LOGIN_LOGIN_IS_INVALID))
}
}
}
Expand All @@ -155,25 +155,25 @@ class LoginAPI : Api() {
successHandler: () -> Unit
) {
if (usernameOrEmail.isEmpty()) {
errorHandler.invoke(Error(ErrorCode.LOGIN_IS_INVALID))
errorHandler.invoke(Error(ErrorCode.LOGIN_LOGIN_IS_INVALID))

return
}

if (!usernameOrEmail.matches(Regex("^[a-zA-Z0-9_]+\$")) && !usernameOrEmail.matches(Regex("^[\\w-.]+@([\\w-]+\\.)+[\\w-]{2,4}\$"))) {
errorHandler.invoke(Error(ErrorCode.LOGIN_IS_INVALID))
errorHandler.invoke(Error(ErrorCode.LOGIN_LOGIN_IS_INVALID))

return
}

if (password.isEmpty()) {
errorHandler.invoke(Error(ErrorCode.LOGIN_IS_INVALID))
errorHandler.invoke(Error(ErrorCode.LOGIN_LOGIN_IS_INVALID))

return
}

if (!password.matches(Regex("^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,64}\$"))) {
errorHandler.invoke(Error(ErrorCode.LOGIN_IS_INVALID))
errorHandler.invoke(Error(ErrorCode.LOGIN_LOGIN_IS_INVALID))

return
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/parnote/route/api/RegisterAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class RegisterAPI : Api() {

if (emailExists) {
databaseManager.closeConnection(sqlConnection) {
handler.invoke(Error(ErrorCode.TAKEN_EMAIL_ERROR))
handler.invoke(Error(ErrorCode.REGISTER_TAKEN_EMAIL_ERROR))
}

return@handler
Expand Down Expand Up @@ -304,7 +304,7 @@ class RegisterAPI : Api() {

if (usernameExists) {
databaseManager.closeConnection(sqlConnection) {
handler.invoke(Error(ErrorCode.TAKEN_USERNAME_ERROR))
handler.invoke(Error(ErrorCode.REGISTER_TAKEN_USERNAME_ERROR))
}

return@handler
Expand Down
16 changes: 8 additions & 8 deletions src/main/kotlin/com/parnote/route/api/ResetPasswordAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ResetPasswordAPI : Api() {

if (!exists) {
databaseManager.closeConnection(sqlConnection) {
handler.invoke(Error(ErrorCode.TOKEN_IS_INVALID))
handler.invoke(Error(ErrorCode.RESET_PASSWORD_INVALID_TOKEN))
}

return@isTokenExists
Expand Down Expand Up @@ -88,7 +88,7 @@ class ResetPasswordAPI : Api() {
return@closeConnection
}

handler.invoke(Error(ErrorCode.TOKEN_IS_INVALID))
handler.invoke(Error(ErrorCode.RESET_PASSWORD_INVALID_TOKEN))
}
}

Expand Down Expand Up @@ -130,7 +130,7 @@ class ResetPasswordAPI : Api() {
) { resultOfDeleteToken, _ ->
databaseManager.closeConnection(sqlConnection) {
if (resultOfDeleteToken == null) {
handler.invoke(Error(ErrorCode.UNKNOWN_ERROR_28))
handler.invoke(Error(ErrorCode.UNKNOWN_ERROR_65))

return@closeConnection
}
Expand Down Expand Up @@ -161,31 +161,31 @@ class ResetPasswordAPI : Api() {
}

if (newPassword.isEmpty()) {
errorHandler.invoke(Error(ErrorCode.NEW_PASSWORD_EMPTY))
errorHandler.invoke(Error(ErrorCode.RESET_PASSWORD_NEW_PASSWORD_EMPTY))

return
}

if (newPasswordRepeat.isEmpty()) {
errorHandler.invoke(Error(ErrorCode.NEW_PASSWORD_REPEAT_EMPTY))
errorHandler.invoke(Error(ErrorCode.RESET_PASSWORD_NEW_PASSWORD_REPEAT_EMPTY))

return
}

if (newPassword != newPasswordRepeat) {
errorHandler.invoke(Error(ErrorCode.NEW_PASSWORD_DOESNT_MATCH))
errorHandler.invoke(Error(ErrorCode.RESET_PASSWORD_NEW_PASSWORD_DOESNT_MATCH))

return
}

if (!newPassword.matches(Regex("^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,64}\$"))) {
errorHandler.invoke(Error(ErrorCode.NEW_PASSWORD_INVALID))
errorHandler.invoke(Error(ErrorCode.RESET_PASSWORD_NEW_PASSWORD_INVALID))

return
}

if (!newPasswordRepeat.matches(Regex("^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,64}\$"))) {
errorHandler.invoke(Error(ErrorCode.NEW_PASSWORD_REPEAT_INVALID))
errorHandler.invoke(Error(ErrorCode.RESET_PASSWORD_NEW_PASSWORD_REPEAT_INVALID))

return
}
Expand Down

0 comments on commit c33eb29

Please sign in to comment.