2022-04-11 10:18:22 +02:00
|
|
|
import newrelic
|
|
|
|
|
|
|
|
from app.models import EnumE
|
|
|
|
|
|
|
|
|
|
|
|
class LoginEvent:
|
|
|
|
class ActionType(EnumE):
|
|
|
|
success = 0
|
|
|
|
failed = 1
|
|
|
|
disabled_login = 2
|
|
|
|
not_activated = 3
|
|
|
|
|
2022-04-11 16:11:01 +02:00
|
|
|
class Source(EnumE):
|
|
|
|
web = 0
|
|
|
|
api = 1
|
|
|
|
|
|
|
|
def __init__(self, action: ActionType, source: Source = Source.web):
|
2022-04-11 10:18:22 +02:00
|
|
|
self.action = action
|
2022-04-11 16:11:01 +02:00
|
|
|
self.source = source
|
2022-04-11 10:18:22 +02:00
|
|
|
|
|
|
|
def send(self):
|
2022-04-11 16:11:01 +02:00
|
|
|
newrelic.agent.record_custom_event(
|
2022-04-12 09:04:57 +02:00
|
|
|
"LoginEvent", {"action": self.action.name, "source": self.source.name}
|
2022-04-11 16:11:01 +02:00
|
|
|
)
|
2022-04-11 10:18:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
class RegisterEvent:
|
|
|
|
class ActionType(EnumE):
|
|
|
|
success = 0
|
2022-04-11 16:11:01 +02:00
|
|
|
failed = 1
|
|
|
|
catpcha_failed = 2
|
|
|
|
email_in_use = 3
|
|
|
|
invalid_email = 4
|
|
|
|
|
|
|
|
class Source(EnumE):
|
|
|
|
web = 0
|
|
|
|
api = 1
|
2022-04-11 10:18:22 +02:00
|
|
|
|
2022-04-11 16:11:01 +02:00
|
|
|
def __init__(self, action: ActionType, source: Source = Source.web):
|
2022-04-11 10:18:22 +02:00
|
|
|
self.action = action
|
2022-04-11 16:11:01 +02:00
|
|
|
self.source = source
|
2022-04-11 10:18:22 +02:00
|
|
|
|
|
|
|
def send(self):
|
2022-04-11 16:11:01 +02:00
|
|
|
newrelic.agent.record_custom_event(
|
2022-04-12 09:04:57 +02:00
|
|
|
"RegisterEvent", {"action": self.action.name, "source": self.source.name}
|
2022-04-11 16:11:01 +02:00
|
|
|
)
|