Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from kivy.uix.boxlayout import BoxLayout
- class MasterControl(BoxLayout):
- def __init__(self, **kwargs):
- super(MasterControl, self).__init__(**kwargs)
- m_currentUser = None
- def loginUser(self, emp):
- self.m_currentUser = emp
- print "I made it to login!"
- # remove login widget, add the rest of the UI according to the security level of the use
- from kivy.uix.anchorlayout import AnchorLayout
- from kivy.uix.label import Label
- from kivy.uix.button import Button
- from kivy.uix.textinput import TextInput
- from kivy.uix.boxlayout import BoxLayout
- from coreAPI.mastercontrol import MasterControl
- from employee import Employee, getEmployees
- class LoginWidget(AnchorLayout):
- def __init__(self, **kwargs):
- super(LoginWidget, self).__init__(**kwargs)
- def loginBtnHandle(instance):
- empList = getEmployees()
- for emp in empList:
- if emp.m_aNum == uNameInput.text:
- if emp.authenticate(pWordInput.text):
- self.parent.loginUser(emp) # Here is where I get AttributeError: 'MasterControl' object has no attribute 'loginUser'
- box = BoxLayout(orientation = 'vertical', size = (300, 110), size_hint = (None, None), spacing = 10)
- uNameInput = TextInput(hint_text = 'Username',
- multiline = False,
- size = (300, 30),
- size_hint = (None, None),
- cursor_color = [0,0,0,1],
- write_tab = False)
- pWordInput = TextInput(hint_text = 'Password',
- multiline = False,
- size = (300, 30),
- size_hint = (None, None),
- cursor_color = [0,0,0,1],
- password = True,
- write_tab = False)
- loginBtn = Button(text = 'Login', size = (300, 50), size_hint = (None, None))
- loginBtn.bind(on_press = loginBtnHandle)
- loginBtn.bind(on_enter = loginBtnHandle)
- box.add_widget(uNameInput)
- box.add_widget(pWordInput)
- box.add_widget(loginBtn)
- self.add_widget(box)
- from passlib.hash import pbkdf2_sha256
- import pickle
- import os
- class Employee():
- def __init__(self, name, aNumber, password, clearance):
- self.m_name = name
- self.m_aNum = aNumber
- self.m_pWordHash = pbkdf2_sha256.hash(password) # Only store the password hash. NEVER the password text
- self.m_clearance = clearance
- def authenticate(self, attempt):
- return pbkdf2_sha256.verify(attempt, self.m_pWordHash)
- def serialize(self):
- filename = 'users/' + self.m_aNum + '.emp'
- frozen = pickle.dumps(self)
- f = open(filename, 'w')
- f.write(frozen)
- f.close()
- return frozen
- def getEmployees():
- empList = []
- path = 'users/'
- for filename in os.listdir(path):
- f = open(path + filename, 'r')
- contents = f.read()
- empList.append(pickle.loads(contents))
- return empList
- tempEmp = Employee('Tester', 'A12345678', 'password', 'HIGH')
- tempEmp.serialize()
Add Comment
Please, Sign In to add comment