thejagstudio commited on
Commit
c3a619e
·
verified ·
1 Parent(s): 84a8179

Upload 54 files

Browse files
api/__pycache__/views.cpython-39.pyc CHANGED
Binary files a/api/__pycache__/views.cpython-39.pyc and b/api/__pycache__/views.cpython-39.pyc differ
 
authentication/__pycache__/models.cpython-39.pyc CHANGED
Binary files a/authentication/__pycache__/models.cpython-39.pyc and b/authentication/__pycache__/models.cpython-39.pyc differ
 
authentication/__pycache__/views.cpython-39.pyc CHANGED
Binary files a/authentication/__pycache__/views.cpython-39.pyc and b/authentication/__pycache__/views.cpython-39.pyc differ
 
authentication/migrations/0007_userdata_revelid.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Generated by Django 4.2.16 on 2024-11-26 08:54
2
+
3
+ from django.db import migrations, models
4
+
5
+
6
+ class Migration(migrations.Migration):
7
+
8
+ dependencies = [
9
+ ("authentication", "0006_userdata_activatedcoupons"),
10
+ ]
11
+
12
+ operations = [
13
+ migrations.AddField(
14
+ model_name="userdata",
15
+ name="revelId",
16
+ field=models.CharField(default="", max_length=50),
17
+ ),
18
+ ]
authentication/migrations/0008_alter_userdata_pincode.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Generated by Django 4.2.16 on 2024-11-26 10:20
2
+
3
+ from django.db import migrations, models
4
+
5
+
6
+ class Migration(migrations.Migration):
7
+
8
+ dependencies = [
9
+ ("authentication", "0007_userdata_revelid"),
10
+ ]
11
+
12
+ operations = [
13
+ migrations.AlterField(
14
+ model_name="userdata",
15
+ name="pincode",
16
+ field=models.CharField(max_length=10),
17
+ ),
18
+ ]
authentication/migrations/__pycache__/0007_userdata_revelid.cpython-39.pyc ADDED
Binary file (620 Bytes). View file
 
authentication/migrations/__pycache__/0008_alter_userdata_pincode.cpython-39.pyc ADDED
Binary file (606 Bytes). View file
 
authentication/models.py CHANGED
@@ -38,6 +38,7 @@ class Coupon(models.Model):
38
 
39
  class UserData(models.Model):
40
  user = models.ForeignKey(User, on_delete=models.CASCADE)
 
41
  refCode = models.CharField(max_length=50, default="")
42
  phone = models.CharField(max_length=15)
43
  birthDate = models.DateField()
@@ -46,7 +47,7 @@ class UserData(models.Model):
46
  city = models.CharField(max_length=50)
47
  state = models.CharField(max_length=50)
48
  country = models.CharField(max_length=50)
49
- pincode = models.IntegerField()
50
  otp = models.IntegerField(null=True, blank=True)
51
  rewardPoints = models.IntegerField(default=0)
52
  isVerified = models.BooleanField(default=False)
 
38
 
39
  class UserData(models.Model):
40
  user = models.ForeignKey(User, on_delete=models.CASCADE)
41
+ revelId = models.CharField(max_length=50, default="")
42
  refCode = models.CharField(max_length=50, default="")
43
  phone = models.CharField(max_length=15)
44
  birthDate = models.DateField()
 
47
  city = models.CharField(max_length=50)
48
  state = models.CharField(max_length=50)
49
  country = models.CharField(max_length=50)
50
+ pincode = models.CharField(max_length=10)
51
  otp = models.IntegerField(null=True, blank=True)
52
  rewardPoints = models.IntegerField(default=0)
53
  isVerified = models.BooleanField(default=False)
authentication/views.py CHANGED
@@ -10,17 +10,18 @@ from rest_framework_simplejwt.tokens import RefreshToken
10
  from rest_framework.permissions import IsAuthenticated, AllowAny
11
  from django.core.mail import send_mail
12
  import random
 
13
  from django.utils import timezone
