Set user join date in database again on account creation
This commit is contained in:
@@ -6,6 +6,7 @@ import rs09.ServerConstants
|
|||||||
import rs09.storage.AccountStorageProvider
|
import rs09.storage.AccountStorageProvider
|
||||||
import rs09.storage.SQLStorageProvider
|
import rs09.storage.SQLStorageProvider
|
||||||
import java.sql.SQLDataException
|
import java.sql.SQLDataException
|
||||||
|
import java.sql.Timestamp
|
||||||
|
|
||||||
class ProductionAuthenticator : AuthProvider<AccountStorageProvider>() {
|
class ProductionAuthenticator : AuthProvider<AccountStorageProvider>() {
|
||||||
override fun configureFor(provider: AccountStorageProvider) {
|
override fun configureFor(provider: AccountStorageProvider) {
|
||||||
@@ -18,6 +19,7 @@ class ProductionAuthenticator : AuthProvider<AccountStorageProvider>() {
|
|||||||
override fun createAccountWith(info: UserAccountInfo): Boolean {
|
override fun createAccountWith(info: UserAccountInfo): Boolean {
|
||||||
try {
|
try {
|
||||||
info.password = SystemManager.getEncryption().hashPassword(info.password)
|
info.password = SystemManager.getEncryption().hashPassword(info.password)
|
||||||
|
info.joinDate = Timestamp(System.currentTimeMillis())
|
||||||
storageProvider.store(info)
|
storageProvider.store(info)
|
||||||
} catch (e: SQLDataException) {
|
} catch (e: SQLDataException) {
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package rs09.auth
|
package rs09.auth
|
||||||
|
|
||||||
|
import java.sql.Timestamp
|
||||||
|
|
||||||
class UserAccountInfo(
|
class UserAccountInfo(
|
||||||
var username: String,
|
var username: String,
|
||||||
var password: String,
|
var password: String,
|
||||||
@@ -17,11 +19,12 @@ class UserAccountInfo(
|
|||||||
var clanReqs: String,
|
var clanReqs: String,
|
||||||
var timePlayed: Long,
|
var timePlayed: Long,
|
||||||
var lastLogin: Long,
|
var lastLogin: Long,
|
||||||
var online: Boolean
|
var online: Boolean,
|
||||||
|
var joinDate: Timestamp
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic fun createDefault() : UserAccountInfo {
|
@JvmStatic fun createDefault() : UserAccountInfo {
|
||||||
return UserAccountInfo("", "", 0, 0, 0, "", "", 0L, 0L, "", "", "", "", "1,0,8,9", 0L, 0L, false).also { it.setInitialReferenceValues() }
|
return UserAccountInfo("", "", 0, 0, 0, "", "", 0L, 0L, "", "", "", "", "1,0,8,9", 0L, 0L, false, joinDate = Timestamp(System.currentTimeMillis())).also { it.setInitialReferenceValues() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +46,7 @@ class UserAccountInfo(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun toArray(): Array<Any> {
|
fun toArray(): Array<Any> {
|
||||||
return arrayOf(username, password, uid, rights, credits, ip, lastUsedIp, muteEndTime, banEndTime, contacts, blocked, clanName, currentClan, clanReqs, timePlayed, lastLogin, online)
|
return arrayOf(username, password, uid, rights, credits, ip, lastUsedIp, muteEndTime, banEndTime, contacts, blocked, clanName, currentClan, clanReqs, timePlayed, lastLogin, online, joinDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ class SQLStorageProvider : AccountStorageProvider {
|
|||||||
result.getLong(15) .let { userData.timePlayed = max(0L, it) }
|
result.getLong(15) .let { userData.timePlayed = max(0L, it) }
|
||||||
result.getLong(16) .let { userData.lastLogin = max(0L, it) }
|
result.getLong(16) .let { userData.lastLogin = max(0L, it) }
|
||||||
result.getBoolean(17) .let { userData.online = it }
|
result.getBoolean(17) .let { userData.online = it }
|
||||||
|
result.getTimestamp(18) .let { userData.joinDate = it ?: Timestamp(System.currentTimeMillis()) }
|
||||||
|
|
||||||
userData.setInitialReferenceValues()
|
userData.setInitialReferenceValues()
|
||||||
return userData
|
return userData
|
||||||
@@ -102,6 +103,7 @@ class SQLStorageProvider : AccountStorageProvider {
|
|||||||
compiledInsertInfoQuery.setLong(14, info.timePlayed)
|
compiledInsertInfoQuery.setLong(14, info.timePlayed)
|
||||||
compiledInsertInfoQuery.setLong(15, info.lastLogin)
|
compiledInsertInfoQuery.setLong(15, info.lastLogin)
|
||||||
compiledInsertInfoQuery.setBoolean(16, info.online)
|
compiledInsertInfoQuery.setBoolean(16, info.online)
|
||||||
|
compiledInsertInfoQuery.setTimestamp(17, info.joinDate)
|
||||||
compiledInsertInfoQuery.execute()
|
compiledInsertInfoQuery.execute()
|
||||||
val result = compiledInsertInfoQuery.generatedKeys
|
val result = compiledInsertInfoQuery.generatedKeys
|
||||||
if (result.next()) {
|
if (result.next()) {
|
||||||
@@ -195,7 +197,8 @@ class SQLStorageProvider : AccountStorageProvider {
|
|||||||
"clanReqs," +
|
"clanReqs," +
|
||||||
"timePlayed," +
|
"timePlayed," +
|
||||||
"lastLogin," +
|
"lastLogin," +
|
||||||
"online" +
|
"online," +
|
||||||
|
"joined_date" +
|
||||||
" FROM members WHERE username = ?;"
|
" FROM members WHERE username = ?;"
|
||||||
private const val insertInfoQuery = "INSERT INTO members (" +
|
private const val insertInfoQuery = "INSERT INTO members (" +
|
||||||
"username," +
|
"username," +
|
||||||
@@ -213,8 +216,9 @@ class SQLStorageProvider : AccountStorageProvider {
|
|||||||
"clanReqs," +
|
"clanReqs," +
|
||||||
"timePlayed," +
|
"timePlayed," +
|
||||||
"lastLogin," +
|
"lastLogin," +
|
||||||
"online" +
|
"online," +
|
||||||
") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"
|
"joined_date" +
|
||||||
|
") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"
|
||||||
|
|
||||||
private fun buildUpdateInfoQuery(updatedIndices: ArrayList<Int>) : String {
|
private fun buildUpdateInfoQuery(updatedIndices: ArrayList<Int>) : String {
|
||||||
val sb = StringBuilder("UPDATE members SET ")
|
val sb = StringBuilder("UPDATE members SET ")
|
||||||
|
|||||||
Reference in New Issue
Block a user