示例#1
0
	def validateToken(self, token):
		userDao = UserDao()
		user = userDao.getUser(token)
		if user == None:
			return ResponseHelper.generateErrorResponse("Invalid token")
		else:
			return user
示例#2
0
	def insertSku(self, sku, token):
		user = self.validateToken(token)
		if 'error' in user:
			return user

		# Validate certain size
		skudao = SkuDao()
		userdao = UserDao()
		checkExistSku = skudao.checkExistSku(sku)
		if (checkExistSku > 0):
			return ResponseUtils.generateErrorResponse("You cannot add SKU already exist!!!")

		addedSize = skudao.getAddedSize(user['id'])
		certainSize = userdao.getCertainSize(user['id'])
		if (addedSize >= certainSize):
			return ResponseUtils.generateErrorResponse("You cannot add more SKU, please contact admin to improve your account!")

		# Validate SKU by product's data in database
		productDao = ProductDao()
		product, exception = productDao.getProductBySellerSku(user, sku)
		if exception != None:
			return ResponseUtils.generateErrorResponse(exception)

		# Add missing arguments and insert to our database
		sku['name'] = product['name']
		sku['link'] = product['url']
		sku['special_price'] = product['special_price']

		skudao.insert(sku, user)
		return ResponseUtils.generateSuccessResponse()
示例#3
0
    def validateToken(self, token):
        userDao = UserDao()
        try:
            user = userDao.getUser(token)
            if user == None:
                return ResponseHelper.generateErrorResponse("Invalid token")

            return user
        except Exception as ex:
            return ResponseHelper.generateErrorResponse(
                '''Valid user exception: {}'''.format(str(ex)))
    def execute(self):
        print("*********** Price Automatically is executed ***********")
        skudao = SkuDao()
        skus = skudao.getAll()
        if (skus == None):
            return

        userDao = UserDao()
        user = userDao.getUser("token")
        for sku in skus:
            enemies = self.getEnemies(sku['link'])
            self.priceAlgorithm(enemies, user, sku)
示例#5
0
	def deleteUser(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 delete user!")

		userDao.deleteUser(user)
		return ResponseHelper.generateSuccessResponse(None)
示例#6
0
  def validateToken(self, token):
    if (StringUtils.isEmpty(token)):
      return None, "Invalid token"

    try:
      userDao = UserDao()
      user = userDao.getUser(token)
      if user == None:
        return None, "Invalid token"

      return user, None
    except Exception as ex:
      return None, '''Valid user exception: {}'''.format(str(ex))
 def doUpdatePrice(self, sku, newSpecialPrice):
     sku['updated_at'] = int(round(time.time()))
     sku['special_price'] = newSpecialPrice
     # Update internal database
     skuDao = SkuDao()
     skuDao.update(sku)
     # Update external database
     userDao = UserDao()
     temporaryUser = userDao.getUser("token")
     lazadaSkuApi = LazadaSkuApi()
     lazadaProduct = lazadaSkuApi.updateProductSpecialPrice(
         sku, temporaryUser, newSpecialPrice)
     print("*********** Price Automatically do updated price ***********")
     print("Sku: ", sku['sku'], "/nnew special price: ", newSpecialPrice)
示例#8
0
	def updatePw(self, user, token):
		userDao = UserDao()
		userDB = userDao.getUserUpdatePW(token)
		if (userDB == None):
			return ResponseHelper.generateErrorResponse("Account not exist!")

		if bcrypt.checkpw(user['oldpass'].encode('utf-8'), userDB['password'].encode('utf-8')):
			password = user['newpass'].encode('utf-8')
			user['newpass'] = bcrypt.hashpw(password, bcrypt.gensalt())
			user['newpass'] = user['newpass'].decode('utf-8')
			user = userDao.updatePw(user, token)
			if not user:
				return ResponseHelper.generateErrorResponse("System error, please try again")

			return ResponseHelper.generateSuccessResponse(user)
		else:
			return ResponseHelper.generateErrorResponse("Password is invalid")
示例#9
0
	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)
