-
Notifications
You must be signed in to change notification settings - Fork 0
/
endpoint.py
120 lines (97 loc) · 3.93 KB
/
endpoint.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
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
import json
import tkinter as tk
from tkinter import messagebox
from zeep import Client
from zeep.exceptions import Fault
from zeep.helpers import serialize_object
# WSDL service URL
wsdl_url = 'https://dev.cpims.net/IPRSServerwcf?wsdl'
class App:
def __init__(self, root):
self.root = root
self.root.title("Login")
# Username input
tk.Label(root, text="Username").pack()
self.username_entry = tk.Entry(root)
self.username_entry.pack()
# Password input
tk.Label(root, text="Password").pack()
self.password_entry = tk.Entry(root, show="*")
self.password_entry.pack()
# Login button
self.login_button = tk.Button(root, text="Login", command=self.login)
self.login_button.pack()
# ID number input (hidden initially)
tk.Label(root, text="ID Number").pack()
self.id_entry = tk.Entry(root)
self.id_entry.pack()
self.id_entry.pack_forget() # Hide ID entry
# Fetch data button (hidden initially)
self.fetch_button = tk.Button(root, text="Fetch Data", command=self.fetch_data)
self.fetch_button.pack()
self.fetch_button.pack_forget() # Hide fetch button
# Initialize client
self.client = None
self.session_token = None
def check_wsdl_connection(self):
try:
self.client = Client(wsdl=wsdl_url)
print("Connection to WSDL service successful!")
except Exception as e:
messagebox.showerror("Connection Error", f"Failed to connect: {e}")
def create_login_payload(self, username, password):
return {
'log': username,
'pass': password
}
def perform_login(self):
username = self.username_entry.get()
password = self.password_entry.get()
login_payload = self.create_login_payload(username, password)
try:
response = self.client.service.Login(**login_payload)
print("Raw response:", response) # Debugging line
response_dict = serialize_object(response)
if response_dict and response_dict.get('LoginSuccess', False):
print("Login successful!")
self.session_token = response_dict.get('SessionToken')
self.show_id_entry()
else:
messagebox.showerror("Login Failed", "Invalid credentials, please try again.")
except Fault as fault:
messagebox.showerror("SOAP Fault", str(fault))
except Exception as e:
messagebox.showerror("Error", str(e))
def show_id_entry(self):
self.id_entry.pack() # Show ID entry
self.fetch_button.pack() # Show fetch button
self.login_button.pack_forget() # Hide login button
def fetch_data(self):
id_number = self.id_entry.get()
input_payload = {
'id_number': id_number,
'session_token': self.session_token
}
try:
response = self.client.service.GetDataByIdCard(**input_payload)
print("Raw response:", response) # Debugging line
response_dict = serialize_object(response)
if not response_dict.get('ErrorOccurred', True):
print("Person's Data Retrieved Successfully:")
print(json.dumps(response_dict, indent=4))
messagebox.showinfo("Data Retrieved", json.dumps(response_dict, indent=4))
else:
messagebox.showerror("Error", response_dict.get('ErrorMessage', 'Unknown error'))
except Fault as fault:
messagebox.showerror("SOAP Fault", str(fault))
except Exception as e:
messagebox.showerror("Error", str(e))
def login(self):
self.check_wsdl_connection()
if self.client:
self.perform_login()
# Run the application
if __name__ == "__main__":
root = tk.Tk()
app = App(root)
root.mainloop()