def validationRoleID(role_id): if role_id is None: raise ValidationException("Role is required field") elif not isinstance(role_id, int): raise ValidationException("Role has invalid integer value") elif not RoleDao.getRoleByID(role_id): raise NotFoundException("Unable to find user role with given id")
def login_authenticate(): if UserDao.isUserExists(request.form['name'], request.form['password']): user = UserDao.getUserByLogin(request.form['name'], request.form['password']) session['login'] = user.login session['user_id'] = user.id session['role'] = RoleDao.getRoleByID(user.role_id).name if session['role'] == 'Customer': return render_template('my_orders.html',) if session['role'] == 'Administrator': return render_template('search_user.html',) if session['role'] == 'Merchandiser': return render_template('manage_orders.html',) if session['role'] == 'Supervisor': return render_template('product_grid.html',) else: error = 'Invalid username/password' return render_template('login(2).html', error=error)
ProductStock.add_new_record(11,2,115) ProductStock.add_new_record(1,2,110) ProductStock.add_new_record(3,1,115) ProductStock.add_new_record(1,3,55) ProductStock.add_new_record(2,2,310) ProductStock.add_new_record(3,2,115) ProductStock.add_new_record(4,2,118) ProductStock.add_new_record(5,1,115) ProductStock.add_new_record(6,2,125) ProductStock.add_new_record(11,3,115) ProductStock.add_new_record(2,3,310) ProductStock.add_new_record(4,3,118) ProductStock.add_new_record(5,3,115) ProductStock.add_new_record(6,3,125) RoleDao.createNewRole("Administrator") RoleDao.createNewRole("Merchandiser") RoleDao.createNewRole("Supervisor") RoleDao.createNewRole("Customer") RegionDao.createNewRegion("North") RegionDao.createNewRegion("West") RegionDao.createNewRegion("South") RegionDao.createNewRegion("East") UserDao.createNewUser('Max', '1111','Maxim','Sidorov', '*****@*****.**',1,2) UserDao.createNewUser('Nikol', '1111','Nikolay','Lobanov', '*****@*****.**', 4,1) UserDao.createNewUser('Vanya', '1111','Ivan','Ivanov', '*****@*****.**', 2,1) UserDao.createNewUser('Andrew', '1111','Andrew','Petrov', '*****@*****.**', 3,4) UserDao.createNewUser('Katya', '1111','Ekaterina','Ivanova', '*****@*****.**', 4,3) UserDao.createNewUser('Roma', '1111','Roman','Melnishin', '*****@*****.**', 2,1)
#!/usr/bin/env python # ---Fill test data for user and related entities---- from models.region_dao import RegionDao from models.role_dao import RoleDao from models.user_dao import UserDao RoleDao.createNewRole("Admin") RegionDao.createNewRegion("Crimea") UserDao.createNewUser('Anton', '111','Maxim','Sidorov', '*****@*****.**', 1,1) UserDao.createNewUser('Vanya', '111','Ivan','Ivanov', '*****@*****.**', 1,1) UserDao.createNewUser('Andrew', '111','Andrew','Petrov', '*****@*****.**', 1,1) UserDao.createNewUser('Katya', '111','Ekaterina','Ivanova', '*****@*****.**', 1,1) for instance in UserDao.getAllUsers(): print(instance.id,instance.login,instance.password,instance.first_name, instance.last_name, instance.email, RoleDao.getRoleByID(instance.role_id).name, RegionDao.getRegionByID(instance.region_id).name)
def getRoleByID(role_id): validationRoleID(role_id) return RoleDao.getRoleByID(role_id)
def deleteRole(role_id): validationRoleID(role_id) RoleDao.deleteRecord(role_id)
def updateRole(role_id, name): validationRoleID(role_id) validationRoleName(name) RoleDao.updateRole(role_id, name)
def createNewRole(name): validationRoleName(name) RoleDao.createNewRole(name)
def getlistRole(): return RoleDao.getAllRoles()