forked from AndresQ9/knowgap-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_demo_ssl_bypass.py
More file actions
189 lines (158 loc) Β· 6.95 KB
/
create_demo_ssl_bypass.py
File metadata and controls
189 lines (158 loc) Β· 6.95 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env python3
"""
Create Demo Instructor Account via API (SSL Bypass)
==================================================
This script creates the demo instructor account by calling the backend API directly,
bypassing SSL certificate verification for local development.
Usage:
python3 create_demo_ssl_bypass.py
"""
import asyncio
import aiohttp
import ssl
import certifi
import json
# Demo account credentials
DEMO_INSTRUCTOR_EMAIL = "demo.instructor@ucf.edu"
DEMO_INSTRUCTOR_PASSWORD = "AchieveUp2024!"
DEMO_CANVAS_TOKEN = "1234567890abcdef" * 4 # 64-character demo token
# Backend API URL
BACKEND_URL = "https://gen-ai-prime-3ddeabb35bd7.herokuapp.com"
async def create_demo_instructor_via_api():
"""Create the demo instructor account via the backend API."""
print("π― Creating Demo Instructor Account via API")
print("=" * 55)
try:
# Prepare signup data
signup_data = {
"name": "Dr. Jane Smith",
"email": DEMO_INSTRUCTOR_EMAIL,
"password": DEMO_INSTRUCTOR_PASSWORD,
"canvasApiToken": DEMO_CANVAS_TOKEN,
"canvasTokenType": "instructor"
}
print("π Connecting to backend API...")
print(f" URL: {BACKEND_URL}")
print(" β οΈ SSL verification disabled for local development")
print()
# Create SSL context that bypasses certificate verification
ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
# Create connector with SSL bypass
connector = aiohttp.TCPConnector(ssl=ssl_context)
# Make API call to create instructor account
async with aiohttp.ClientSession(connector=connector) as session:
url = f"{BACKEND_URL}/auth/signup"
headers = {
'Content-Type': 'application/json'
}
print("π Creating demo instructor account...")
async with session.post(url, json=signup_data, headers=headers) as response:
response_text = await response.text()
print(f" Status Code: {response.status}")
print(f" Response: {response_text}")
print()
if response.status == 201:
print("β
Demo instructor created successfully via API!")
print(f" π§ Email: {DEMO_INSTRUCTOR_EMAIL}")
print(f" π Password: {DEMO_INSTRUCTOR_PASSWORD}")
print(f" π― Role: Instructor")
print()
print("π Ready to use with frontend:")
print(" Frontend: https://achieveup.netlify.app")
print(" Backend: https://gen-ai-prime-3ddeabb35bd7.herokuapp.com")
return True
elif response.status == 409:
print("βΉοΈ Demo instructor already exists in database")
print(f" π§ Email: {DEMO_INSTRUCTOR_EMAIL}")
print(" You can now log in with the demo credentials")
return True
else:
print(f"β Failed to create demo instructor: {response.status}")
print(f" Response: {response_text}")
return False
except Exception as e:
print(f"β Error creating demo instructor via API: {str(e)}")
print()
print("π§ TROUBLESHOOTING:")
print("1. Check if the backend is running and accessible")
print("2. Verify the backend URL is correct")
print("3. Check network connectivity")
print()
import traceback
traceback.print_exc()
return False
async def test_demo_login():
"""Test the demo account login to verify it works."""
print("π§ͺ Testing Demo Account Login")
print("=" * 35)
try:
# Prepare login data
login_data = {
"email": DEMO_INSTRUCTOR_EMAIL,
"password": DEMO_INSTRUCTOR_PASSWORD
}
print("π Testing login with demo credentials...")
# Create SSL context that bypasses certificate verification
ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
# Create connector with SSL bypass
connector = aiohttp.TCPConnector(ssl=ssl_context)
async with aiohttp.ClientSession(connector=connector) as session:
url = f"{BACKEND_URL}/auth/login"
headers = {
'Content-Type': 'application/json'
}
async with session.post(url, json=login_data, headers=headers) as response:
response_text = await response.text()
print(f" Status Code: {response.status}")
print(f" Response: {response_text}")
print()
if response.status == 200:
print("β
Demo account login successful!")
print(" The demo account is working correctly")
return True
else:
print(f"β Demo account login failed: {response.status}")
print(f" Response: {response_text}")
return False
except Exception as e:
print(f"β Error testing demo login: {str(e)}")
return False
async def main():
"""Main function."""
print("π― AchieveUp Demo Account Creator (SSL Bypass Version)")
print("=" * 60)
print()
print("β οΈ SSL certificate verification is disabled for local development")
print(" This is safe for creating demo accounts.")
print()
# Create demo instructor via API
success = await create_demo_instructor_via_api()
if success:
print()
print("π Demo account creation complete!")
print("=" * 50)
# Test the login
print("Testing login functionality...")
login_success = await test_demo_login()
if login_success:
print()
print("π― DEMO ACCOUNT READY!")
print("=" * 25)
print("You can now log in to the frontend using:")
print(f" Email: {DEMO_INSTRUCTOR_EMAIL}")
print(f" Password: {DEMO_INSTRUCTOR_PASSWORD}")
print()
print("The demo account has full instructor permissions")
print("and will work with all AchieveUp features.")
else:
print()
print("β οΈ Demo account created but login test failed.")
print(" Please check the backend logs for more details.")
else:
print("β Failed to create demo account. Check the error messages above.")
if __name__ == "__main__":
asyncio.run(main())