def getPayments(): if not request.json: abort(400) man_id = request.json.get("man_id", None) if man_id is None: abort(400) db = Database(config) sql = "SELECT `id`, `status` FROM StoreManufacturer WHERE id = %s" manufacturer = db.getOneByParam(sql, man_id) if not manufacturer: abort(400) if manufacturer is not None and manufacturer.get("status") != 1: return get_response("Производитель сейчас не активен", False) sql = """SELECT smp.payment_id, spmt.name FROM StoreManufacturerPayment smp INNER JOIN StorePaymentMethodTranslate spmt ON spmt.language_id = 1 AND spmt.object_id = smp.payment_id WHERE smp.manufacturer_id = %s""" payments = db.getAllWithParams(sql, [man_id]) return get_response(payments, True)
def checkCode(): if not request.json: abort(400) phone = request.json.get("phone", None) code = request.json.get("code", None) token = request.json.get("token", None) if not code or not phone or not token: abort(400) db = Database(config) user = db.getOneByParam( "SELECT `id`, `sms_code`, `token` FROM `user_register` WHERE `phone` = %s", phone) if not user or user.get("token") != token: abort(403) if user.get("sms_code") != code: return get_response("Ваш код SMS неверен", False) id = user.get("id") new_token = randomString(25) user = db.executeByParams( "UPDATE `user_register` SET `token` = %s WHERE `id` = %s", [new_token, id]) return get_response({"new_token": new_token}, True)
def getCategories(): if not request.json: abort(400) man_id = request.json.get("man_id", None) if man_id is None: abort(400) db = Database(config) sql = "SELECT `id`, `status` FROM StoreManufacturer WHERE id = %s" manufacturer = db.getOneByParam(sql, man_id) if not manufacturer: abort(400) if manufacturer is not None and manufacturer.get("status") != 1: return get_response("Производитель сейчас не активен", False) sql = """SELECT sc.`id`, sct.`name` FROM `StoreCategory` sc INNER JOIN `StoreCategoryTranslate` sct ON sct.`object_id` = sc.`id` AND sct.`language_id` = 1 WHERE sc.`parent` IN ( SELECT smcr.`category_id` FROM `StoreManufacturerCategoryRef` smcr WHERE smcr.`manufacturer_id` = %s) AND sc.level = 4""" categories = db.getAllWithParams(sql, [man_id]) return get_response(categories, True)
def getManufacturer(): if not request.json: abort(400) man_id = request.json.get("man_id", None) lat = request.json.get("lat", None) lng = request.json.get("lng", None) if not man_id or not lat or not lng: abort(400) db = Database(config) sql = """SELECT smt.`name`, smt.`description`, sm.`is_new`, sm.`work_start`, sm.`work_finish`, sm.`status`, smi.name AS 'image' FROM `StoreManufacturer` sm INNER JOIN `StoreManufacturerTranslate` smt ON smt.`object_id` = sm.`id` AND smt.`language_id` = 1 LEFT JOIN StoreManufacturerImage smi ON smi.manufacturer_id = sm.id AND smi.is_main = 1 WHERE sm.`id` = %s""" manufacturer = db.getOneByParam(sql, man_id) if not manufacturer: abort(400) if manufacturer is not None and manufacturer.get("status") != 1: return get_response("Производитель сейчас не активен", False) result = { "name": manufacturer.get("name"), "description": manufacturer.get("description"), "is_new": True if manufacturer.get("is_new") == 1 else False, "start_work": str(manufacturer.get("work_start")), "finish_work": str(manufacturer.get("work_finish")), "image": manufacturer.get("image") } result["delivery_price"] = getDeliveryPrice(man_id, lat, lng) new_image = None if result.get("image") is not None: new_image = config.manufacturer_path + result.get("image") url = config.url_bringo + config.b_manufacturer_path + result.get( "image") if (is_downloadable(url) and not is_file_exists(new_image)): downloand_image(url, new_image) elif not is_file_exists(new_image): new_image = None if new_image is None: new_image = config.no_manufacturer result["image"] = new_image return get_response(result, True)
def userExists(): if not request.json: abort(400) user_id = request.json.get("user_id", None) intro_token = request.json.get("intro_token", None) if not user_id or not intro_token: abort(400) if intro_token is None or intro_token != config.intro_token: abort(400) db = Database(config) sql = "SELECT u.`id`, up.`phone`, u.`username` FROM `user` u INNER JOIN `user_profile` up ON up.`user_id` = u.`id` WHERE u.`id` = %s" user = db.getOneByParam(sql, user_id) user_id = user.get("id", None) phone = user.get("phone", None) username = user.get("username", None) if user is None or user_id is None or phone is None: return get_response("Пользователь не существует", False) return get_response( { "phone": phone, "user_id": user_id, "username": username }, True)
def verify_password(username, password): db = Database(config) user = db.getOneByParam( "SELECT `password` FROM `user` WHERE `username` = %s", username) if user is not None and user.get("password") is not None: if validatePassword(password, user.get("password")): return True return False
def __init__(self, parent, *args, **kwargs): tk.Frame.__init__(self, parent, *args, **kwargs) self.parent = parent self.database = Database() parent.title("Music Player") parent.geometry("1000x600") style = ThemedStyle(parent) style.set_theme("scidgrey")
def register(): if not request.json: abort(400) phone = request.json.get("phone", None) intro_token = request.json.get("intro_token", None) if phone is None: # or len(str(phone)) != 9: abort(400) if intro_token is None or intro_token != config.intro_token: abort(400) code = randomSmsCode() db = Database(config) user = db.getOneByParam( "SELECT id FROM `user_register` WHERE `phone` = %s", phone) if not user: sql = """INSERT INTO `user_register`( `phone`, `sms_code`, `password`, `token`, `send_count`, `fail_count`, `created_at`, `updated_at`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)""" db.executeByParams(sql, [ phone, code, randomString(), randomString(25), 0, 0, currentTime(), currentTime() ]) else: user = db.executeByParams( "UPDATE `user_register` SET `sms_code` = %s WHERE `phone` = %s", [code, phone]) user = db.getOneByParam( "SELECT sms_code, token FROM `user_register` WHERE `phone` = %s", phone) # send sms to phone number headers = {'User-Agent': 'Mozilla/5.0'} payload = { 'login': Config.sms_login, 'key': Config.sms_pass, 'text': code, 'phone': phone, 'sender': 'Bringo.uz' } requests.post(Config.sms_url, data=payload, headers=headers) return get_response( { "code": user.get("sms_code", code), "token": user.get("token", None) }, True)
def getProduct(): if not request.json: abort(400) man_id = request.json.get("man_id", None) product_id = request.json.get("product_id", None) if not man_id or not product_id: abort(400) db = Database(config) sql = "SELECT `id`, `status` FROM StoreManufacturer WHERE id = %s" manufacturer = db.getOneByParam(sql, man_id) if not manufacturer: abort(400) if manufacturer is not None and manufacturer.get("status") != 1: return get_response("Производитель сейчас не активен", False) sql = """SELECT p.id, pt.name, sppr.is_default, (SELECT spt.ingredients FROM StoreProductTranslate spt WHERE spt.object_id = sppr.store_product_id AND spt.language_id = 1) AS 'ingredients', (SELECT spi.name FROM StoreProductImage spi WHERE spi.is_main = 1 AND spi.product_id = sppr.product_id) AS 'image' FROM Products p INNER JOIN ProductTranslate pt ON pt.object_id = p.id AND pt.language_id = 1 INNER JOIN StoreProductProductRef sppr ON sppr.product_id = p.id WHERE p.id = %s GROUP BY sppr.product_id ORDER BY sppr.is_default DESC""" product = db.getOneByParam(sql, product_id) sql = """SELECT sppr.option_id AS 'id', ot.name, sp.price, sp.id AS 'product_id' FROM StoreProductProductRef sppr INNER JOIN StoreProduct sp ON sp.id = sppr.store_product_id INNER JOIN OptionTranslate ot ON ot.object_id = sppr.option_id AND ot.language_id = 1 WHERE sppr.product_id = %s""" product["options"] = db.getAllWithParams(sql, [product_id]) new_image = None if product["image"] is not None: new_image = config.product_path + product["image"] url = config.url_bringo + config.product_path + product["image"] if (is_downloadable(url) and not is_file_exists(new_image)): downloand_image(url, new_image) elif not is_file_exists(new_image): new_image = None if new_image is None: new_image = config.no_product product["image"] = new_image return get_response(product, True)
def getProductsAll(): if not request.json: abort(400) man_id = request.json.get("man_id", None) # cat_id = request.json.get("cat_id", None) if not man_id: abort(400) db = Database(config) sql = "SELECT `id`, `status` FROM StoreManufacturer WHERE id = %s" manufacturer = db.getOneByParam(sql, man_id) if not manufacturer: abort(400) # sql = "SELECT `id` FROM `StoreCategory` WHERE `id` = %s AND `level` = 4" # category = db.getOneByParam(sql, cat_id) #if not category: #abort(400) if manufacturer is not None and manufacturer.get("status") != 1: return get_response("Производитель сейчас не активен", False) # sql = """SELECT # sc.`id`, # sct.`name` # FROM `StoreCategory` sc # INNER JOIN `StoreCategoryTranslate` sct # ON sct.`object_id` = sc.`id` AND sct.`language_id` = 1 # WHERE sc.`parent` IN ( # SELECT smcr.`category_id` # FROM `StoreManufacturerCategoryRef` smcr # WHERE smcr.`manufacturer_id` = %s) # AND sc.level = 4""" # p.position sql = """SELECT sppr.product_id AS 'id', sp.price, pt.name, (SELECT spt.ingredients FROM StoreProductTranslate spt WHERE spt.object_id = sp.id and spt.language_id = 1) AS 'ingredients', sppr.is_default, (SELECT spi.name FROM StoreProductImage spi WHERE spi.is_main = 1 AND spi.product_id = sp.id) AS 'image', (SELECT sct.`name` FROM `StoreCategoryTranslate` sct WHERE sct.object_id = spcr.category AND sct.`language_id` = 1 ) AS 'catName' FROM StoreProductCategoryRef spcr INNER JOIN StoreProduct sp ON sp.id = spcr.product INNER JOIN StoreProductProductRef sppr ON sppr.store_product_id = spcr.product INNER JOIN ProductTranslate pt ON pt.object_id = sppr.product_id AND pt.language_id = 1 INNER JOIN Products p ON p.id = sppr.product_id WHERE sp.manufacturer_id = %s AND sp.is_active = 1 GROUP BY sppr.product_id ORDER BY sppr.is_default DESC""" products = db.getAllWithParams(sql, [man_id]) for product in products: new_image = None if product["image"] is not None: new_image = config.product_path + product["image"] url = config.url_bringo + config.product_path + product["image"] if (is_downloadable(url) and not is_file_exists(new_image)): downloand_image(url, new_image) elif not is_file_exists(new_image): new_image = None if new_image is None: new_image = config.no_product product["image"] = new_image return get_response(products, True)
def setPassword(): if not request.json: abort(400) token = request.json.get("token", None) password = request.json.get("password", None) if not password or not token: abort(400) db = Database(config) register = db.getOneByParam( "SELECT `id`, `phone`, `token` FROM `user_register` WHERE `token` = %s", token) if not register or register.get("token") != token: abort(403) phone = register.get("phone") user_profile = db.getOneByParam( "SELECT `user_id` FROM `user_profile` WHERE `phone` = %s", phone) if user_profile and user_profile.get("user_id"): user = db.getOneByParam("SELECT `id` FROM `user` WHERE `id` = %s", user_profile.get("user_id")) hash = encryptPassword(password) if user and user.get("id"): db.executeByParams( "UPDATE `user` SET `password` = %s, `active` = 1 WHERE `id` = %s", [hash, user.get("id")]) else: sql = """INSERT INTO `user` (`username`, `password`, `email`, `created_at`, `last_login`, `login_ip`, `recovery_key`, `recovery_password`, `discount`, `banned`, `service`, `social_id`, `active`, `secret_code`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""" hash = encryptPassword(password) email = str(phone) + "*****@*****.**" db.executeByParams(sql, [ str(phone), hash, email, None, None, None, None, None, None, 0, None, None, 1, None ]) user = db.getOneByParam( "SELECT `id` FROM `user` WHERE `username` = %s", phone) if user and user.get("id"): sql = """INSERT INTO `user_profile` (`user_id`, `full_name`, `phone`, `delivery_address`, `new_phone`) VALUES (%s, %s, %s, %s, %s)""" db.executeByParams( sql, [user.get("id"), str(phone), phone, None, None]) # finally check if user was successfully registered user_profile = db.getOneByParam( "SELECT `user_id`, `phone` FROM `user_profile` WHERE `phone` = %s", phone) if user_profile and user_profile.get("user_id"): user = db.getOneByParam( "SELECT `id`, `username` FROM `user` WHERE `id` = %s", user_profile.get("user_id")) phone = None if user_profile and user_profile.get("phone") is not None: phone = user_profile.get("phone") user_id = None if user and user.get("id") is not None: user_id = user.get("id") if user_id is not None and phone is not None: db.executeByParams("DELETE FROM `user_register` WHERE `token` = %s", [token]) return get_response( { "phone": phone, "user_id": user_id, "password": password, "username": user.get("username", None) }, True)
globals.zoneid = globals.getzoneidbyname(globals.config['default_zone']) # Creates a ModelPicker object in charge of setting spawn models as Pickable. globals.picker = ModelPicker() globals.grid_list = list() globals.gridlinks_list = list() # Loads the various GUI components app = wx.App() globals.spawndialog = SpawnsFrame(wx.Frame(None, -1, ' ')) globals.spawndialog.Show() globals.griddialog = GridsFrame(wx.Frame(None, -1, ' ')) globals.griddialog.Show() # # Connects to the database globals.database = Database(cfg['host'], cfg['user'], cfg['password'], cfg['port'], cfg['db']) connection = globals.database.ConnectToDatabase() # Gets spawn data for the current zone spawnscursor = globals.database.GetDbSpawnData() gridscursor = globals.database.GetDbGridIdsByZoneId(globals.zoneid) spawnsnumrows = spawnscursor.rowcount gridsnumrows = gridscursor.rowcount # Visually loads spawn data in the zone world.PopulateSpawns(spawnscursor, spawnsnumrows) # NEEDS REFACTORING # Populates the spawns treeview spawnscursor = globals.database.GetDbSpawnData()