14
  from datetime import timedelta
15
  from .models import UserData
 
16
 
17
  # In-memory storage for OTPs (use a persistent storage in production)
18
  OTP_STORAGE = {}
19
 
20
 
21
  class RegisterView(APIView):
22
- authentication_classes = ()
23
- permission_classes = () # Allow any
24
 
25
  def post(self, request):
26
  try:
@@ -29,7 +30,17 @@ class RegisterView(APIView):
29
  password = data.get('password')
30
  first_name = data.get('first_name')
31
  last_name = data.get('last_name')
32
-
 
 
 
 
 
 
 
 
 
 
33
  if User.objects.filter(email=email).exists():
34
  return JsonResponse({'error': 'Email already exists'}, status=400)
35
 
@@ -41,6 +52,21 @@ class RegisterView(APIView):
41
  last_name=last_name
42
  )
43
  user.save()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  otp = random.randint(100000, 999999)
45
  OTP_STORAGE[email] = {
46
  'otp': otp,
@@ -48,15 +74,105 @@ class RegisterView(APIView):
48
  }
49
  print(otp)
50
  # Send OTP via email
51
- send_mail(
52
- 'Password Reset OTP',
53
- f'Your OTP for password reset is {otp}',
54
- '[email protected]', # Replace with your email
55
- [email],
56
- fail_silently=False,
57
- )
58
- return JsonResponse({'message': 'User registered successfully'}, status=201)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  except Exception as e:
 
60
  return JsonResponse({'error': str(e)}, status=400)
61
 
62
 
@@ -73,7 +189,7 @@ class LoginView(APIView):
73
  if user is not None:
74
  refresh = RefreshToken.for_user(user)
75
  userDataObj = UserData.objects.get(user=user)
76
- userData ={}
77
  userData['email'] = user.email
78
  userData['first_name'] = user.first_name
79
  userData['last_name'] = user.last_name
@@ -99,15 +215,19 @@ class LoginView(APIView):
99
  except Exception as e:
100
  print(e)
101
  return JsonResponse({'error': str(e)}, status=400)
102
-
 
103
  class UserDetailView(APIView):
104
  permission_classes = [IsAuthenticated]
105
 
106
  def get(self, request):
107
  user = request.user
 
108
  userDataObj = UserData.objects.get(user=user)
109
- userData ={}
110
  userData['email'] = user.email
 
 
111
  userData['first_name'] = user.first_name
112
  userData['last_name'] = user.last_name
113
  userData["phone"] = userDataObj.phone
@@ -125,7 +245,51 @@ class UserDetailView(APIView):
125
  userData["isBlocked"] = userDataObj.isBlocked
126
  userData["isDeleted"] = userDataObj.isDeleted
127
  return JsonResponse(userData, status=200)
128
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
 
130
  class LogoutView(APIView):
131
  permission_classes = [IsAuthenticated]
@@ -145,14 +309,13 @@ class LogoutView(APIView):
145
  'status': 'success',
146
  'message': 'Successfully logged out'
147
  })
148
- except :
149
  return JsonResponse({
150
  "error": "Invalid token",
151
  "status": "error"
152
  }, status=400)
153
 
154
 
155
-
156
  class RequestPasswordResetView(APIView):
157
  authentication_classes = ()
158
  permission_classes = () # Allow any
@@ -265,6 +428,7 @@ class ResetPasswordView(APIView):
265
  except Exception as e:
266
  return JsonResponse({'error': str(e)}, status=400)
267
 
 
268
  class refreshTokenView(APIView):
269
  def post(self, request):
270
  try:
@@ -275,4 +439,3 @@ class refreshTokenView(APIView):
275
  return JsonResponse({'access': access}, status=200)
276
  except Exception as e:
277
  return JsonResponse({'error': str(e)}, status=400)
278
-
 
10
  from rest_framework.permissions import IsAuthenticated, AllowAny
11
  from django.core.mail import send_mail
12
  import random
13
+ import requests
14
  from django.utils import timezone
