Skip to content

Commit

Permalink
feat: Add events constants #47
Browse files Browse the repository at this point in the history
Adds events constants and updates readme examples to use them.

Fixes #20
  • Loading branch information
joladev authored Jan 9, 2019
1 parent deb1ccb commit 85b0b3a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/build
.coverage
/htmlcov
.vscode/
6 changes: 4 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ Here is a simple example of track event.
.. code:: python
from castle.client import Client
from castle import events
castle = Client.from_request(request)
castle.track({
'event': '$login.succeeded',
'event': events.LOGIN_SUCCEEDED,
'user_id': 'user_id'
})
Expand All @@ -80,10 +81,11 @@ background worker you can generate data for a worker:
.. code:: python
from castle.client import Client
from castle import events
context = Client.to_context(request)
options = Client.to_options({
'event': '$login.succeeded',
'event': events.LOGIN_SUCCEEDED,
'user_id': user.id,
'properties': {
'key': 'value'
Expand Down
37 changes: 37 additions & 0 deletions castle/events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Record when a user succesfully logs in.
LOGIN_SUCCEEDED = '$login.succeeded'
# Record when a user failed to log in.
LOGIN_FAILED = '$login.failed'
# Record when a user logs out.
LOGOUT_SUCCEEDED = '$logout.succeeded'
# Record when a user updated their profile (including password, email, phone, etc).
PROFILE_UPDATE_SUCCEEDED = '$profile_update.succeeded'
# Record errors when updating profile.
PROFILE_UPDATE_FAILED = '$profile_update.failed'
# Capture account creation, both when a user signs up as well as when created manually
# by an administrator.
REGISTRATION_SUCCEEDED = '$registration.succeeded'
# Record when an account failed to be created.
REGISTRATION_FAILED = '$registration.failed'
# The user completed all of the steps in the password reset process and the password was
# successfully reset.Password resets do not required knowledge of the current password.
PASSWORD_RESET_SUCCEEDED = '$password_reset.succeeded'
# Use to record when a user failed to reset their password.
PASSWORD_RESET_FAILED = '$password_reset.failed'
# The user successfully requested a password reset.
PASSWORD_RESET_REQUEST_SUCCCEEDED = '$password_reset_request.succeeded'
# The user failed to request a password reset.
PASSWORD_RESET_REQUEST_FAILED = '$password_reset_request.failed'
# User account has been reset.
INCIDENT_MITIGATED = '$incident.mitigated'
# User confirmed malicious activity.
REVIEW_ESCALATED = '$review.escalated'
# User confirmed safe activity.
REVIEW_RESOLVED = '$review.resolved'
# Record when a user is prompted with additional verification, such as two-factor
# authentication or a captcha.
CHALLENGE_REQUESTED = '$challenge.requested'
# Record when additional verification was successful.
CHALLENGE_SUCCEEDED = '$challenge.succeeded'
# Record when additional verification failed.
CHALLENGE_FAILED = '$challenge.failed'

0 comments on commit 85b0b3a

Please sign in to comment.