def verify(): models = {'user': User, 'vendor': Vendor} token = request.args.get('token', '', type=str) info = redis_get(CONFIRM_EMAIL, token, delete=True, serialize=True) if info: # if info['action'] == 'register': # session[USER_REGISTER_STEP] = 2 # session[USER_REGISTER_EMAIL] = info['email'] # return redirect(url_for('user.register', step=2)) if info['action'] == 'confirm': role = models[info['role']].query.get(info['id']) if role: if 'email' in info and info['email'] != role.email: role.email = info['email'] role.email_confirmed = True db.session.commit() if info['role'] == 'user': return redirect(url_for('user.profile', _anchor='my')) elif info['role'] == 'vendor': return redirect(url_for('vendor.settings')) # elif info['action'] == 'reset_password': # session[USER_RESET_PASSWORD_STEP] = 1 # session[USER_RESET_PASSWORD_USERNAME] = info['email'] # return redirect(url_for('user.reset_password_next')) return u'此链接已失效'
def vendor_detail(vendor_id): if not current_app.debug and vendor_id not in [12801, 12803, 12806, 12836]: abort(404) format = request.args.get('format', '', type=str) if format == 'json': data = redis_get('BRAND_ITEMS', vendor_id) if data is None: data = {} if current_app.debug: for scene_id in [2, 3, 4, 6]: scene = Scene.query.get(scene_id) item_list = statisitc.item_query.filter(Item.vendor_id == vendor_id, Item.scene_id == scene_id).all() if not item_list: continue items = [random.SystemRandom().choice(item_list) for _ in range(10)] data[scene_id] = {'scene': scene.scene, 'items': items_json(items)} else: for scene_id in current_app.config['ITEMS']['vendor_detail'][str(vendor_id)].keys(): scene = Scene.query.get(scene_id) items = [] for item_id in current_app.config['ITEMS']['vendor_detail'][str(vendor_id)][scene_id]: items.append(Item.query.get(item_id)) data[scene_id] = {'scene': scene.scene, 'items': items_json(items)} data = json.dumps(data) redis_set('BRAND_ITEMS', vendor_id, data, expire=86400) return Response(data, mimetype='application/json') return render_template('user/brand_detail.html')
def brand_list(): format = request.args.get('format', '', type=str) if format == 'json': data = redis_get('BRAND', 'ITEMS') if data is None: brands = statisitc.brands['available'] data = { vendor_id: { 'brand': brands[vendor_id]['brand'] } for vendor_id in brands } for vendor_id in data: if current_app.debug: item_list = Item.query.filter( Item.vendor_id == vendor_id, Item.is_deleted == False, Item.is_component == False).all() items = [ random.SystemRandom().choice(item_list) for _ in range(5) ] else: items = current_app.config['ITEMS']['brands'][str( vendor_id)] data[vendor_id]['items'] = items_json(items) data = json.dumps(data) redis_set('BRAND', 'ITEMS', data, expire=86400) return Response(data, mimetype='application/json') return render_template('user/brands.html')
def furniture(): format = request.args.get('format', '', type=str) if format == 'json': data = redis_get('STYLE', 'ITEMS') if data is None: styles = statisitc.styles['available'] data = { style_id: { 'style': styles[style_id]['style'] } for style_id in styles } for style_id in data: if current_app.debug: item_list = Item.query.filter( Item.style_id == style_id).all() items = [ random.SystemRandom().choice(item_list) for _ in range(8) ] else: items = [] for item_id in current_app.config['ITEMS']['furniture'][ str(style_id)]: items.append(Item.query.get(item_id)) data[style_id]['items'] = items_json(items) data = json.dumps(data) redis_set('STYLE', 'ITEMS', data, expire=86400) return Response(data, mimetype='application/json') return render_template('user/furniture.html')
def send_sms_captcha(template, mobile): if not redis_get(SMS_CAPTCHA_SENT, mobile): captcha_chars = sms_captcha_generator() redis_set(SMS_CAPTCHA, mobile, captcha_chars) sms_generator(template, mobile, verify_code=captcha_chars) redis_set(SMS_CAPTCHA_SENT, mobile, True, 60) return True return False
def verify(): token = request.args.get('token', '', type=str) action = request.args.get('action', '', type=str) vendor_id = redis_get(DISTRIBUTOR_REGISTER, token, delete=True) if vendor_id: session['register_permission'] = True session['vendor_id'] = vendor_id return redirect(url_for('.register')) return u'已失效'
def image_callback(): image_path = request.values.get('object', '', type=str) item_dict = redis_get('OSS', image_path, delete=True, serialize=True) if item_dict: image_name = image_path.rsplit('/', 1)[-1] image_hash = image_name.split('.', 1)[0] item_image = ItemImage(item_dict['item_id'], image_path, image_hash, item_dict['filename'][:30], 999) # 新上传的图片默认在最后 db.session.add(item_image) db.session.commit() return jsonify({'success': True, 'image': {'hash': item_image.hash, 'url': item_image.url, 'created': item_image.created}}) return jsonify({'success': False})
def navbar(): data = redis_get('INDEX_NAVBAR', 'ITEMS') if data is None: data = {} for scene_id in [2, 3, 4, 6]: # 客厅 书房 卧室 餐厅 scene = Scene.query.get(scene_id) if current_app.debug: item_list = statisitc.item_query.filter(Item.scene_id == scene_id).all() if not item_list: items = [] else: items = [random.SystemRandom().choice(item_list) for _ in range(8)] else: items = current_app.config['ITEMS']['navbars'][str(scene_id)] data[scene.id] = {'scene': scene.scene, 'items': items_json(items)} data = json.dumps(data) redis_set('INDEX_NAVBAR', 'ITEMS', data, expire=86400) return Response(data, mimetype='application/json')
def brand_list(): format = request.args.get('format', '', type=str) if format == 'json': data = redis_get('BRAND', 'ITEMS') if data is None: brands = statisitc.brands['available'] data = {vendor_id: {'brand': brands[vendor_id]['brand']} for vendor_id in brands} for vendor_id in data: if current_app.debug: item_list = Item.query.filter(Item.vendor_id == vendor_id, Item.is_deleted == False, Item.is_component == False).all() items = [random.SystemRandom().choice(item_list) for _ in range(5)] else: items = current_app.config['ITEMS']['brands'][str(vendor_id)] data[vendor_id]['items'] = items_json(items) data = json.dumps(data) redis_set('BRAND', 'ITEMS', data, expire=86400) return Response(data, mimetype='application/json') return render_template('user/brands.html')
def image_callback(): image_path = request.values.get('object', '', type=str) item_dict = redis_get('OSS', image_path, delete=True, serialize=True) if item_dict: image_name = image_path.rsplit('/', 1)[-1] image_hash = image_name.split('.', 1)[0] item_image = ItemImage(item_dict['item_id'], image_path, image_hash, item_dict['filename'][:30], 999) # 新上传的图片默认在最后 db.session.add(item_image) db.session.commit() return jsonify({ 'success': True, 'image': { 'hash': item_image.hash, 'url': item_image.url, 'created': item_image.created } }) return jsonify({'success': False})
def furniture(): format = request.args.get('format', '', type=str) if format == 'json': data = redis_get('STYLE', 'ITEMS') if data is None: styles = statisitc.styles['available'] data = {style_id: {'style': styles[style_id]['style']} for style_id in styles} for style_id in data: if current_app.debug: item_list = Item.query.filter(Item.style_id == style_id).all() items = [random.SystemRandom().choice(item_list) for _ in range(8)] else: items = [] for item_id in current_app.config['ITEMS']['furniture'][str(style_id)]: items.append(Item.query.get(item_id)) data[style_id]['items'] = items_json(items) data = json.dumps(data) redis_set('STYLE', 'ITEMS', data, expire=86400) return Response(data, mimetype='application/json') return render_template('user/furniture.html')
def vendor_detail(vendor_id): if not current_app.debug and vendor_id not in [12801, 12803, 12806, 12836]: abort(404) format = request.args.get('format', '', type=str) if format == 'json': data = redis_get('BRAND_ITEMS', vendor_id) if data is None: data = {} if current_app.debug: for scene_id in [2, 3, 4, 6]: scene = Scene.query.get(scene_id) item_list = statisitc.item_query.filter( Item.vendor_id == vendor_id, Item.scene_id == scene_id).all() if not item_list: continue items = [ random.SystemRandom().choice(item_list) for _ in range(10) ] data[scene_id] = { 'scene': scene.scene, 'items': items_json(items) } else: for scene_id in current_app.config['ITEMS']['vendor_detail'][ str(vendor_id)].keys(): scene = Scene.query.get(scene_id) items = [] for item_id in current_app.config['ITEMS'][ 'vendor_detail'][str(vendor_id)][scene_id]: items.append(Item.query.get(item_id)) data[scene_id] = { 'scene': scene.scene, 'items': items_json(items) } data = json.dumps(data) redis_set('BRAND_ITEMS', vendor_id, data, expire=86400) return Response(data, mimetype='application/json') return render_template('user/brand_detail.html')
def navbar(): data = redis_get('INDEX_NAVBAR', 'ITEMS') if data is None: data = {} for scene_id in [2, 3, 4, 6]: # 客厅 书房 卧室 餐厅 scene = Scene.query.get(scene_id) if current_app.debug: item_list = statisitc.item_query.filter( Item.scene_id == scene_id).all() if not item_list: items = [] else: items = [ random.SystemRandom().choice(item_list) for _ in range(8) ] else: items = current_app.config['ITEMS']['navbars'][str(scene_id)] data[scene.id] = {'scene': scene.scene, 'items': items_json(items)} data = json.dumps(data) redis_set('INDEX_NAVBAR', 'ITEMS', data, expire=86400) return Response(data, mimetype='application/json')