-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
129 lines (115 loc) · 5.18 KB
/
Copy pathmodels.py
File metadata and controls
129 lines (115 loc) · 5.18 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from flask import jsonify, request
import pymongo
from pymongo import MongoClient
from errorCodes import *
import os
# from app import app
# import sys
# sys.path.append('/Users/anshajgoyal/Documents/GitHub/booksAPI')
# from app import app
# from login import *
# sys.path.pop()
from login import UserVerification
from books import Books
class User:
def __init__(self):
self.client = MongoClient(app.config['MONGO_URI'])
self.UserVerification = UserVerification()
self.Books = Books()
return
def signup(self):
print(request.form)
compulsoryDetails = {
"email": request.json.get('email',None),
# "phone": request.json.get('phone',None),
"fname": request.json.get('fname',None),
"password": request.json.get('password',None),
"gender": request.json.get('gender', None)
}
phoneNumber = request.json.get('phone',None)
compulsoryDetails['phone'] = None if phoneNumber==None else str(phoneNumber)
if not all(compulsoryDetails.values()):
return E13
compulsoryDetails.update({"mname": request.json.get('mname',"None"),
"lname": request.json.get('lname',"None"),
"dob" : request.json.get("dob", "None")
})
print(compulsoryDetails)
if not all(list(map(lambda x: isinstance(x, str), list(compulsoryDetails.values())))):
return E15
if not all([self.UserVerification.phoneNumberValidator(phoneNumber), len(str(phoneNumber))==10], self.UserVerification.genderVerify(details['gender'])):
return E14
if not (compulsoryDetails['dob']!="None" and self.UserVerification.dobVerify(compulsoryDetails['dob'])):
return E22
existing = self.UserVerification.acctExists(compulsoryDetails['email'], phoneNumber)
if existing[0]:
return existing[1]
return self.UserVerification.createAccount(compulsoryDetails)
def otpverify(self):
compulsoryDetails = {
"phone": request.json.get('phone',None),
"sign": request.json.get('signature',None),
"otp": request.json.get('otp',None)
}
if not all(list(map(str, list(compulsoryDetails.values())))):
return E13
if not all([isinstance(compulsoryDetails['sign'],str), isinstance(compulsoryDetails['otp'], str), isinstance(compulsoryDetails['phone'],str)]):
print(compulsoryDetails)
return E15
if not all([self.UserVerification.phoneNumberValidator(compulsoryDetails['phone']), len(str(compulsoryDetails['phone']))==10]):
return E14
if not self.UserVerification.insert_otp_db.find_one({"phone":compulsoryDetails['phone']}):
return E6
return self.UserVerification.verifyOTP(compulsoryDetails)
def login(self):
email = request.json.get('email',None)
phoneNumber = request.json.get('phone',None)
password = request.json.get('password',None)
if not ((email or phoneNumber) and password):
return E13
if isinstance(password, str):
if email and isinstance(email, str):
return self.UserVerification.login(password, email.upper())
elif phoneNumber and isinstance(phoneNumber, str):
return self.UserVerification.login(password, password = password)
else:
return E15
else: return E15
def private(self):
token = request.headers.get('AUTHORIZATION', None)
if not token: return E16
if not (isinstance(token, str)): print(71);return E17
if not self.UserVerification.checkValidJwt(token): print(72);return E17
active = self.UserVerification.checkActiveSession(token)
if not active: return E18
E19.update(active)
return E19
def logout(self, current_user):
return self.UserVerification.deleteSession(current_user)
def insertBook(self):
if not request.json: return E25
get = request.json.get
keys = {str:["bookName" ,"authorNames"] ,int: ["MRP" ,"rental" ,"securityDeposit" ,"timePeriod" ,"qtyAvailable" ],dict :["otherDetails"]}
data = {j: get(j, None) for i in keys for j in keys[i]}
# return data
# print(data.values())
if not all(data.values()): return E13
# locals().update(data)
# print(locals())
# print(bookName)
for i in keys:
# print(i)
if not all(map(lambda x: isinstance(data[x], i), keys[i])):
return E15
return self.Books.insertBook(data)
# if not all(map(lambda x: isinstance(exec(x), str), keys['str']) or map(lambda x: isinstance(exec(x), int), keys['int'])): return E15
# bookName: str,
# authorNames: str,
# bookPriceInMRP: int,
# rentalPrice: int,
# securityDeposit: int,
# timePeriod: int,
# qtyAvailable: int,
# details: dict
if __name__ != "__main__":
from app import app