feat: added tracking events for password reset initiation
This commit is contained in:
committed by
Fatima Sohail
parent
bcf8b38c25
commit
8e7a5f18c7
@@ -24,6 +24,7 @@ from django.views.decorators.debug import sensitive_post_parameters
|
||||
from django.views.decorators.http import require_http_methods
|
||||
from django_ratelimit.decorators import ratelimit
|
||||
from edx_django_utils.monitoring import set_custom_attribute
|
||||
from eventtracking import tracker
|
||||
from openedx_events.learning.data import UserData, UserPersonalData
|
||||
from openedx_events.learning.signals import SESSION_LOGIN_COMPLETED
|
||||
from openedx_filters.learning.filters import StudentLoginRequested
|
||||
@@ -61,6 +62,7 @@ from openedx.features.enterprise_support.api import activate_learner_enterprise,
|
||||
log = logging.getLogger("edx.student")
|
||||
AUDIT_LOG = logging.getLogger("audit")
|
||||
USER_MODEL = get_user_model()
|
||||
PASSWORD_RESET_INITIATED = 'edx.user.passwordreset.initiated'
|
||||
|
||||
|
||||
def _do_third_party_auth(request):
|
||||
@@ -194,6 +196,14 @@ def _enforce_password_policy_compliance(request, user): # lint-amnesty, pylint:
|
||||
LoginFailures.increment_lockout_counter(user)
|
||||
|
||||
AUDIT_LOG.info("Password reset initiated for email %s.", user.email)
|
||||
tracker.emit(
|
||||
PASSWORD_RESET_INITIATED,
|
||||
{
|
||||
"email": user.email,
|
||||
"user_id": user.id,
|
||||
"source": "Policy Compliance",
|
||||
}
|
||||
)
|
||||
send_password_reset_email_for_user(user, request)
|
||||
|
||||
# Prevent the login attempt.
|
||||
|
||||
@@ -52,6 +52,7 @@ from common.djangoapps.util.password_policy_validators import normalize_password
|
||||
POST_EMAIL_KEY = 'openedx.core.djangoapps.util.ratelimit.request_post_email'
|
||||
REAL_IP_KEY = 'openedx.core.djangoapps.util.ratelimit.real_ip'
|
||||
SETTING_CHANGE_INITIATED = 'edx.user.settings.change_initiated'
|
||||
PASSWORD_RESET_INITIATED = 'edx.user.passwordreset.initiated'
|
||||
|
||||
# Maintaining this naming for backwards compatibility.
|
||||
log = logging.getLogger("edx.student")
|
||||
@@ -289,6 +290,14 @@ def password_reset(request):
|
||||
user = request.user
|
||||
# Prefer logged-in user's email
|
||||
email = user.email if user.is_authenticated else request.POST.get('email')
|
||||
tracker.emit(
|
||||
PASSWORD_RESET_INITIATED,
|
||||
{
|
||||
"email": email,
|
||||
"user_id": user.id,
|
||||
"source": "Logistration Page",
|
||||
}
|
||||
)
|
||||
AUDIT_LOG.info("Password reset initiated for email %s.", email)
|
||||
|
||||
if getattr(request, 'limited', False):
|
||||
@@ -608,6 +617,14 @@ def password_change_request_handler(request):
|
||||
# Prefer logged-in user's email
|
||||
email = user.email if user.is_authenticated else request.POST.get('email')
|
||||
AUDIT_LOG.info("Password reset initiated for email %s.", email)
|
||||
tracker.emit(
|
||||
PASSWORD_RESET_INITIATED,
|
||||
{
|
||||
"email": email,
|
||||
"user_id": user.id,
|
||||
"source": "Account API",
|
||||
}
|
||||
)
|
||||
|
||||
if getattr(request, 'limited', False) and not request_from_support_tools:
|
||||
AUDIT_LOG.warning("Password reset rate limit exceeded for email %s.", email)
|
||||
|
||||
Reference in New Issue
Block a user