15
  from datetime import timedelta
16
  from .models import UserData
17
+ import uuid
18
 
19
  # In-memory storage for OTPs (use a persistent storage in production)
20
  OTP_STORAGE = {}
21
 
22
 
23
  class RegisterView(APIView):
24
+ permission_classes = [AllowAny]
 
25
 
26
  def post(self, request):
27
  try:
 
30
  password = data.get('password')
31
  first_name = data.get('first_name')
32
  last_name = data.get('last_name')
33
+ phone = data.get('phone')
34
+ birthDate = data.get('birthDate')
35
+ gender = data.get('gender', 'male')
36
+ streetName = data.get('streetName')
37
+ city = data.get('city')
38
+ state = data.get('state')
39
+ country = data.get('country')
40
+ pincode = data.get('pincode')
41
+ getUpdates = data.get('getUpdates', False)
42
+ birthDate = birthDate.split('T')[0]
43
+
44
  if User.objects.filter(email=email).exists():
45
  return JsonResponse({'error': 'Email already exists'}, status=400)
46
 
 
52
  last_name=last_name
53
  )
54
  user.save()
55
+
56
+ userDataObj = UserData.objects.create(
57
+ user=user,
58
+ phone=phone,
59
+ refCode=phone,
60
+ birthDate=birthDate,
61
+ gender=gender,
62
+ streetName=streetName,
63
+ city=city,
64
+ state=state,
65
+ country=country,
66
+ pincode=pincode,
67
+ isSubscribed=getUpdates
68
+ )
69
+
70
  otp = random.randint(100000, 999999)
71
  OTP_STORAGE[email] = {
72
  'otp': otp,
 
74
  }
75
  print(otp)
76
  # Send OTP via email
