Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package co.nilin.opex.api.core.inout.auth

open class Device {
var deviceUuid: String?=null
var appVersion: String?=null
var osVersion: String?=null
var os: Os?=null
var appVersion: String? = null
var os: Os? = null
var osVersion: String? = null
var brand: String? = null
var model: String? = null
var platform: Platform? = null
var agent: String? = null
var pushToken: String? = null
var deviceUuid: String? = null
var buildNumber: Int? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ enum class SessionStatus {
enum class Os {
ANDROID, IOS, MOBILE_WEB, DESKTOP_WEB
}
enum class Platform {
WEB_APP, WEB_DESKTOP, ANDROID_NATIVE_APP, IOS_NATIVE_APP, WEB_ADMIN_DESKTOP
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package co.nilin.opex.auth.data

open class Device {
var deviceUuid: String?=null
var appVersion: String?=null
var osVersion: String?=null
var os: Os?=null
var appVersion: String? = null
var os: Os? = null
var osVersion: String? = null
var brand: String? = null
var model: String? = null
var platform: Platform? = null
var agent: String? = null
var pushToken: String? = null
var deviceUuid: String? = null
var buildNumber: Int? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ import java.time.LocalDateTime

data class LoginEvent(
val uuid: String,
val sessionId: String?,
val deviceUuid: String?,
val appVersion: String?,
val osVersion: String?,
val expireDate: LocalDateTime,
val pushToken: String?,
val os: Os?,
val brand: String?,
val model: String?,
val platform: Platform?,
val agent: String?,
val buildNumber: Int?,
val sessionId: String,
val expireDate: LocalDateTime
) : AuthEvent()
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ data class Sessions(
val sessionStatus: SessionStatus?,
val sessionCreateDate: LocalDateTime?,
val sessionExpireDate: LocalDateTime?,
var isCurrentSession: Boolean?=false
var isCurrentSession: Boolean? = false
)

enum class SessionStatus {
Expand All @@ -25,3 +25,7 @@ enum class SessionStatus {
enum class Os {
ANDROID, IOS, MOBILE_WEB, DESKTOP_WEB
}

enum class Platform {
WEB_APP, WEB_DESKTOP, ANDROID_NATIVE_APP, IOS_NATIVE_APP, WEB_ADMIN_DESKTOP
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,27 @@ class LoginService(
return TokenResponse(token, null, null)
}

private fun sendLoginEvent(userId: String, sessionState: String?, request: Device, expiresIn: Int) {
private fun sendLoginEvent(
userId: String,
sessionState: String?,
request: Device,
expiresIn: Int
) {
authEventProducer.send(
LoginEvent(
userId,
sessionState,
request.deviceUuid,
request.appVersion,
request.osVersion,
LocalDateTime.now().plusSeconds(expiresIn.toLong()),
request.os
uuid = userId,
deviceUuid = request.deviceUuid,
appVersion = request.appVersion,
osVersion = request.osVersion,
pushToken = request.pushToken,
os = request.os,
brand = request.brand,
model = request.model,
platform = request.platform,
agent = request.agent,
buildNumber = request.buildNumber,
sessionId = sessionState ?: "",
expireDate = LocalDateTime.now().plusSeconds(expiresIn.toLong())
Comment thread
AmirRajabii marked this conversation as resolved.
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class RegisterService(
isUserDuplicate(username)
val otpType = username.type.otpType
val otpReceiver = OTPReceiver(request.username, otpType)
val res = otpProxy.requestOTP(request.username, listOf(otpReceiver),OTPAction.REGISTER)
val res = otpProxy.requestOTP(request.username, listOf(otpReceiver), OTPAction.REGISTER)
return TempOtpResponse(res.otp, otpReceiver)
}

Expand Down Expand Up @@ -107,16 +107,27 @@ class RegisterService(
keycloakProxy.linkGoogleIdentity(userId, email, googleUserId)
}

private fun sendLoginEvent(userId: String, sessionState: String?, request: Device, expiresIn: Int) {
private fun sendLoginEvent(
userId: String,
sessionState: String?,
request: Device,
expiresIn: Int
) {
authProducer.send(
LoginEvent(
userId,
sessionState,
request.deviceUuid,
request.appVersion,
request.osVersion,
LocalDateTime.now().plusSeconds(expiresIn.toLong()),
request.os
uuid = userId,
deviceUuid = request.deviceUuid,
appVersion = request.appVersion,
osVersion = request.osVersion,
pushToken = request.pushToken,
os = request.os,
brand = request.brand,
model = request.model,
platform = request.platform,
agent = request.agent,
buildNumber = request.buildNumber,
sessionId = sessionState ?: "",
expireDate = LocalDateTime.now().plusSeconds(expiresIn.toLong())
Comment thread
AmirRajabii marked this conversation as resolved.
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ data class Device(
val os: Os? = null,
val osVersion: String? = null,
val appVersion: String? = null,
val brand: String? = null,
val model: String? = null,
val platform: Platform? = null,
val agent: String? = null,
val pushToken: String? = null,
val createDate: LocalDateTime?= LocalDateTime.now(),
val lastUpdateDate: LocalDateTime?= LocalDateTime.now()

val buildNumber: Int? = null,
val createDate: LocalDateTime? = LocalDateTime.now(),
val lastUpdateDate: LocalDateTime? = LocalDateTime.now()
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ data class LoginEvent(
val osVersion: String?,
val pushToken: String?,
val os: Os?,
val brand: String?,
val model: String?,
val platform: Platform?,
val agent: String?,
val buildNumber: Int?,
val sessionId: String,
val expireDate: LocalDateTime,
) : SessionEvent()
val expireDate: LocalDateTime
) : SessionEvent()

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package co.nilin.opex.device.core.data

enum class Platform {
WEB_APP, WEB_DESKTOP, ANDROID_NATIVE_APP, IOS_NATIVE_APP, WEB_ADMIN_DESKTOP
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,24 @@ class UserSessionDeviceService(
) {

suspend fun getUserSessionsWithDevices(sessionsRequest: SessionsRequest): List<UserSessionDevice> {
return sessionPersister.fetchUserDeviceSession( sessionsRequest)
return sessionPersister.fetchUserDeviceSession(sessionsRequest)
}

@Transactional
suspend fun upsertDevice(loginEvent: LoginEvent) {
val device = with(loginEvent) {
devicePersister.upsertDevice(
Device(
deviceUuid = this.deviceUuid ?: UUID.randomUUID().toString(),
os = this.os,
osVersion = this.osVersion,
appVersion = this.appVersion,
pushToken = this.pushToken,
deviceUuid = deviceUuid ?: UUID.randomUUID().toString(),
os = os,
osVersion = osVersion,
appVersion = appVersion,
brand = brand,
model = model,
platform = platform,
agent = agent,
pushToken = pushToken,
buildNumber = buildNumber
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import co.nilin.opex.device.core.spi.DevicePersister
import co.nilin.opex.device.ports.postgres.dao.DeviceRepository
import co.nilin.opex.device.ports.postgres.utils.toDto
import co.nilin.opex.device.ports.postgres.utils.toModel

import kotlinx.coroutines.reactive.awaitFirstOrNull
import kotlinx.coroutines.reactive.awaitFirst
import kotlinx.coroutines.reactive.awaitFirstOrNull
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import java.time.LocalDateTime
Expand All @@ -29,7 +28,12 @@ class DeviceManagerImpl(
os = device.os,
osVersion = device.osVersion,
appVersion = device.appVersion,
brand = device.brand,
model = device.model,
platform = device.platform,
agent = device.agent,
pushToken = device.pushToken,
buildNumber = device.buildNumber,
lastUpdateDate = now
)
).awaitFirst()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package co.nilin.opex.device.ports.postgres.model

import co.nilin.opex.device.core.data.Os
import co.nilin.opex.device.core.data.Platform
import org.springframework.data.annotation.Id
import org.springframework.data.annotation.Version
import org.springframework.data.relational.core.mapping.Column
Expand All @@ -10,13 +11,33 @@ import java.time.LocalDateTime

@Table(name = "devices")
data class DeviceModel(
@Id val id: Long?=null,
@Column("device_uuid") val deviceUuid: String,
@Column("os") val os: Os?,
@Column("os_version") val osVersion: String?,
@Column("app_version") val appVersion: String?,
@Column("push_token") val pushToken: String?,
@Column("create_date") val creteDate: LocalDateTime? = LocalDateTime.now(),
@Column("last_update_date") val lastUpdateDate: LocalDateTime? = LocalDateTime.now(),
@Column @Version var version: Long? = null
@Id
val id: Long? = null,
@Column("device_uuid")
val deviceUuid: String,
@Column("os")
val os: Os?,
@Column("os_version")
val osVersion: String?,
@Column("app_version")
val appVersion: String?,
@Column("brand")
val brand: String?,
@Column("model")
val model: String?,
@Column("platform")
val platform: Platform?,
@Column("agent")
val agent: String?,
@Column("push_token")
val pushToken: String?,
@Column("build_number")
val buildNumber: Int?,
@Column("create_date")
val createDate: LocalDateTime? = LocalDateTime.now(),
@Column("last_update_date")
val lastUpdateDate: LocalDateTime? = LocalDateTime.now(),
@Version
@Column("version")
var version: Long? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ fun Device.toModel(): DeviceModel {
os = os,
osVersion = osVersion,
appVersion = appVersion,
brand = brand,
model = model,
platform = platform,
agent = agent,
pushToken = pushToken,
creteDate = createDate ?: LocalDateTime.now(),
buildNumber = buildNumber,
createDate = createDate ?: LocalDateTime.now(),
lastUpdateDate = lastUpdateDate ?: LocalDateTime.now()
)
}
Expand All @@ -28,8 +33,13 @@ fun DeviceModel.toDto(): Device {
os = os,
osVersion = osVersion,
appVersion = appVersion,
brand = brand,
model = model,
platform = platform,
agent = agent,
pushToken = pushToken,
createDate = creteDate,
buildNumber = buildNumber,
createDate = createDate,
lastUpdateDate = lastUpdateDate
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE devices
ADD COLUMN IF NOT EXISTS brand VARCHAR(100),
ADD COLUMN IF NOT EXISTS model VARCHAR(100),
ADD COLUMN IF NOT EXISTS platform VARCHAR(50),
ADD COLUMN IF NOT EXISTS agent VARCHAR(255),
ADD COLUMN IF NOT EXISTS build_number INTEGER;
Comment thread
AmirRajabii marked this conversation as resolved.
3 changes: 3 additions & 0 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ services:
postgres-profile:
ports:
- "5440:5432"
postgres-device-management:
ports:
- "5441:5432"
accountant:
ports:
- "127.0.0.1:8089:8080"
Expand Down
Loading