-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.py
63 lines (61 loc) · 2.86 KB
/
controller.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
# the function of the controller. Stand between the model and the view in order to easily make future modifications to functionality. The controller has acces to the models functions. The model is like a work horse and can validate and take action while the controller uses the information from the model to make decisions about what to do.
from passlib.hash import pbkdf2_sha256 as passs
class Con:
def __init__(self,modl):
self.modl = modl
# make the model initalize a connection
def adduser(self,username, fullname, password):
## hash the password and then move the information into the model.
password = self.hashpasscode(password)
return self.modl.adduser(username,fullname,password)
def hashpasscode(self, password):
return passs.encrypt(password,rounds=20000, salt_size=16)
def authuser(self, username, password):
passhash = self.modl.getpass(username)
print(str(password) + " " + str(passhash))
if( passs.verify(password, passhash) ):
## user verified.
return True
return False
def getapikey(self, username,password):
if(self.authuser(username,password)):
return self.modl.getapikey(username)
def addnote(self,content, apik):
## validate the apik.
if(self.modl.validtateapik(apik)):
# The key is valid. continue and add the note.
if(self.modl.addnote(content,apik)):
return "note has been created"
else:
return "key is not valid"
def listnotes(self,apik, ark = 1):
if(self.modl.validtateapik(apik)):
return self.modl.listnotes(apik, ark)
else:
return "key is not valid"
def arcnote(self, noteid, apik):
if(self.modl.apikownsnote(apik, noteid)):
## the apik owns the noteid. continue with update.
if(self.modl.arcnote(noteid)):
return "active status has been updated"
else:
return "something went wrong"
else:
return "you are either not owner of fhe noteid and/or apik does not exists."
def delnote(self,noteid,apik):
if(self.modl.apikownsnote(apik,noteid)):
## del the note
if(self.modl.delnote(noteid)):
return "note has been deleted"
else:
return "something went wrong"
else:
return "you are either not owner of fhe noteid and/or apik does not exists."
def unarc(self,noteid,apik):
if(self.modl.apikownsnote(apik,noteid)):
if(self.modl.unarcnote(noteid)):
return "note has been reverted back into main"
else:
return "some error has occured"
else:
return "You either don't own the note or have a invalid apikey and/or noteid"