def add_customer(self, username, product, agency=None): from taurusxradius.modules.dbservice.customer_add import CustomerAdd with make_db(self.db) as db: formdata = Storage({ 'account_number': username, 'password': '******', 'area_id': '1', 'idcard': '000000', 'agency_id': str(agency.id) if agency else None, 'builder_name': None, 'giftflows': '0', 'giftdays': '0', 'charge_code': None, 'expire_date': '2017-06-27', 'fee_value': str(product.fee_price / 100.0), 'status': '1', 'realname': 'r_%s' % username, 'node_id': '1', 'account_rule': '1', 'address': u'\u6d4b\u8bd5\u7528\u6237\u5730\u5740', 'ip_address': None, 'product_id': str(product.id), 'mobile': '000000', 'months': '0', 'customer_desc': u'\u6d4b\u8bd5\u7528\u6237' }) serv = CustomerAdd(db, self.aes) cuser = serv.add(formdata) self.print_error(serv) return cuser return
def userReg(self, wsbody): formdata = Storage() formdata.node_id = self.get_ws_attr(wsbody, 'areaCode') formdata.area_id = self.get_ws_attr(wsbody, 'courtyardCode', defval='') formdata.customer_id = self.get_ws_attr(wsbody, 'userName', notnull=True) formdata.account_number = self.get_ws_attr(wsbody, 'userName', notnull=True) formdata.password = self.get_ws_attr(wsbody, 'password', notnull=True) formdata.realname = self.get_ws_attr(wsbody, 'realName') formdata.product_id = self.get_ws_attr(wsbody, 'productCode', notnull=True) formdata.expire_date = self.get_ws_attr(wsbody, 'authEndDate', notnull=True) formdata.address = self.get_ws_attr(wsbody, 'installAddress') formdata.ip_address = self.get_ws_attr(wsbody, 'ipAddress') formdata.mobile = self.get_ws_attr(wsbody, 'mobile') formdata.idcard = self.get_ws_attr(wsbody, 'idcard') formdata.fee_value = 0 formdata.giftdays = 0 formdata.giftflows = 0 formdata.agency_id = None formdata.charge_code = None formdata.months = 0 formdata.status = 1 formdata.builder_name = None formdata.customer_desc = 'BOSS\xe5\xbc\x80\xe9\x80\x9a\xe8\xb4\xa6\xe5\x8f\xb7' account = self.db.query(models.TrAccount).get(formdata.account_number) if account: return self.send_wsresp('userReg', code=Codes.ERROR_ALREADY_EXIST, UserCode='', error=u'\u7528\u6237\u5df2\u7ecf\u5b58\u5728') else: cmanager = CustomerAdd(self.db, self.aes) ret = cmanager.add(formdata) if not ret: self.send_wsresp('userReg', code=Codes.ERROR_UNKNOWN, UserCode='', error=cmanager.last_error) else: self.send_wsresp('userReg', code=Codes.SUCCESS, UserCode=formdata.account_number.strip()) return
def do_vcard(self, form, product): vcard_code = form.d.vcard_code vcard_pwd = form.d.vcard_pwd _feevalue, _expire = self.order_calc(form.d.product_id) order_id = utils.gen_order_id() formdata = Storage(form.d) formdata.order_id = order_id formdata['node_id'] = self.get_param_value('default_user_node_id', 1) formdata['area_id'] = '' formdata['fee_value'] = _feevalue formdata['expire_date'] = _expire formdata['accept_source'] = 'ssportal' formdata['giftdays'] = 0 formdata['giftflows'] = 0 formdata['ip_address'] = '' formdata['status'] = 1 formdata['vcard_code'] = vcard_code formdata['vcard_pwd'] = vcard_pwd formdata['customer_desc'] = u'客户自助充值卡开户' formdata['product_name'] = product.product_name manager = CustomerAdd(self.db, self.aes) ret = manager.add(formdata) if ret: order = self.db.query(models.TrCustomerOrder).get(order_id) logger.info(u'充值卡开户成功') self.render('alipay_return.html', order=order) else: return self.render_error(code=1, msg=u'充值卡订单处理失败 %s' % manager.last_error)
def post(self): try: phone = self.get_argument('phone') domain = self.get_argument('domain') last_send = self.session.get('sms_last_send', 0) if last_send > 0: sec = int(time.time()) - last_send if sec < 60: self.render_json(code=1, msg=u'还需等待%s秒' % sec) return self.session['sms_last_send'] = int(time.time()) self.session.save() vcode = str(time.time()).replace('.', '')[-6:] gateway = self.get_param_value('sms_gateway') apikey = self.get_param_value('sms_api_user') apisecret = self.get_param_value('sms_api_pwd') resp = yield smsapi.send_vcode(gateway, apikey, apisecret, phone, vcode) cmanager = CustomerAdd(self.db, self.aes, config=self.settings.config) customer = cmanager.add_wlan_user(domain, phone, vcode, u'hotspot sms verify join') if not customer: logger.error(cmanager.last_error) self.render_json(code=1, msg=u'自动注册失败') return self.render_json(code=0, msg='ok') except Exception as err: logger.exception(err) self.render_json(code=1, msg=u'发送短信失败')
def post(self): try: formdata = self.parse_form_request() if not formdata: return service = CustomerAdd(self.db, self.aes) ret = service.add(formdata) if ret: return self.render_success() return self.render_server_err(msg=service.last_error) except Exception as err: logger.exception(err, trace='api') return self.render_unknow(err)
def do_new_order(self, formdata): """ 开户订单结果处理 """ manager = CustomerAdd(self.db, self.aes) if manager.add(formdata): self.write(self.wxpay.generate_notify_resp(self.success)) logger.info('neworder process done', trace='wxpay', order_id=formdata.order_id) self.send_user_paynotify(formdata) else: logger.error(u'收到支付结果通知,但处理订单失败 %s' % manager.last_error, trace='wxpay')
def post(self): nodes, products = self.get_form_params() form = customer_forms.customer_batch_open_form(nodes, products) if not form.validates(source=self.get_params()): return self.render('account_batch_open_form.html', form=form) try: cmanager = CustomerAdd(self.db, self.aes, operator=self.current_user) ret = cmanager.batch_add(form.d) if not ret: return self.render('account_batch_open_form.html', form=form, msg=cmanager.last_error) except Exception as err: logger.exception(err) return self.render_error(msg=u'用户开户失败,请联系管理员:ERROR:%s' % repr(err)) self.redirect('/admin/customer')
def post(self): nodes, products, agencies = self.get_form_params() form = customer_forms.customer_open_form(nodes, products, agencies) if not form.validates(source=self.get_params()): return self.render('account_open_form.html', form=form) try: cmanager = CustomerAdd(self.db, self.aes, operator=self.current_user) _params = dict(operator_name=self.current_user.username, operator_ip=self.current_user.ipaddr) ret = cmanager.add(form.d, **_params) if not ret: return self.render('account_open_form.html', form=form, msg=cmanager.last_error) except Exception as err: logger.exception(err) return self.render_error(msg=u'用户开户失败,请联系管理员:ERROR:%s' % repr(err)) CustomerBuildAccountHandler.set_session_number(form.d.account_rule, '') self.redirect(self.detail_url_fmt(form.d.account_number))
def post(self, order_type): isok = self.alipay.notify_verify(self.get_params()) if not isok: self.write('failure') logger.info(u'收到支付宝订单通知,订单无效', trace='alipay', **self.get_params()) return order_id = self.get_argument('out_trade_no') if self.db.query(models.TrCustomerOrder).filter_by( order_id=order_id, pay_status=1).count() == 1: self.write('success') return formdata = self.paycache.get(order_paycaache_key(order_id)) if not formdata: logger.error(u'收到支付宝订单通知,但是本地缓存查不到订单%s' % order_id, trace='alipay') self.write('failure') return ret = False if order_type == 'new': manager = CustomerAdd(self.db, self.aes) ret = manager.add(formdata) if order_type == 'renew': manager = AccountRenew(self.db, self.aes) ret = manager.renew(formdata) if order_type == 'charge': manager = AccountChange(self.db, self.aes) ret = manager.charge(formdata) if ret: self.write('success') logger.info(u'收到支付宝订单通知,处理成功', trace='alipay', account_number=formdata.account_number, order_id=formdata.order_id) else: logger.error(u'订单处理失败', trace='alipay')
def get(self, order_type): isok = self.alipay.notify_verify(self.get_params()) if not isok: logger.info(u'收到支付宝订单通知,订单校验无效', trace='alipay', **self.get_params()) return self.render_error(code=1, msg=u'订单校验无效') order_id = self.get_argument('out_trade_no') order = self.db.query(models.TrCustomerOrder).get(order_id) if order and order.pay_status == 1: return self.render('alipay_return.html', order=order) formdata = self.paycache.get(order_paycaache_key(order_id)) if not formdata: logger.error(u'收到支付宝订单通知,但是本地查不到订单%s' % order_id, trace='alipay') return self.render_error(code=1, msg=u'订单不存在') ret = False if order_type == 'new': manager = CustomerAdd(self.db, self.aes) ret = manager.add(formdata) if order_type == 'renew': manager = AccountRenew(self.db, self.aes) ret = manager.renew(formdata) if order_type == 'charge': manager = AccountCharge(self.db, self.aes) ret = manager.charge(formdata) if ret: order = self.db.query(models.TrCustomerOrder).get(order_id) logger.info(u'收到支付宝订单通知,处理成功', trace='alipay', account_number=formdata.account_number, order_id=order_id) self.render('alipay_return.html', order=order) else: return self.render_error(code=1, msg=u'订单处理失败 %s' % manager.last_error)
def test_add_boflows_customer(self): pid = None with make_db(self.db) as db: formdata = Storage({ 'product_policy': '5', 'bind_mac': '0', 'bind_vlan': '0', 'fee_flows': '30', 'fee_price': '5', 'fee_months': '0', 'fee_times': '0', 'free_auth': '1', 'free_auth_uprate': '1', 'free_auth_downrate': '1', 'concur_number': '0', 'output_max_limit': '10', 'input_max_limit': '10', 'product_name': u'\u4e70\u65ad\u6d41\u91cf30G5\u5143' }) serv = ProductService(db, self.aes) item = serv.add(formdata) self.print_error(serv) raise item or AssertionError pid = item.id with make_db(self.db) as db: formdata = Storage({ 'account_number': 'test07', 'password': '******', 'area_id': '1', 'idcard': '000000', 'agency_id': None, 'builder_name': None, 'giftflows': '0', 'giftdays': '0', 'charge_code': None, 'expire_date': '3000-06-27', 'fee_value': '5.0', 'status': '1', 'realname': 'test07', 'node_id': '1', 'account_rule': '1', 'address': u'\u6d4b\u8bd5\u7528\u6237\u5730\u5740', 'ip_address': None, 'product_id': pid, 'mobile': '000000', 'months': '0', 'customer_desc': u'\u4e70\u65ad\u6d41\u91cf\u6d4b\u8bd5\u7528\u6237' }) serv = CustomerAdd(db, self.aes) ret = serv.add(formdata) self.print_error(serv) raise ret or AssertionError return
def test_add_ppmonth_customer(self): pid = None with make_db(self.db) as db: formdata = Storage({ 'product_policy': '0', 'bind_mac': '0', 'bind_vlan': '0', 'fee_times': '0', 'fee_flows': '0', 'fee_price': '30', 'fee_months': '0', 'free_auth': '1', 'free_auth_uprate': '1', 'free_auth_downrate': '1', 'output_max_limit': '10', 'input_max_limit': '10', 'concur_number': '0', 'product_name': '\xe9\xa2\x84\xe4\xbb\x98\xe8\xb4\xb9\xe5\x8c\x85\xe6\x9c\x8810M30\xe5\x85\x83' }) serv = ProductService(db, self.aes) item = serv.add(formdata) self.print_error(serv) raise item or AssertionError pid = item.id with make_db(self.db) as db: formdata = Storage({ 'account_number': 'test02', 'password': '******', 'area_id': '1', 'idcard': '000000', 'builder_name': None, 'agency_id': None, 'giftflows': '0', 'giftdays': '0', 'charge_code': None, 'expire_date': '2017-06-27', 'fee_value': '360.00', 'status': '1', 'realname': 'test02', 'node_id': '1', 'account_rule': '1', 'address': u'\u6d4b\u8bd5\u7528\u6237\u5730\u5740', 'ip_address': None, 'product_id': pid, 'mobile': '000000', 'months': '12', 'customer_desc': u'\u9884\u4ed8\u8d39\u5305\u6708\u6d4b\u8bd5\u7528\u6237' }) serv = CustomerAdd(db, self.aes) ret = serv.add(formdata) self.print_error(serv) raise ret or AssertionError return
def post(self): is_smsvcode = int( self.get_param_value('usrportal_smsvcode_required', 0)) is_email = int(self.get_param_value('usrportal_email_required', 0)) form = register_forms.register_form(is_smsvcode, is_email) _validates, _msg = form.validatesjson(source=self.get_params()) if not _validates: return self.render_json(code=1, json=1, msg=_msg) account_number = '' mobile = '' email = '' if is_smsvcode: #开启短信验证,使用手机号作为ID mobile = form.d.mobile account_number = mobile elif is_email: #开启邮件验证,使用邮箱地址作为ID email = form.d.email account_number = email else: # 否则用户自定义ID account_number = form.d.account_number password = form.d.password confirmpassword = form.d.confirmpassword if not account_number: errmsg = u'请填写用户名' if is_smsvcode: errmsg = u'请填写手机号码' elif is_email: errmsg = u'请填写邮箱地址' return self.render_json(code=1, msg=errmsg) if not password: return self.render_json(code=1, msg=u'请填写密码') if password != confirmpassword: return self.render_json(code=1, msg=u'两次密码输入不一致') account = self.db.query(models.TrAccount).get(account_number) if account_number and account: errmsg = u'用户帐号[%s]已经存在' % (account_number) if is_smsvcode: errmsg = u'手机号帐号[%s]已经存在' % (account_number) elif is_email: errmsg = u'邮箱帐号[%s]已经存在' % (account_number) return self.render_json(code=1, msg=errmsg) if is_smsvcode: #开启短信验证 customer = self.db.query( models.TrCustomer).filter_by(mobile=mobile).scalar() if customer: return self.render_json( code=1, msg=u'手机号[%s]被其他账号绑定,如果不是您正在使用的帐号,请联系管理员进行处理!' % (mobile)) smsvcode = self.get_argument('vcode', '') if account_number and not smsvcode: return self.render_json(code=1, msg=u'验证码不能为空') logger.info('usrportal.sms.vcode = %s ' % self.cache.get( 'usrportal.sms.vcode.{}'.format(account_number))) if account_number and smsvcode and self.cache.get( 'usrportal.sms.vcode.{}'.format( account_number)) != smsvcode: return self.render_json(code=1, msg=u'验证码不匹配') elif is_email: #开启邮件验证 customer = self.db.query( models.TrCustomer).filter_by(email=email).scalar() if customer: return self.render_json( code=1, msg=u'邮箱[%s]被其他账号绑定,如果不是您正在使用的帐号,请联系管理员进行处理!' % (email)) # 添加帐号信息、用户信息 cmanager = CustomerAdd(self.db, self.aes) product_id = self.get_param_value( 'default_product_policy', 'HOLD-000000-NONE') # 从参数的默认资费策略中读取默认产品ID form = register_forms.register_customer_open_form() form.node_id.set_value('1') form.area_id.set_value('1') form.realname.set_value(account_number) form.mobile.set_value(mobile) form.email.set_value(email) form.account_number.set_value(account_number) form.password.set_value(password) form.product_id.set_value(product_id) _fee_value, _expire_date = self.order_calc(product_id) form.fee_value.set_value(_fee_value) if _expire_date == datetime.datetime.now().strftime('%Y-%m-%d'): """如果有效期与当前日期相等,则将有效期减一天,使帐号立即失效""" _expire_date = datetime.datetime.strptime( _expire_date, '%Y-%m-%d') - datetime.timedelta(days=1) _expire_date = _expire_date.strftime('%Y-%m-%d') form.expire_date.set_value(_expire_date) form.billing_type.set_value('1') _params = dict(operator_name=account_number, operator_ip=self.request.remote_ip) ret = cmanager.add(form.d, **_params) if not ret: return self.render_json(code=1, msg=cmanager.last_error) self.db.commit() account = self.db.query(models.TrAccount).get(account_number) if not account: return self.render_json(code=1, msg=u'帐号[%s]添加异常' % (account_number)) customer = self.db.query(models.TrCustomer).get(account.customer_id) if not customer: return self.render_json(code=1, msg=u'用户[%s]添加异常' % (account_number)) if is_smsvcode: customer.mobile_active = 1 self.db.commit() return self.render_json(code=0, msg=u'恭喜 %s ,手机帐号已成功注册!' % (str(account_number))) elif is_email: #开启邮件验证,发送激活验证邮件 uuid = utils.get_uuid() token = QXToken( '%s-%s-%s' % (customer.customer_id, customer.mobile, customer.email), uuid) strToken = token.generate_auth_token() customer.active_code = uuid customer.token = strToken self.db.commit() topic = 'TaurusXRadius注册激活邮件!' content = "尊敬的用户:" + str(account_number) + "\n\n\ 您好!\n\n\n\ 感谢您注册TaurusXRadius,请点击以下链接完成注册: \n\ http://" + self.request.host + "/usrportal/register/confirm?uuid=" + str( uuid) + "&token=" + str(strToken) + " \n\ " send_mail_self(self, email, topic, content) msgEmail = str(email[0:1] + 3 * '*' + email[email.find('@'):]) return self.render_json( code=0, msg=u'我们已经将激活邮箱帐号的链接发送到你的邮箱(%s),请前往您的邮箱点击链接,激活您的帐号。' % (msgEmail)) else: return self.render_json(code=0, msg=u'恭喜 %s ,用户帐号已成功注册!' % (str(account_number)))