-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patholdclass.py
More file actions
56 lines (51 loc) · 2.09 KB
/
Copy patholdclass.py
File metadata and controls
56 lines (51 loc) · 2.09 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
from typing import Dict
import sqlite3
import ControllerException
from AppError import *
class VehicleClass:
jsonSchema = {
"type" : "byte",
"properties" : {
"VID" : {"type" : "string"},
"request" : {"type" : "string"}
}
}
latest_response = None
UID = None
def __init__(self, conn: sqlite3.Connection):
self.sqlConn = conn
def storeVID(self, input):
self.VID = input["VID"]
self.requestType = input["request"]
self.bodyRequest = input["body"]
def getMember(self):
#check on sql to retreive both uid and create new authkey
#then return the authkey to application
sqlCursor = self.sqlConn.cursor()
sqlCursor.execute("SELECT UIDMember FROM TRGIDMember WHERE VIDLease=:vehicle",{"vehicle": self.VID})
result = sqlCursor.fetchall()
if result is None:
raise UserNotFound
else:
self.UID = result[0]
self.latest_response = "Can't find UIDMember for selected VIDLease"
def getOwner(self):
sqlCursor = self.sqlConn.cursor()
sqlCursor.execute("SELECT UIDMember FROM TRGIDMember WHERE VIDLease=:vehicle",{"vehicle": self.VID})
result = sqlCursor.fetchone()
if result is None:
raise UserNotFound
else:
self.UID = result[0]
self.latest_response = "Can't find UIDMember for selected VIDLease"
def postRequestHandler(self):
#insert to user MSTblUserLogin
sqlCursor = self.sqlConn.cursor()
try:
sqlCursor.execute("INSERT INTO MSTblUserLogin(username,password) VALUES (:user,:pass)",{"user": self.username, "pass": self.password})
UID = sqlCursor.lastrowid
sqlCursor.execute("INSERT INTO GIDHeader(UIDOwner) VALUES (:uid)",{"uid": UID})
self.sqlConn.commit()
self.latest_response = "Users has been created. Login to use authenticated endpoint"
except sqlite3.IntegrityError as e:
raise UserExist