Skip to content

Commit 3113358

Browse files
bodom0015lmarini
andauthored
Add events for user login and signup (#181)
Co-authored-by: Luigi Marini <[email protected]>
1 parent b512cb4 commit 3113358

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

app/services/EventSinkService.scala

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class EventSinkService {
2727
val userService: UserService = DI.injector.getInstance(classOf[UserService])
2828
val appConfig: AppConfigurationService = DI.injector.getInstance(classOf[AppConfigurationService])
2929

30-
// Fetch directly from config on demand
30+
// UNUSED: Fetch directly from config on demand
3131
def getGoogleAnalytics(): String = Play.configuration.getString(EventSinkService.GA_CONFIG_KEY).getOrElse("")
3232
def getAmplitudeApiKey(): String = Play.configuration.getString(EventSinkService.AMPLITUDE_CONFIG_KEY).getOrElse("")
3333
def getMongoAuth(): String = Play.configuration.getString(EventSinkService.AMPLITUDE_CONFIG_KEY).getOrElse("")
@@ -51,14 +51,23 @@ class EventSinkService {
5151
messageService.submit(exchangeName, queueName, metadata, "fanout")
5252
}
5353

54-
// TODO: Call this when admin changes configuration via the UI
55-
def syncAuthInfo() = {
56-
Logger.info("Synchronizing event sink consumer auth")
57-
logEvent("auth_sync", Json.obj(
58-
"amplitude" -> getAmplitudeApiKey(),
59-
"google_analytics" -> getGoogleAnalytics(),
60-
"influx" -> getInfluxAuth(),
61-
"mongo" -> getMongoAuth()
54+
/** Log an event when user signs up */
55+
def logUserSignupEvent(user: User) = {
56+
Logger.info("New user signed up: " + user.id.stringify)
57+
logEvent("user_activity", Json.obj(
58+
"type" -> "signup",
59+
"user_id" -> user.id,
60+
"user_name" -> user.fullName
61+
))
62+
}
63+
64+
/** Log an event when user logs in */
65+
def logUserLoginEvent(user: User) = {
66+
Logger.info("User logged in: " + user.id.stringify)
67+
logEvent("user_activity", Json.obj(
68+
"type" -> "login",
69+
"user_id" -> user.id,
70+
"user_name" -> user.fullName
6271
))
6372
}
6473

app/services/SecureSocialEventListener.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class SecureSocialEventListener(app: play.api.Application) extends EventListener
1212
override def id: String = "SecureSocialEventListener"
1313
lazy val userService: UserService = DI.injector.getInstance(classOf[UserService])
1414
lazy val spaceService: SpaceService = DI.injector.getInstance(classOf[SpaceService])
15+
lazy val sinkService: EventSinkService = DI.injector.getInstance(classOf[EventSinkService])
1516
lazy val appConfig: AppConfigurationService = DI.injector.getInstance(classOf[AppConfigurationService])
1617

1718
def onEvent(event: Event, request: RequestHeader, session: Session): Option[Session] = {
@@ -27,6 +28,7 @@ class SecureSocialEventListener(app: play.api.Application) extends EventListener
2728
case None => Logger.debug("No email found for user "+user.id.stringify)
2829
}
2930
userService.updateUserField(user.id, "lastLogin", new Date())
31+
sinkService.logUserSignupEvent(user)
3032
}
3133
case None => {
3234
Logger.error(s"Could not find user ${event.user.fullName} in database")
@@ -47,6 +49,7 @@ class SecureSocialEventListener(app: play.api.Application) extends EventListener
4749
case None => Logger.debug("No email found for user "+user.id.stringify)
4850
}
4951
userService.updateUserField(user.id, "lastLogin", new Date())
52+
sinkService.logUserLoginEvent(user)
5053
}
5154
case None => {
5255
Logger.error(s"Could not find user ${event.user.fullName} in database")

0 commit comments

Comments
 (0)