-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandlers.py
More file actions
62 lines (45 loc) · 1.5 KB
/
Copy pathhandlers.py
File metadata and controls
62 lines (45 loc) · 1.5 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
import json
users = {}
def home():
return "200 OK", "text/plain", "Hello Dharampal"
def about():
return "200 OK", "text/plain", "About Your Mom"
def api():
data = {
"name" : "Dharampal the great",
"role" : "Tuzya ichi"
}
return "200 OK", "application/json", json.dumps(data)
def login(body):
data = json.loads(body)
username = data.get("username")
password = data.get("password")
if username in users and users[username] == password:
return "200 OK", "application/json", json.dumps({
"message": "Login success"
})
else:
return "401 Unauthorized", "application/json", json.dumps({
"message": "Invalid credentials"
})
def signup(body):
# print("SIGNUP bodyyy yadddyy yadddyyy:" , repr(body))
data = json.loads(body)
username = data.get("username")
password = data.get("password")
# print("STEP 3 username:", username)
# print("STEP 4 password:", password)
if not username and password:
return "400 Bad Request", "application/json", json.dumps({
"message": "Missing username or password"
})
if username in users:
return "409 confilct", "application/json", json.dumps({
"message": "User already exists"
})
users[username] = password
return "201 created", "application/json", json.dumps({
"message": "User created"
})
def not_found():
return "404 You can't see me", "text/plain", "404 Not Found"