Created the OAuthTokenObtainPairView, a custom API view that handles the OAuth-based login process.
The view performs the following steps:
OAuth Authentication: Authenticates users using either Google or GitHub OAuth, retrieving the authorization code and exchanging it for an access token.
User Retrieval or Creation: If the user already exists in our system, they are retrieved; if not, a new user is created with the data provided by the OAuth provider.
JWT Token Assignment: Once the user is authenticated, the view assigns them a JWT token for secure access to our platform.
This was implemented by leveraging Django's RefreshToken.for_user() method, which issues the user a new JWT token upon successful OAuth login.
Code References:
OAuthTokenObtainPairView in views.py: Contains the logic for handling Google/GitHub OAuth login, checking for existing users, creating new users as necessary, and assigning JWT tokens.
Task 2: Create a Celery Task to Send a Welcome Email on Successful Registration or Login
Objective:
To configure a Celery task that sends a welcome email notification to the user upon successful registration or login.
Implementation:
Added a new Celery task, send_welcome_email, in tasks.py that sends a welcome email with the user's details.
The task is triggered asynchronously after successful registration or login by calling send_welcome_email.apply_async with the user’s ID as an argument.
Configured the email template to include the user's name and email, making the email more personalized and welcoming.
Set up the Celery task configuration in the settings and ensured that the Celery worker is connected to Redis, allowing for smooth background task processing.
Code References:
send_welcome_email in tasks.py: Contains the logic for sending the welcome email using Django’s send_mail function.
CustomSocialAccountAdapter in adapters.py: This adapter activates users after registration and triggers the send_welcome_email task.
The email configuration and template setup in settings.py ensure that the email is sent from the configured SMTP settings.
Created the OAuthTokenObtainPairView, a custom API view that handles the OAuth-based login process. The view performs the following steps: OAuth Authentication: Authenticates users using either Google or GitHub OAuth, retrieving the authorization code and exchanging it for an access token. User Retrieval or Creation: If the user already exists in our system, they are retrieved; if not, a new user is created with the data provided by the OAuth provider. JWT Token Assignment: Once the user is authenticated, the view assigns them a JWT token for secure access to our platform. This was implemented by leveraging Django's RefreshToken.for_user() method, which issues the user a new JWT token upon successful OAuth login. Code References:
OAuthTokenObtainPairView in views.py: Contains the logic for handling Google/GitHub OAuth login, checking for existing users, creating new users as necessary, and assigning JWT tokens. Task 2: Create a Celery Task to Send a Welcome Email on Successful Registration or Login Objective: To configure a Celery task that sends a welcome email notification to the user upon successful registration or login.
Implementation:
Added a new Celery task, send_welcome_email, in tasks.py that sends a welcome email with the user's details. The task is triggered asynchronously after successful registration or login by calling send_welcome_email.apply_async with the user’s ID as an argument. Configured the email template to include the user's name and email, making the email more personalized and welcoming. Set up the Celery task configuration in the settings and ensured that the Celery worker is connected to Redis, allowing for smooth background task processing. Code References:
send_welcome_email in tasks.py: Contains the logic for sending the welcome email using Django’s send_mail function. CustomSocialAccountAdapter in adapters.py: This adapter activates users after registration and triggers the send_welcome_email task. The email configuration and template setup in settings.py ensure that the email is sent from the configured SMTP settings.