Added otp verification
This commit is contained in:
parent
1faf46cc1b
commit
fda5118c39
1 changed files with 34 additions and 0 deletions
|
@ -1,4 +1,8 @@
|
|||
import logging
|
||||
import os
|
||||
import pyotp
|
||||
import requests
|
||||
import dotenv
|
||||
from django.contrib.sites.models import Site
|
||||
|
||||
from datacenterlight.tasks import create_vm_task
|
||||
|
@ -11,6 +15,17 @@ from .models import VMPricing, VMTemplate
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
PROJECT_DIR = os.path.abspath(
|
||||
os.path.join(os.path.dirname(__file__)),
|
||||
)
|
||||
|
||||
# load .env file
|
||||
dotenv.read_dotenv("{0}/.env".format(PROJECT_DIR))
|
||||
|
||||
|
||||
def env(env_name):
|
||||
return os.environ.get(env_name)
|
||||
|
||||
|
||||
def get_cms_integration(name):
|
||||
current_site = Site.objects.get_current()
|
||||
|
@ -100,3 +115,22 @@ def clear_all_session_vars(request):
|
|||
'generic_payment_details', 'product_id']:
|
||||
if session_var in request.session:
|
||||
del request.session[session_var]
|
||||
|
||||
|
||||
def check_otp(name, realm, token):
|
||||
data = {
|
||||
"auth_name": env('AUTH_NAME'),
|
||||
"auth_token": pyotp.TOTP(env('AUTH_SEED')).now(),
|
||||
"auth_realm": env('AUTH_REALM'),
|
||||
"name": name,
|
||||
"realm": realm,
|
||||
"token": token
|
||||
}
|
||||
response = requests.post(
|
||||
"https://{OTP_SERVER}{OTP_VERIFY_ENDPOINT}".format(
|
||||
OTP_SERVER=env('OTP_SERVER'),
|
||||
OTP_VERIFY_ENDPOINT=env('OTP_VERIFY_ENDPOINT')
|
||||
),
|
||||
data=data
|
||||
)
|
||||
return response.status_code
|
||||
|
|
Loading…
Reference in a new issue