Guest User

Untitled

a guest
Mar 31st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. from kivy.uix.boxlayout import BoxLayout
  2.  
  3. class MasterControl(BoxLayout):
  4. def __init__(self, **kwargs):
  5. super(MasterControl, self).__init__(**kwargs)
  6. m_currentUser = None
  7.  
  8. def loginUser(self, emp):
  9. self.m_currentUser = emp
  10. print "I made it to login!"
  11. # remove login widget, add the rest of the UI according to the security level of the use
  12.  
  13. from kivy.uix.anchorlayout import AnchorLayout
  14. from kivy.uix.label import Label
  15. from kivy.uix.button import Button
  16. from kivy.uix.textinput import TextInput
  17. from kivy.uix.boxlayout import BoxLayout
  18.  
  19. from coreAPI.mastercontrol import MasterControl
  20. from employee import Employee, getEmployees
  21.  
  22. class LoginWidget(AnchorLayout):
  23. def __init__(self, **kwargs):
  24. super(LoginWidget, self).__init__(**kwargs)
  25.  
  26. def loginBtnHandle(instance):
  27. empList = getEmployees()
  28. for emp in empList:
  29. if emp.m_aNum == uNameInput.text:
  30. if emp.authenticate(pWordInput.text):
  31. self.parent.loginUser(emp) # Here is where I get AttributeError: 'MasterControl' object has no attribute 'loginUser'
  32.  
  33. box = BoxLayout(orientation = 'vertical', size = (300, 110), size_hint = (None, None), spacing = 10)
  34.  
  35. uNameInput = TextInput(hint_text = 'Username',
  36. multiline = False,
  37. size = (300, 30),
  38. size_hint = (None, None),
  39. cursor_color = [0,0,0,1],
  40. write_tab = False)
  41.  
  42. pWordInput = TextInput(hint_text = 'Password',
  43. multiline = False,
  44. size = (300, 30),
  45. size_hint = (None, None),
  46. cursor_color = [0,0,0,1],
  47. password = True,
  48. write_tab = False)
  49.  
  50. loginBtn = Button(text = 'Login', size = (300, 50), size_hint = (None, None))
  51. loginBtn.bind(on_press = loginBtnHandle)
  52. loginBtn.bind(on_enter = loginBtnHandle)
  53.  
  54. box.add_widget(uNameInput)
  55. box.add_widget(pWordInput)
  56. box.add_widget(loginBtn)
  57.  
  58. self.add_widget(box)
  59.  
  60. from passlib.hash import pbkdf2_sha256
  61. import pickle
  62. import os
  63.  
  64. class Employee():
  65. def __init__(self, name, aNumber, password, clearance):
  66. self.m_name = name
  67. self.m_aNum = aNumber
  68. self.m_pWordHash = pbkdf2_sha256.hash(password) # Only store the password hash. NEVER the password text
  69. self.m_clearance = clearance
  70.  
  71. def authenticate(self, attempt):
  72. return pbkdf2_sha256.verify(attempt, self.m_pWordHash)
  73.  
  74. def serialize(self):
  75. filename = 'users/' + self.m_aNum + '.emp'
  76. frozen = pickle.dumps(self)
  77. f = open(filename, 'w')
  78. f.write(frozen)
  79. f.close()
  80. return frozen
  81.  
  82. def getEmployees():
  83. empList = []
  84. path = 'users/'
  85. for filename in os.listdir(path):
  86. f = open(path + filename, 'r')
  87. contents = f.read()
  88. empList.append(pickle.loads(contents))
  89. return empList
  90.  
  91. tempEmp = Employee('Tester', 'A12345678', 'password', 'HIGH')
  92. tempEmp.serialize()
Add Comment
Please, Sign In to add comment