77
+ # send_mail(
78
+ # 'Password Reset OTP',
79
+ # f'Your OTP for password reset is {otp}',
80
+ # '[email protected]', # Replace with your email
81
+ # [email],
82
+ # fail_silently=False,
83
+ # )
84
+
85
+ # Add user to Revel system
86
+ revel_payload = json.dumps({
87
+ "accept_checks": False,
88
+ "account_balance": None,
89
+ "account_limit": None,
90
+ "active": True,
91
+ "address": streetName,
92
+ "birth_date": birthDate,
93
+ "cc_exp": "03/22",
94
+ "cc_first_name": first_name,
95
+ "cc_last_name": last_name,
96
+ "cc_last_4_digits": "1111",
97
+ "city": city,
98
+ "company_name": "B-Company",
99
+ # "contract_expiration": "2019-05-16T00:00:00",
100
+ "created_by": "/enterprise/User/9393/",
101
+ "created_date": timezone.now().isoformat(),
102
+ "customer_groups": [],
103
+ "deleted": False,
104
+ "discount": 0,
105
+ "email": email,
106
+ "email_opt_in": getUpdates,
107
+ # "exp_date": "1919-05-16T00:00:00",
108
+ "expensify_account": f'{{"{email}":["193"]}}',
109
+ "first_name": first_name,
110
+ "gender": 0 if gender.lower() == 'male' else 1,
111
+ "gift_card_numbers": [],
112
+ "is_visitor": False,
113
+ "last_name": last_name,
114
+ "lic_number": "EAK173",
115
+ "loyalty_number": None,
116
+ "loyalty_ref_id": "",
117
+ "notes": "New Customer",
118
+ "ok_to_email": False,
119
+ "past_due": 0,
120
+ "phone_number": phone,
121
+ "phone_opt_in": getUpdates,
122
+ "pin": "",
123
+ "post_opt_in": False,
124
+ "ref_number": "1731-147709",
125
+ "reward_card_numbers": [],
126
+ "source": None,
127
+ "state": state,
128
+ "tax_exempt": False,
129
+ # "tax_location": "CA Orange County",
130
+ # "third_party_id": "1731147709",
131
+ "title": "Mr" if gender == "male" else "Ms",
132
+ "total_purchases": 0,
133
+ "total_visits": 0,
134
+ "track_as_company": True,
135
+ "type": 1,
136
+ "updated_by": "/enterprise/User/9393/",
137
+ "updated_date": timezone.now().isoformat(),
138
+ "uuid": uuid.uuid4().hex,
139
+ "vehicles": [],
140
+ "version_date": timezone.now().isoformat(),
141
+ "zipcode": pincode
142
+ })
143
+ revel_headers = {
144
+ 'content-type': 'application/json',
145
+ 'API-AUTHENTICATION': 'fab57498544244e38bfc2741880f8d61:ed9628295b0642e1b38308795c9cdadd58012df4ceb84a3b9d441c017a1eeac0'
146
+ }
147
+ revel_response = requests.post("https://101smokeshop-uat.revelup.com/resources/Customer/", headers=revel_headers, data=revel_payload)
148
+ # print(revel_response.json())
149
+
150
+ userDataObj.revelId = revel_response.json()['id']
151
+ userDataObj.save()
152
+ refresh = RefreshToken.for_user(user)
153
+ userData = {}
154
+ userData['email'] = user.email
155
+ userData['first_name'] = user.first_name
156
+ userData['last_name'] = user.last_name
157
+ userData['access'] = str(refresh.access_token)
158
+ userData['refresh'] = str(refresh)
159
+ userData["phone"] = userDataObj.phone
160
+ userData["refCode"] = userDataObj.refCode
161
+ userData["birthDate"] = userDataObj.birthDate
162
+ userData["gender"] = userDataObj.gender
163
+ userData["streetName"] = userDataObj.streetName
164
+ userData["city"] = userDataObj.city
165
+ userData["state"] = userDataObj.state
166
+ userData["country"] = userDataObj.country
167
+ userData["pincode"] = userDataObj.pincode
168
+ userData["rewardPoints"] = userDataObj.rewardPoints
169
+ userData["isVerified"] = userDataObj.isVerified
170
+ userData["isSubscribed"] = userDataObj.isSubscribed
171
+ userData["isBlocked"] = userDataObj.isBlocked
172
+ userData["isDeleted"] = userDataObj.isDeleted
173
+ return JsonResponse(userData, status=200)
174
  except Exception as e:
175
+ print(e)
176
  return JsonResponse({'error': str(e)}, status=400)
177
 
178
 
 
189
  if user is not None:
190
  refresh = RefreshToken.for_user(user)
191
  userDataObj = UserData.objects.get(user=user)
192
+ userData = {}
193
  userData['email'] = user.email
194
  userData['first_name'] = user.first_name
195
  userData['last_name'] = user.last_name
 
215
  except Exception as e:
216
  print(e)
217
  return JsonResponse({'error': str(e)}, status=400)
218
+
219
+
220
  class UserDetailView(APIView):
221
  permission_classes = [IsAuthenticated]
222
 
223
  def get(self, request):
224
  user = request.user
225
+ refresh = RefreshToken.for_user(user)
226
  userDataObj = UserData.objects.get(user=user)
227
+ userData = {}
228
  userData['email'] = user.email
229
+ userData['access'] = str(refresh.access_token)
230
+ userData['refresh'] = str(refresh)
231
  userData['first_name'] = user.first_name
232
  userData['last_name'] = user.last_name
233
  userData["phone"] = userDataObj.phone
 
245
  userData["isBlocked"] = userDataObj.isBlocked
246
  userData["isDeleted"] = userDataObj.isDeleted
247
  return JsonResponse(userData, status=200)
