コード例 #1
0
ファイル: user_manager.py プロジェクト: vanthaiunghoa/seller
	def getAll(self, token):
		userToken = self.validateToken(token)
		if 'error' in userToken:
			return userToken

		userDao = UserDao()
		userAdmin = userDao.getAdminUser(userToken['id'])
		if userAdmin == None:
			return ResponseHelper.generateErrorResponse("Sorry! You are not allowed to delete user!")

		userDao = UserDao()
		return userDao.getAll()
コード例 #2
0
ファイル: user_manager.py プロジェクト: vanthaiunghoa/seller
	def updateUser(self, user, token):
		userToken = self.validateToken(token)
		if 'error' in userToken:
			return userToken

		else:
			password = user['password'].encode('utf-8')
			user['password'] = bcrypt.hashpw(password, bcrypt.gensalt())
			user['password'] = user['password'].decode('utf-8')

		userDao = UserDao()
		userAdmin = userDao.getAdminUser(userToken['id'])
		if userAdmin == None:
			return ResponseHelper.generateErrorResponse("Sorry! You are not allowed to update user!")

		userDao.updateUser(user)
		return ResponseHelper.generateSuccessResponse(None)
コード例 #3
0
ファイル: user_manager.py プロジェクト: vanthaiunghoa/seller
	def insertUser(self, user, token):
		userToken = self.validateToken(token)
		if 'error' in userToken:
			return userToken

		userDao = UserDao()
		userAdmin = userDao.getAdminUser(userToken['id'])
		if userAdmin == None:
			return ResponseHelper.generateErrorResponse("Sorry! You are not allowed to insert new user!")

		userDB = userDao.getUserByUsername(user['username'])
		if (userDB != None):
			return ResponseHelper.generateErrorResponse("Username is already used")

		else:
			password = user['password'].encode('utf-8')
			user['password'] = bcrypt.hashpw(password, bcrypt.gensalt())
			userDao.insert(user)
			return ResponseHelper.generateSuccessResponse(user)