added recaptcha verification (#79)

This commit is contained in:
karthik mv 2022-04-10 23:12:02 +05:30 committed by GitHub
parent 90b2a56819
commit 5450273a67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 2 deletions

View File

@ -16,14 +16,15 @@ logger = logging.getLogger('db')
IS_COMPENSATION_DETAILS_PDF, IS_COMPENSATION_DETAILS_PDF,
ALLOWED_BRANCH, SELECTION_PROCEDURE_ROUNDS, SELECTION_PROCEDURE_DETAILS, IS_SELECTION_PROCEDURE_DETAILS_PDF, ALLOWED_BRANCH, SELECTION_PROCEDURE_ROUNDS, SELECTION_PROCEDURE_DETAILS, IS_SELECTION_PROCEDURE_DETAILS_PDF,
TENTATIVE_DATE_OF_JOINING, TENTATIVE_DATE_OF_JOINING,
TENTATIVE_NO_OF_OFFERS, OTHER_REQUIREMENTS TENTATIVE_NO_OF_OFFERS, OTHER_REQUIREMENTS, RECAPTCHA_VALUE
]) ])
def addPlacement(request): def addPlacement(request):
try: try:
data = request.data data = request.data
files = request.FILES files = request.FILES
opening = Placement() opening = Placement()
if not verify_recaptcha(data[RECAPTCHA_VALUE]):
raise Exception("Recaptcha Failed")
opening.id = generateRandomString() opening.id = generateRandomString()
# Add a company details in the opening # Add a company details in the opening
opening.company_name = data[COMPANY_NAME] opening.company_name = data[COMPANY_NAME]

View File

@ -117,6 +117,7 @@ OTHER_REQUIREMENTS = 'other_requirements'
DEADLINE_DATETIME = 'deadline_datetime' DEADLINE_DATETIME = 'deadline_datetime'
OFFER_ACCEPTED = 'offer_accepted' OFFER_ACCEPTED = 'offer_accepted'
EMAIL_VERIFIED = 'email_verified' EMAIL_VERIFIED = 'email_verified'
RECAPTCHA_VALUE = 'recaptchakey'
STUDENT_LIST = "student_list" STUDENT_LIST = "student_list"
STUDENT_ID = "student_id" STUDENT_ID = "student_id"

View File

@ -19,6 +19,7 @@ from google.auth.transport import requests
from google.oauth2 import id_token from google.oauth2 import id_token
from rest_framework import status from rest_framework import status
from rest_framework.response import Response from rest_framework.response import Response
import requests as rq
from .constants import * from .constants import *
from .models import User, PrePlacementOffer, PlacementApplication from .models import User, PrePlacementOffer, PlacementApplication
@ -233,3 +234,18 @@ def generateOneTimeVerificationLink(email, opening_id, opening_type):
print(sys.exc_info()) print(sys.exc_info())
logger.warning("Utils - generateOneTimeVerificationLink: " + str(sys.exc_info())) logger.warning("Utils - generateOneTimeVerificationLink: " + str(sys.exc_info()))
return False, "_" return False, "_"
def verify_recaptcha(request):
try:
data = {
'secret': settings.RECAPTCHA_SECRET_KEY,
'response': request
}
r = rq.post('https://www.google.com/recaptcha/api/siteverify', data=data)
result = r.json()
# logger.info("Recaptcha Response: " + str(result)+"request: "+str(data))
return result['success']
except:
print(sys.exc_info())
logger.warning("Utils - verify_recaptcha: " + str(sys.exc_info()))
return False, "_"

View File

@ -161,6 +161,8 @@ EMAIL_PORT = 587
EMAIL_HOST_USER = os.environ.get("EMAIL") # 'email here' EMAIL_HOST_USER = os.environ.get("EMAIL") # 'email here'
EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_PASSWORD") # 'password here' EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_PASSWORD") # 'password here'
RECAPTCHA_SECRET_KEY = os.environ.get("RECAPTCHA_SECRET_KEY")
LOGGING = { LOGGING = {
'version': 1, 'version': 1,
'disable_existing_loggers': False, 'disable_existing_loggers': False,

View File

@ -9,3 +9,4 @@ DB_USER=postgres
DB_PASSWORD=root DB_PASSWORD=root
DB_HOST=localhost DB_HOST=localhost
DB_PORT=5432 DB_PORT=5432
RECAPTCHA_SECRET_KEY=6LdXXj4fAAAAADRZvwwsznKPEI-StyN6s_4glHLj