|
1
|
|
|
""" |
|
2
|
|
|
incomplete |
|
3
|
|
|
implemented using data structures |
|
4
|
|
|
#creating dtrequest, dtuser and dtlogin list with dictionary |
|
5
|
|
|
to simulate data store |
|
6
|
|
|
|
|
7
|
|
|
""" |
|
8
|
|
|
|
|
9
|
|
|
import psycopg2 |
|
10
|
|
|
from config import dbconfig, basedir |
|
11
|
|
|
import os |
|
12
|
|
|
import jwt |
|
13
|
|
|
|
|
14
|
|
|
from flask import json, jsonify |
|
15
|
|
|
from itsdangerous import (TimedJSONWebSignatureSerializer |
|
16
|
|
|
as Serializer, BadSignature, SignatureExpired) |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
def test_connection(): |
|
22
|
|
|
"""connect to the postgresql server""" |
|
23
|
|
|
conn = None |
|
24
|
|
|
try: |
|
25
|
|
|
#read conection parameters |
|
26
|
|
|
#params = dbconfig(basedir+'database.ini', 'postgresql') |
|
27
|
|
|
|
|
28
|
|
|
#connect to server |
|
29
|
|
|
print('Conecting to the PostgreSQL database...') |
|
30
|
|
|
conn = psycopg2.connect(dbname='mtracker_db',user="antonio", password="pass.123") |
|
31
|
|
|
|
|
32
|
|
|
#create a cursor |
|
33
|
|
|
cur = conn.cursor() |
|
34
|
|
|
|
|
35
|
|
|
#execute a statement |
|
36
|
|
|
print('Postgres database version: ') |
|
37
|
|
|
cur.execute('SELECT version()') |
|
38
|
|
|
|
|
39
|
|
|
#display the postgress db server version |
|
40
|
|
|
db_version = cur.fetchone() |
|
41
|
|
|
print(db_version) |
|
42
|
|
|
|
|
43
|
|
|
#close comm with pgSQL |
|
44
|
|
|
cur.close() |
|
45
|
|
|
except (Exception, psycopg2.DatabaseError) as error: |
|
46
|
|
|
print(error) |
|
47
|
|
|
finally: |
|
48
|
|
|
if conn is not None: |
|
49
|
|
|
conn.close() |
|
50
|
|
|
print('Database connection closed.') |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
#User sample data |
|
58
|
|
|
dtusers = [ |
|
59
|
|
|
{ |
|
60
|
|
|
"id": 1, |
|
61
|
|
|
"fname": "John", |
|
62
|
|
|
"lname": "Doe", |
|
63
|
|
|
"email": "[email protected]" |
|
64
|
|
|
}, |
|
65
|
|
|
{ |
|
66
|
|
|
"id": 2, |
|
67
|
|
|
"fname": "Susan", |
|
68
|
|
|
"lname": "Sue", |
|
69
|
|
|
"email": "[email protected]" |
|
70
|
|
|
}, |
|
71
|
|
|
{ |
|
72
|
|
|
"id": 3, |
|
73
|
|
|
"fname": "Mary", |
|
74
|
|
|
"lname": "Doe", |
|
75
|
|
|
"email": "[email protected]" |
|
76
|
|
|
}, |
|
77
|
|
|
{ |
|
78
|
|
|
"id": 4, |
|
79
|
|
|
"fname": "Anto", |
|
80
|
|
|
"lname": "Denis", |
|
81
|
|
|
"email": "[email protected]" |
|
82
|
|
|
} |
|
83
|
|
|
] |
|
84
|
|
|
|
|
85
|
|
|
#requests sample data |
|
86
|
|
|
dtrequest = [ |
|
87
|
|
|
{ |
|
88
|
|
|
"id": 1, |
|
89
|
|
|
"requestor":"Anto kish", |
|
90
|
|
|
"email": "[email protected]", |
|
91
|
|
|
"type": "maintenance", |
|
92
|
|
|
"status":"Approved", |
|
93
|
|
|
"desc": "Description goes here" |
|
94
|
|
|
}, |
|
95
|
|
|
{ |
|
96
|
|
|
"id": 2, |
|
97
|
|
|
"requestor":"John Doe", |
|
98
|
|
|
"email": "[email protected]", |
|
99
|
|
|
"type": "repair", |
|
100
|
|
|
"status":"Pending", |
|
101
|
|
|
"desc": "Description goes here" |
|
102
|
|
|
}, |
|
103
|
|
|
{ |
|
104
|
|
|
"id": 3, |
|
105
|
|
|
"requestor":"Anto kish", |
|
106
|
|
|
"email": "[email protected]", |
|
107
|
|
|
"type": "maintenance", |
|
108
|
|
|
"status":"Pending", |
|
109
|
|
|
"desc": "Description goes here" |
|
110
|
|
|
}, |
|
111
|
|
|
{ |
|
112
|
|
|
"id": 4, |
|
113
|
|
|
"requestor":"John Doe", |
|
114
|
|
|
"email": "[email protected]", |
|
115
|
|
|
"type": "maintenance", |
|
116
|
|
|
"status":"Approved", |
|
117
|
|
|
"desc": "Description goes here" |
|
118
|
|
|
} |
|
119
|
|
|
] |
|
120
|
|
|
#login data |
|
121
|
|
|
dtlogin = [ |
|
122
|
|
|
{ |
|
123
|
|
|
"id": 1, |
|
124
|
|
|
"username": "[email protected]", |
|
125
|
|
|
"password": "pass" |
|
126
|
|
|
}, |
|
127
|
|
|
{ |
|
128
|
|
|
"id": 2, |
|
129
|
|
|
"username": "[email protected]", |
|
130
|
|
|
"password": "pass" |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
] |
|
134
|
|
|
|
|
135
|
|
|
"""To be implemented when intergrating with database""" |
|
136
|
|
|
class UserAuth(object): |
|
137
|
|
|
def hash_password(self, pwd): |
|
138
|
|
|
pass |
|
139
|
|
|
|
|
140
|
|
|
def verify_password(self, pwd): |
|
141
|
|
|
pass |
|
142
|
|
|
|
|
143
|
|
|
def generate_auth_token(self, expiration=600): |
|
144
|
|
|
pass |
|
145
|
|
|
|
|
146
|
|
|
@staticmethod |
|
147
|
|
|
def verify_auth_token(token): |
|
148
|
|
|
pass |
|
149
|
|
|
|
|
150
|
|
|
if __name__ == '__main__': |
|
151
|
|
|
test_connection() |