示例#10
0
	def login(self, user):
		userDao = UserDao()
		userDB = userDao.getUserByUsername(user['username'])
		if (userDB == None):
			return ResponseHelper.generateErrorResponse("Username is invalid")

		if bcrypt.checkpw(user['password'].encode('utf-8'), userDB['password'].encode('utf-8')):
			token = jwt.encode({'user' : 'username', 'createdAt': datetime.datetime.utcnow().isoformat()}, 'leoz')
			user['id'] = userDB['id']
			user['token'] = token.decode("utf-8")
			user['username'] = userDB['username'] # using lazada_user_name in database instead.
			user['password'] = None
			user = userDao.updateUserToken(user)
			if not user:
				return ResponseHelper.generateErrorResponse("System error, please try again")

			return ResponseHelper.generateSuccessResponse(user)
		else:
			return ResponseHelper.generateErrorResponse("Password is invalid")
示例#11
0
	def register(self, user):
		passwordOriginal = user['password']
		password = user['password'].encode('utf-8')
		user['password'] = bcrypt.hashpw(password, bcrypt.gensalt()).decode('utf-8')
		user['certain_size'] = SkuConfig.DEFAULT_CERTAIN_SIZE

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

		# Insert new user
		userDao.insert(user)

		# Login it in
		loginUser = {
			"username": user['username'],
			"password": passwordOriginal
		}
		return self.login(loginUser)
示例#12
0
	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)
示例#13
0
	def initialize(self):
		userDao = UserDao()
		userDao.createTable()
示例#14
0
	def getUser(self, token):
		userDao = UserDao()
		return userDao.getUser(token)
示例#15
0
	def createUser(self, user):
		userDao = UserDao()
		return userDao.insert(user)
示例#16
0
from database.user_dao import UserDao
from database.shop_dao import ShopDao
from database.product_dao import ProductDao
from database.constant_dao import ConstantDao
from database.account_statement_dao import AccountStatementDao
from database.account_statement_exception_dao import AccountStatementExceptionDao
from config import ConstantConfig
from utils.lazada_api_helper import LazadaApiHelper

# Database instances
userDao = UserDao()
shopDao = ShopDao()
prroductDao = ProductDao()
constantDao = ConstantDao()
accountStatementDao = AccountStatementDao()
accountStatementExceptionDao = AccountStatementExceptionDao()


class AppController(object):
    def initDatabase(self):
        # Init tables
        shopDao.createTable()
        prroductDao.createTable()
        constantDao.createTable()
        accountStatementDao.createTable()
        accountStatementExceptionDao.createTable()
        # Init default values
        self.initDefaultConstantValue()

    #-----------------------------------------------------------------------------
    # Insert default constant for all user
示例#17
0
import time
from database.user_dao import UserDao
from cronjob.get_order_worker import GetOrderWorker
from config import CronJob

if __name__ == "__main__":

    userDao = UserDao()
    superAdmin = userDao.getSuperAdmin()

    while True:
        if (superAdmin):
            clone = GetOrderWorker({"user": superAdmin})
            try:
                clone.daemon = True
                clone.start()
            except Exception as ex:
                clone.join(0)
                print("Error: unable to start thread: ", ex)

        time.sleep(CronJob.GET_ORDER_TIME_INTEVAL)
示例#18
0
import time
from database.user_dao import UserDao
from cronjob.auto_price_worker import AutoPriceWorker
from config import CronJob

if __name__ == "__main__":

    starttime = time.time()
    userDao = UserDao()

    while True:
        users = userDao.getAll()
        if (users):
            for user in users:
                clone = AutoPriceWorker({"user": user})
                try:
                    clone.daemon = True
                    clone.start()
                except Exception as ex:
                    clone.join(0)
                    print("Error: unable to start thread: ", ex)

        time.sleep(CronJob.AUTO_PRICE_TIME_INTEVAL)