248
+
249
+ def post(self, request):
250
+ try:
251
+ user = request.user
252
+ userDataObj = UserData.objects.get(user=user)
253
+ data = json.loads(request.body)
254
+ user.email = data.get('email', user.email)
255
+ user.first_name = data.get('first_name', user.first_name)
256
+ user.last_name = data.get('last_name', user.last_name)
257
+ userDataObj.phone = data.get('phone', userDataObj.phone)
258
+ userDataObj.refCode = data.get('phone', userDataObj.phone)
259
+ userDataObj.birthDate = data.get('birthDate', userDataObj.birthDate).split('T')[0]
260
+ userDataObj.gender = data.get('gender', userDataObj.gender)
261
+ userDataObj.streetName = data.get('streetName', userDataObj.streetName)
262
+ userDataObj.city = data.get('city', userDataObj.city)
263
+ userDataObj.state = data.get('state', userDataObj.state)
264
+ userDataObj.country = data.get('country', userDataObj.country)
265
+ userDataObj.pincode = data.get('pincode', userDataObj.pincode)
266
+ user.save()
267
+ userDataObj.save()
268
+ userData = {}
269
+ refresh = RefreshToken.for_user(user)
270
+ userData['email'] = user.email
271
+ userData['access'] = str(refresh.access_token)
272
+ userData['refresh'] = str(refresh)
273
+ userData['first_name'] = user.first_name
274
+ userData['last_name'] = user.last_name
275
+ userData["phone"] = userDataObj.phone
276
+ userData["refCode"] = userDataObj.refCode
277
+ userData["birthDate"] = userDataObj.birthDate
278
+ userData["gender"] = userDataObj.gender
279
+ userData["streetName"] = userDataObj.streetName
280
+ userData["city"] = userDataObj.city
281
+ userData["state"] = userDataObj.state
282
+ userData["country"] = userDataObj.country
283
+ userData["pincode"] = userDataObj.pincode
284
+ userData["rewardPoints"] = userDataObj.rewardPoints
285
+ userData["isVerified"] = userDataObj.isVerified
286
+ userData["isSubscribed"] = userDataObj.isSubscribed
287
+ userData["isBlocked"] = userDataObj.isBlocked
288
+ userData["isDeleted"] = userDataObj.isDeleted
289
+ return JsonResponse({'message': 'User data updated successfully', "data": userData}, status=200)
290
+ except Exception as e:
291
+ return JsonResponse({'error': str(e)}, status=400)
292
+
293
 
294
  class LogoutView(APIView):
295
  permission_classes = [IsAuthenticated]
 
309
  'status': 'success',
310
  'message': 'Successfully logged out'
311
  })
312
+ except:
313
  return JsonResponse({
314
  "error": "Invalid token",
315
  "status": "error"
316
  }, status=400)
317
 
318
 
 
319
  class RequestPasswordResetView(APIView):
320
  authentication_classes = ()
321
  permission_classes = () # Allow any
 
428
  except Exception as e:
429
  return JsonResponse({'error': str(e)}, status=400)
430
 
431
+
432
  class refreshTokenView(APIView):
433
  def post(self, request):
434
  try:
 
439
  return JsonResponse({'access': access}, status=200)
440
  except Exception as e:
441
  return JsonResponse({'error': str(e)}, status=400)
 
oneOone/__pycache__/settings.cpython-39.pyc CHANGED
Binary files a/oneOone/__pycache__/settings.cpython-39.pyc and b/oneOone/__pycache__/settings.cpython-39.pyc differ
 
oneOone/settings.py CHANGED
@@ -166,7 +166,7 @@ REST_FRAMEWORK = {
166
 
167
 
168
  SIMPLE_JWT = {
169
- 'ACCESS_TOKEN_LIFETIME': timedelta(minutes=60),
170
  'REFRESH_TOKEN_LIFETIME': timedelta(days=60),
171
  'ROTATE_REFRESH_TOKENS': True,
172
  'BLACKLIST_AFTER_ROTATION': True,
 
166
 
167
 
168
  SIMPLE_JWT = {
169
+ 'ACCESS_TOKEN_LIFETIME': timedelta(minutes=720),
170
  'REFRESH_TOKEN_LIFETIME': timedelta(days=60),
171
  'ROTATE_REFRESH_TOKENS': True,
172
  'BLACKLIST_AFTER_ROTATION': True,