Пример #1
0
def addEmployee():
    error = None
    if request.method == 'POST':

        req = request.json
        username = req['userName']
        email = req['email']
        password = req['password']
        user = user_model.UserModel()
        employeeProfile = employee_profile_model.EmployeeProfileModel()
        req = request.json

        if user.isExist("userName", username):
            error = 'Username already taken'
        elif user.isExist("email", email):
            error = 'Email already used'
        if error is None:
            user.setUserName(username)
            user.setEmail(email)
            user.setPassword(password)
            user.setType("e")
            user.insertUser()
            user.setUser(username)
            employeeProfile.setFirstName(req['firstName'])
            employeeProfile.setLastName(req['lastName'])
            employeeProfile.setEmployeeId(req['employeeId'])
            employeeProfile.setPhoneNumber(req['phoneNumber'])
            employeeProfile.setPosition(req['position'])
            employeeProfile.setSalary(req['salary'])
            employeeProfile.addEmployee(user.getUserId())
            return json.dumps({'Added': True})

    return json.dumps({'Added': False, 'error': error})
Пример #2
0
def updateProfile():
    employeeProfile = employee_profile_model.EmployeeProfileModel(
        session['userId'])
    user = user_model.UserModel(session['userId'])
    req = request.json
    if md5(req['Password'].encode('utf-8')).hexdigest() == user.getPassword():
        if req['firstName'] != employeeProfile.getFirstName():
            employeeProfile.updateField('firstName', req['firstName'])

        if req['lastName'] != employeeProfile.getLastName():
            employeeProfile.updateField('lastName', req['lastName'])

        if req['employeeId'] != employeeProfile.getEmployeeId():
            employeeProfile.updateField('employeeId', req['employeeId'])

        if req['phone'] != employeeProfile.getPhoneNumber():
            employeeProfile.updateField('phone', req['phone'])

        if req['position'] != employeeProfile.getPosition():
            employeeProfile.updateField('position', req['position'])

        if req['salary'] != employeeProfile.getSalary():
            employeeProfile.updateField('salary', req['salary'])

        if req['newPassword']:
            user.updateField('password', req['newPassword'])

        return json.dumps({'error': 'Updated'})

    return json.dumps({'error': 'Current Password is Incorrect'})
Пример #3
0
def login():
    error = None
    path = None
    if request.method == 'POST':
        req = request.json
        username = req['username']
        password = req['password']
        user = user_model.UserModel()
        user.setUser(username)
        app = current_app._get_current_object()    
        customerProfile = customer_profile_model.CustomerProfileModel(user.getUserId())
        session.clear()
        
        
        if user.getUserName() is None or user.getPassword() != md5(password.encode('utf-8')).hexdigest():
            error = 'Invalid username or password or not correct.'

     
        if user.getUserName() is not None:
            if user.getType() not in req['type']:
                if user.getType() == "c":
                    error = "Not a customer account"
                else:
                    error = "Not a employee account"

        if user.getType() == 'e':

            employeeProfile = employee_profile_model.EmployeeProfileModel(user.getUserId())        
            
            if user.getType() == 'e':
                session['profileId'] = employeeProfile.getProfileId()
                if employeeProfile.getPosition() == "chef":
                    path = '/chef'
                if employeeProfile.getPosition() == "deliveryboy":
                    path = '/DeliveryHome'
        if user.getType() == 'm':
                    path = '/Manager'        
                    
        if req['type'] == "c":
            if customerProfile.getApprove() == "0":
                error = 'Account not approve yet!'
            else:
                path = '/Menu'    
      

        if error is None:
            session['userId'] = user.getUserId()
            session['username'] = user.getUserName()
            session['email'] = user.getEmail()
            session['type'] = user.getType()
            
            token = jwt.encode({'userId': user.getUserId(), 'username': user.getUserName(), 'email': user.getEmail(), 'exp': datetime.datetime.utcnow() + datetime.timedelta(minutes=50)}, app.config['SECRET_KEY'])
            return json.dumps({'authenticated': True, 'token': token.decode('UTF-8'),'path': path, 'type': user.getType()})

        flash(error)

    return json.dumps({'authenticated': False, 'error': error})
Пример #4
0
def getEmployee():
    employeeProfile = employee_profile_model.EmployeeProfileModel()
    employeeProfile = employeeProfile.getEmployee()
    for i in range(len(employeeProfile)):
        user = user_model.UserModel(employeeProfile[i]['userId'])
        employeeProfile[i]['userName'] = user.getUserName()
        employeeProfile[i]['email'] = user.getEmail()
        employeeProfile[i]['userId'] = user.getUserId()
        employeeProfile[i]['registrationDate'] = user.getRegistrationDate()
    return json.dumps({'employees': employeeProfile})
Пример #5
0
def removeDish():
    error = None
    if request.method == 'POST':
        req = request.json

        if error is None:
            employeeProfile = employee_profile_model.EmployeeProfileModel(
                req['profileId'])
            employeeProfile.removeEmployee(req['profileId'], req['userId'])
            return json.dumps({'Remove': True})

    return json.dumps({'Remove': False, 'error': error})