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)
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)
def createUser(self, user): userDao = UserDao() return userDao.insert(user)