-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateOTP.py
51 lines (45 loc) · 1.34 KB
/
generateOTP.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import json
import boto3
import random
import time
db = boto3.resource('dynamodb')
dbTable = db.Table('OTP')
timer = 180
def lambda_handler(event,context):
MailID = event['queryStringParameters']['MailID']
users = []
OTP_Verified = db.Table('OTP_Table')
response = OTP_Verified.get_item(
Key={
'MailID':MailID
})
try:
users.extend(response['Item'])
length = len(users)
if length>0:
return {
'statusCode': 200,
'headers': {
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'OPTIONS,POST,GET'
},
'body':json.dumps('User Already Verified')}
except KeyError:
pass
otp = random.randint(100000,999999)
entry = {
'MailID':MailID,
'otp':otp,
'Verified':False,
'ExpiryTime':int(time.time()) + timer
}
response = dbTable.put_item(Item=entry)
return {
'statusCode': 200,
'headers': {
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'OPTIONS,POST,GET'
},
'body':json.dumps( "A verification code has been sent top " + MailID)}