2022-04-11 08:18:22 +00: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 14:11:01 +00:00
|
|
|
class Source(EnumE):
|
|
|
|
web = 0
|
|
|
|
api = 1
|
|
|
|
|
|
|
|
def __init__(self, action: ActionType, source: Source = Source.web):
|
2022-04-11 08:18:22 +00:00
|
|
|
self.action = action
|
2022-04-11 14:11:01 +00:00
|
|
|
self.source = source
|
2022-04-11 08:18:22 +00:00
|
|
|
|
|
|
|
def send(self):
|
2022-04-11 14:11:01 +00:00
|
|
|
newrelic.agent.record_custom_event(
|
2022-04-12 07:04:57 +00:00
|
|
|
"LoginEvent", {"action": self.action.name, "source": self.source.name}
|
2022-04-11 14:11:01 +00:00
|
|
|
)
|
2022-04-11 08:18:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
class RegisterEvent:
|
|
|
|
class ActionType(EnumE):
|
|
|
|
success = 0
|
2022-04-11 14:11:01 +00:00
|
|
|
failed = 1
|
|
|
|
catpcha_failed = 2
|
|
|
|
email_in_use = 3
|
|
|
|
invalid_email = 4
|
|
|
|
|
|
|
|
class Source(EnumE):
|
|
|
|
web = 0
|
|
|
|
api = 1
|
2022-04-11 08:18:22 +00:00
|
|
|
|
2022-04-11 14:11:01 +00:00
|
|
|
def __init__(self, action: ActionType, source: Source = Source.web):
|
2022-04-11 08:18:22 +00:00
|
|
|
self.action = action
|
2022-04-11 14:11:01 +00:00
|
|
|
self.source = source
|
2022-04-11 08:18:22 +00:00
|
|
|
|
|
|
|
def send(self):
|
2022-04-11 14:11:01 +00:00
|
|
|
newrelic.agent.record_custom_event(
|
2022-04-12 07:04:57 +00:00
|
|
|
"RegisterEvent", {"action": self.action.name, "source": self.source.name}
|
2022-04-11 14:11:01 +00:00
|
|
|
)
|