示例#1
0
def card_list(db, render):
    product_id = request.params.get('product_id')
    card_type = request.params.get('card_type') 
    card_status = request.params.get('card_status')
    batch_no = request.params.get('batch_no')
    query_begin_time = request.params.get('query_begin_time')
    query_end_time = request.params.get('query_end_time')
    
    _query = db.query(models.SlcRechargerCard)
    if product_id and card_type == '0':
        _query = _query.filter(models.SlcRechargerCard.product_id==product_id)
    if card_type:
        _query = _query.filter(models.SlcRechargerCard.card_type==card_type)
    if batch_no:
        _query = _query.filter(models.SlcRechargerCard.batch_no==batch_no)
    if card_status:
        _query = _query.filter(models.SlcRechargerCard.card_status==card_status)
    if query_begin_time:
        _query = _query.filter(models.SlcRechargerCard.create_time >= query_begin_time+' 00:00:00')
    if query_end_time:
        _query = _query.filter(models.SlcRechargerCard.create_time <= query_end_time+' 23:59:59')
    
    products = db.query(models.SlcRadProduct).filter(
        models.SlcRadProduct.product_status == 0,
        models.SlcRadProduct.product_policy.in_([0,2,3,5])
    )
    if request.path == '/list':
        print "total:",_query.count()
        return render("card_list", 
            page_data = get_page_data(_query),
            card_types = card_forms.card_types,
            card_states = card_forms.card_states,
            products = products,
            colors = {0:'',1:'class="success"',2:'class="warning"',3:'class="danger"'},
            **request.params
        )
    elif request.path == '/export':
        data = Dataset()
        data.append((
            u'批次号',u'充值卡号',u'充值卡密码',u'充值卡类型',u'状态',
            u'资费id', u'面值/售价',u"授权月数",u"授权时长(小时)",u"授权流量(MB)",u"过期时间",u'创建时间'
         ))
        print "total:",_query.count()
        for i in _query:
            data.append((
                i.batch_no, i.card_number, utils.decrypt(i.card_passwd),card_forms.card_types[i.card_type],
                card_forms.card_states[i.card_status],get_product_name(db,i.product_id),utils.fen2yuan(i.fee_value),
                i.months,utils.sec2hour(i.times),utils.kb2mb(i.flows),i.expire_date,i.create_time
            ))
        name = u"RADIUS-CARD-" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S") + ".xls"
        return export_file(name,data)
示例#2
0
def portal_auth(db, render):
    user = request.params.get("user")
    token = request.params.get("token")
    if not user:return abort(403,'user is empty')
    if not token:return abort(403,'token is empty')
    account = db.query(models.SlcRadAccount).filter_by(
        account_number=user
    ).first()
    if not account:
        return abort(403,'user not exists')
    secret = get_param_value(db,"portal_secret")
    date = utils.get_currdate()
    _token = md5("%s%s%s%s"%(user,utils.decrypt(account.password),secret,date)).hexdigest()
    if _token == token:
        member = db.query(models.SlcMember).get(account.member_id)
        set_cookie('customer_id',member.member_id,path="/")
        set_cookie('customer',member.member_name,path="/")
        set_cookie('customer_login_time', utils.get_currtime(),path="/")
        set_cookie('customer_login_ip', request.remote_addr,path="/") 
        redirect("/")
    else:
        return abort(403,'token is invalid')
示例#3
0
def password_update_post(db, render):
    form = forms.password_update_form()
    if not form.validates(source=request.forms):
        return render("base_form", form=form)
        
    account = db.query(models.SlcRadAccount).filter_by(account_number=form.d.account_number).first()
    if not account:
        return render("base_form", form=form,msg=u'没有这个账号')
        
    if account.member_id != get_cookie("customer_id"):
        return render("base_form", form=form,msg=u'该账号用用户不匹配')
    
    if utils.decrypt(account.password) !=  form.d.old_password:
        return render("base_form", form=form,msg=u'旧密码不正确')
        
    if form.d.new_password != form.d.new_password2:
        return render("base_form", form=form,msg=u'确认新密码不匹配')
    
    account.password =  utils.encrypt(form.d.new_password)
    db.commit()
    websock.update_cache("account",account_number=account.account_number)
    redirect("/")
示例#4
0
def portal_auth(db):
    user = request.params.get("user")
    token = request.params.get("token")
    if not user: return abort(403, 'user is empty')
    if not token: return abort(403, 'token is empty')
    account = db.query(
        models.SlcRadAccount).filter_by(account_number=user).first()
    if not account:
        return abort(403, 'user not exists')
    secret = get_param_value(db, "portal_secret")
    date = utils.get_currdate()
    _token = md5(
        "%s%s%s%s" %
        (user, utils.decrypt(account.password), secret, date)).hexdigest()
    if _token == token:
        member = db.query(models.SlcMember).get(account.member_id)
        set_cookie('customer_id', member.member_id, path="/")
        set_cookie('customer', member.member_name, path="/")
        set_cookie('customer_login_time', utils.get_currtime(), path="/")
        set_cookie('customer_login_ip', request.remote_addr, path="/")
        redirect("/")
    else:
        return abort(403, 'token is invalid')
示例#5
0
def password_update_post(db):
    form = forms.password_update_form()
    if not form.validates(source=request.forms):
        return render("base_form", form=form)

    account = db.query(models.SlcRadAccount).filter_by(
        account_number=form.d.account_number).first()
    if not account:
        return render("base_form", form=form, msg=u'没有这个账号')

    if account.member_id != get_cookie("customer_id"):
        return render("base_form", form=form, msg=u'该账号用用户不匹配')

    if utils.decrypt(account.password) != form.d.old_password:
        return render("base_form", form=form, msg=u'旧密码不正确')

    if form.d.new_password != form.d.new_password2:
        return render("base_form", form=form, msg=u'确认新密码不匹配')

    account.password = utils.encrypt(form.d.new_password)
    db.commit()
    websock.update_cache("account", account_number=account.account_number)
    redirect("/")
示例#6
0
def member_query(db, render):
    node_id = request.params.get('node_id')
    realname = request.params.get('realname')
    idcard = request.params.get('idcard')
    mobile = request.params.get('mobile')
    user_name = request.params.get('user_name')
    status = request.params.get('status')
    product_id = request.params.get('product_id')
    address = request.params.get('address')
    expire_days = request.params.get('expire_days')
    opr_nodes = get_opr_nodes(db)
    _query = db.query(
        models.SlcMember,
        models.SlcRadAccount,
        models.SlcRadProduct.product_name,
        models.SlcNode.node_desc
    ).filter(
        models.SlcRadProduct.id == models.SlcRadAccount.product_id,
        models.SlcMember.member_id == models.SlcRadAccount.member_id,
        models.SlcNode.id == models.SlcMember.node_id
    )

    _now = datetime.datetime.now()

    if idcard:
        _query = _query.filter(models.SlcMember.idcard == idcard)
    if mobile:
        _query = _query.filter(models.SlcMember.mobile == mobile)
    if node_id:
        _query = _query.filter(models.SlcMember.node_id == node_id)
    else:
        _query = _query.filter(models.SlcMember.node_id.in_([i.id for i in opr_nodes]))
    if realname:
        _query = _query.filter(models.SlcMember.realname.like('%' + realname + '%'))
    if user_name:
        _query = _query.filter(models.SlcRadAccount.account_number.like('%' + user_name + '%'))

    #用户状态判断
    if status:
        if status == '4':
            _query = _query.filter(models.SlcRadAccount.expire_date <= _now.strftime("%Y-%m-%d"))
        elif status == '1':
            _query = _query.filter(
                models.SlcRadAccount.status == status,
                models.SlcRadAccount.expire_date >= _now.strftime("%Y-%m-%d")
            )
        else:
            _query = _query.filter(models.SlcRadAccount.status == status)

    if product_id:
        _query = _query.filter(models.SlcRadAccount.product_id == product_id)
    if address:
        _query = _query.filter(models.SlcMember.address.like('%' + address + '%'))
    if expire_days:
        _days = int(expire_days)
        td = datetime.timedelta(days=_days)
        edate = (_now + td).strftime("%Y-%m-%d")
        _query = _query.filter(models.SlcRadAccount.expire_date <= edate)
        _query = _query.filter(models.SlcRadAccount.expire_date >= _now.strftime("%Y-%m-%d"))

    if request.path == '/':
        return render("bus_member_list",
                      page_data=get_page_data(_query),
                      node_list=opr_nodes,
                      products=db.query(models.SlcRadProduct),
                      **request.params)
    elif request.path == "/export":
        data = Dataset()
        data.append((
            u'区域', u'姓名', u'证件号', u'邮箱', u'联系电话', u'地址',
            u'用户账号', u'密码', u'资费', u'过期时间', u'余额(元)',
            u'时长(小时)', u'流量(MB)', u'并发数', u'ip地址', u'状态', u'创建时间'
        ))
        for i, j, _product_name, _node_desc in _query:
            data.append((
                _node_desc, i.realname, i.idcard, i.email, i.mobile, i.address,
                j.account_number, utils.decrypt(j.password), _product_name,
                j.expire_date, utils.fen2yuan(j.balance),
                utils.sec2hour(j.time_length), utils.kb2mb(j.flow_length), j.user_concur_number, j.ip_address,
                forms.user_state[j.status], j.create_time
            ))
        name = u"RADIUS-USER-" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S") + ".xls"
        return export_file(name, data)
示例#7
0
def decrypt_data(db):
    msg_data = request.params.get('data')
    return dict(code=0, data=utils.decrypt(msg_data))
示例#8
0
def decrypt_data(db):    
    msg_data = request.params.get('data')
    return dict(code=0,data=utils.decrypt(msg_data))
示例#9
0
def account_recharge(db):
    form = forms.recharge_form()
    if not form.validates(source=request.forms):
        return render("base_form", form=form)
    if vcache.is_over(get_cookie("customer_id"), form.d.recharge_card):
        return render("base_form",
                      form=form,
                      msg=u"该充值卡一小时内密码输入错误超过5次,请一小时后再试")

    # 1 check card
    card = db.query(models.SlcRechargerCard).filter_by(
        card_number=form.d.recharge_card).first()
    check_result = check_card(card)
    if check_result['code'] > 0:
        return render('base_form', form=form, msg=check_result['data'])

    if utils.decrypt(card.card_passwd) != form.d.recharge_pwd:
        vcache.incr(get_cookie("customer_id"), form.d.recharge_card)
        errs = vcache.errs(get_cookie("customer_id"), form.d.recharge_card)
        return render('base_form', form=form, msg=u"充值卡密码错误%s次" % errs)

    vcache.clear(get_cookie("customer_id"), form.d.recharge_card)

    # 2 check account
    account = db.query(models.SlcRadAccount).filter_by(
        account_number=form.d.account_number).first()
    if not account:
        return render("base_form", form=form, msg=u'没有这个账号')
    if account.member_id != get_cookie("customer_id"):
        return render("base_form", form=form, msg=u'该账号用用户不匹配')
    if account.status not in (UsrNormal, UsrExpire):
        return render("base_form", form=form, msg=u'只有正常状态的用户才能充值')

    # 3 check product
    user_product = db.query(models.SlcRadProduct).get(account.product_id)
    if card.card_type == ProductCard and card.product_id != account.product_id:
        return render("base_form", form=form, msg=u'您使用的是资费卡,但资费套餐与该账号资费不匹配')
    if card.card_type == BalanceCard and user_product.product_policy not in (
            PPTimes, PPFlow):
        return render("base_form",
                      form=form,
                      msg=u'您使用的是余额卡,只能为预付费时长或预付费流量账号充值')

    # 4 start recharge
    accept_log = models.SlcRadAcceptLog()
    accept_log.accept_type = 'charge'
    accept_log.accept_source = 'customer'
    accept_log.account_number = form.d.account_number
    accept_log.accept_time = utils.get_currtime()
    accept_log.operator_name = "customer"
    accept_log.accept_desc = u"用户自助充值:上网账号:%s,充值卡:%s" % (form.d.account_number,
                                                         form.d.recharge_card)
    db.add(accept_log)
    db.flush()
    db.refresh(accept_log)

    _datetime = utils.get_currtime()
    order_fee = 0
    balance = 0
    expire_date = account.expire_date
    d_expire_date = datetime.datetime.strptime(expire_date, "%Y-%m-%d")
    # 预付费包月
    if user_product.product_policy == PPMonth:
        expire_date = utils.add_months(d_expire_date,
                                       card.months).strftime("%Y-%m-%d")
        order_fee = decimal.Decimal(user_product.fee_price) * decimal.Decimal(
            card.months)
        order_fee = int(order_fee.to_integral_value())
    # 买断包月,买断时长,买断流量
    if user_product.product_policy in (BOMonth, BOTimes, BOFlows):
        expire_date = utils.add_months(d_expire_date,
                                       card.months).strftime("%Y-%m-%d")
        order_fee = user_product.fee_price
    #预付费时长,预付费流量
    elif user_product.product_policy in (PPTimes, PPFlow):
        balance = card.fee_value

    order = models.SlcMemberOrder()
    order.order_id = utils.gen_order_id()
    order.member_id = get_cookie("customer_id")
    order.product_id = account.product_id
    order.account_number = form.d.account_number
    order.order_fee = order_fee
    order.actual_fee = card.fee_value
    order.pay_status = 1
    order.accept_id = accept_log.id
    order.order_source = 'customer'
    order.create_time = _datetime
    order.order_desc = u"用户自助充值,充值卡[ %s ]" % form.d.recharge_card
    db.add(order)

    account.expire_date = expire_date
    account.balance += balance
    account.time_length += card.times
    account.flow_length += card.flows
    account.status = 1

    card.card_status = CardUsed

    db.commit()
    redirect("/")
示例#10
0
def account_open(db):
    form = forms.account_open_form()
    if not form.validates(source=request.forms):
        return render("card_open_form", form=form)
    if vcache.is_over(get_cookie("customer_id"), form.d.recharge_card):
        return render("card_open_form",
                      form=form,
                      msg=u"该充值卡一小时内密码输入错误超过5次,请一小时后再试")

    card = db.query(models.SlcRechargerCard).filter_by(
        card_number=form.d.recharge_card).first()
    check_result = check_card(card)
    if check_result['code'] > 0:
        return render('card_open_form', form=form, msg=check_result['data'])

    if utils.decrypt(card.card_passwd) != form.d.recharge_pwd:
        vcache.incr(get_cookie("customer_id"), form.d.recharge_card)
        errs = vcache.errs(get_cookie("customer_id"), form.d.recharge_card)
        return render('card_open_form', form=form, msg=u"充值卡密码错误%s次" % errs)

    vcache.clear(get_cookie("customer_id"), form.d.recharge_card)

    # start open
    accept_log = models.SlcRadAcceptLog()
    accept_log.accept_type = 'open'
    accept_log.accept_source = 'customer'
    accept_log.account_number = form.d.account_number
    accept_log.accept_time = utils.get_currtime()
    accept_log.operator_name = "customer"
    accept_log.accept_desc = u"用户自助开户:%s" % (form.d.account_number)
    db.add(accept_log)
    db.flush()
    db.refresh(accept_log)

    _datetime = utils.get_currtime()
    order_fee = 0
    balance = 0
    expire_date = utils.add_months(datetime.datetime.now(),
                                   card.months).strftime("%Y-%m-%d")
    product = db.query(models.SlcRadProduct).get(form.d.product_id)
    # 预付费包月
    if product.product_policy == PPMonth:
        order_fee = decimal.Decimal(product.fee_price) * decimal.Decimal(
            card.months)
        order_fee = int(order_fee.to_integral_value())
    # 买断包月,买断时长,买断流量
    elif product.product_policy in (BOMonth, BOTimes, BOFlows):
        order_fee = int(product.fee_price)
    #预付费时长,预付费流量
    elif product.product_policy in (PPTimes, PPFlow):
        balance = card.fee_value
        expire_date = '3000-11-11'

    order = models.SlcMemberOrder()
    order.order_id = utils.gen_order_id()
    order.member_id = get_cookie("customer_id")
    order.product_id = product.id
    order.account_number = form.d.account_number
    order.order_fee = order_fee
    order.actual_fee = card.fee_value
    order.pay_status = 1
    order.accept_id = accept_log.id
    order.order_source = 'customer'
    order.create_time = _datetime
    order.order_desc = u"用户使用充值卡[ %s ]开户" % form.d.recharge_card
    db.add(order)

    account = models.SlcRadAccount()
    account.account_number = form.d.account_number
    account.ip_address = ''
    account.member_id = get_cookie("customer_id")
    account.product_id = order.product_id
    account.install_address = ''
    account.mac_addr = ''
    account.password = utils.encrypt(form.d.password)
    account.status = 1
    account.balance = balance
    account.time_length = int(product.fee_times)
    account.flow_length = int(product.fee_flows)
    account.expire_date = expire_date
    account.user_concur_number = product.concur_number
    account.bind_mac = product.bind_mac
    account.bind_vlan = product.bind_vlan
    account.vlan_id = 0
    account.vlan_id2 = 0
    account.create_time = _datetime
    account.update_time = _datetime
    db.add(account)

    clog = models.SlcRechargeLog()
    clog.member_id = get_cookie("customer_id")
    clog.card_number = card.card_number
    clog.account_number = form.d.account_number
    clog.recharge_status = 0
    clog.recharge_time = _datetime
    db.add(clog)

    card.card_status = CardUsed

    db.commit()
    redirect('/')
示例#11
0
def card_list(db, render):
    product_id = request.params.get('product_id')
    card_type = request.params.get('card_type')
    card_status = request.params.get('card_status')
    batch_no = request.params.get('batch_no')
    query_begin_time = request.params.get('query_begin_time')
    query_end_time = request.params.get('query_end_time')

    _query = db.query(models.SlcRechargerCard)
    if product_id and card_type == '0':
        _query = _query.filter(
            models.SlcRechargerCard.product_id == product_id)
    if card_type:
        _query = _query.filter(models.SlcRechargerCard.card_type == card_type)
    if batch_no:
        _query = _query.filter(models.SlcRechargerCard.batch_no == batch_no)
    if card_status:
        _query = _query.filter(
            models.SlcRechargerCard.card_status == card_status)
    if query_begin_time:
        _query = _query.filter(
            models.SlcRechargerCard.create_time >= query_begin_time +
            ' 00:00:00')
    if query_end_time:
        _query = _query.filter(
            models.SlcRechargerCard.create_time <= query_end_time +
            ' 23:59:59')

    products = db.query(models.SlcRadProduct).filter(
        models.SlcRadProduct.product_status == 0,
        models.SlcRadProduct.product_policy.in_([0, 2, 3, 5]))
    if request.path == '/list':
        print "total:", _query.count()
        return render("card_list",
                      page_data=get_page_data(_query),
                      card_types=card_forms.card_types,
                      card_states=card_forms.card_states,
                      products=products,
                      colors={
                          0: '',
                          1: 'class="success"',
                          2: 'class="warning"',
                          3: 'class="danger"'
                      },
                      **request.params)
    elif request.path == '/export':
        data = Dataset()
        data.append(
            (u'批次号', u'充值卡号', u'充值卡密码', u'充值卡类型', u'状态', u'资费id', u'面值/售价',
             u"授权月数", u"授权时长(小时)", u"授权流量(MB)", u"过期时间", u'创建时间'))
        print "total:", _query.count()
        for i in _query:
            data.append(
                (i.batch_no, i.card_number, utils.decrypt(i.card_passwd),
                 card_forms.card_types[i.card_type],
                 card_forms.card_states[i.card_status],
                 get_product_name(db, i.product_id), utils.fen2yuan(
                     i.fee_value), i.months, utils.sec2hour(i.times),
                 utils.kb2mb(i.flows), i.expire_date, i.create_time))
        name = u"RADIUS-CARD-" + datetime.datetime.now().strftime(
            "%Y%m%d-%H%M%S") + ".xls"
        return export_file(name, data)
示例#12
0
def account_recharge(db):
    form = forms.recharge_form()
    if not form.validates(source=request.forms):
        return render("base_form", form=form)
    if vcache.is_over(get_cookie("customer_id"),form.d.recharge_card):
         return render("base_form", form=form,msg=u"该充值卡一小时内密码输入错误超过5次,请一小时后再试")
    
    # 1 check card     
    card = db.query(models.SlcRechargerCard).filter_by(card_number=form.d.recharge_card).first()  
    check_result = check_card(card)
    if check_result['code'] > 0:
        return render('base_form',form=form,msg=check_result['data'])

    if utils.decrypt(card.card_passwd) != form.d.recharge_pwd:
        vcache.incr(get_cookie("customer_id"),form.d.recharge_card)
        errs = vcache.errs(get_cookie("customer_id"),form.d.recharge_card)
        return render('base_form',form=form,msg=u"充值卡密码错误%s次"%errs)   
        
    vcache.clear(get_cookie("customer_id"),form.d.recharge_card)
        
    # 2 check account
    account = db.query(models.SlcRadAccount).filter_by(account_number=form.d.account_number).first()
    if not account:
        return render("base_form", form=form,msg=u'没有这个账号')
    if account.member_id != get_cookie("customer_id"):
        return render("base_form", form=form,msg=u'该账号用用户不匹配')
    if account.status not in (UsrNormal,UsrExpire):
        return render("base_form", form=form,msg=u'只有正常状态的用户才能充值')
    
    # 3 check product
    user_product = db.query(models.SlcRadProduct).get(account.product_id)    
    if card.card_type == ProductCard and card.product_id != account.product_id:
        return render("base_form", form=form,msg=u'您使用的是资费卡,但资费套餐与该账号资费不匹配')
    if card.card_type == BalanceCard and user_product.product_policy not in (PPTimes,PPFlow):
        return render("base_form", form=form,msg=u'您使用的是余额卡,只能为预付费时长或预付费流量账号充值')
    
    # 4 start recharge
    accept_log = models.SlcRadAcceptLog()
    accept_log.accept_type = 'charge'
    accept_log.accept_source = 'customer'
    accept_log.account_number = form.d.account_number
    accept_log.accept_time = utils.get_currtime()
    accept_log.operator_name = "customer"
    accept_log.accept_desc = u"用户自助充值:上网账号:%s,充值卡:%s"%(form.d.account_number,form.d.recharge_card)
    db.add(accept_log)
    db.flush()
    db.refresh(accept_log) 
    
    _datetime = utils.get_currtime()
    order_fee = 0
    balance = 0
    expire_date = account.expire_date
    d_expire_date = datetime.datetime.strptime(expire_date,"%Y-%m-%d")
    # 预付费包月
    if user_product.product_policy == PPMonth:
        expire_date = utils.add_months(d_expire_date,card.months).strftime("%Y-%m-%d")
        order_fee = decimal.Decimal(user_product.fee_price) * decimal.Decimal(card.months)
        order_fee = int(order_fee.to_integral_value())
    # 买断包月,买断时长,买断流量
    if user_product.product_policy in (BOMonth,BOTimes,BOFlows):
        expire_date = utils.add_months(d_expire_date,card.months).strftime("%Y-%m-%d")
        order_fee = user_product.fee_price
    #预付费时长,预付费流量
    elif user_product.product_policy in (PPTimes,PPFlow):
        balance = card.fee_value
    
    order = models.SlcMemberOrder()
    order.order_id = utils.gen_order_id()
    order.member_id = get_cookie("customer_id")
    order.product_id = account.product_id
    order.account_number = form.d.account_number
    order.order_fee = order_fee
    order.actual_fee = card.fee_value
    order.pay_status = 1
    order.accept_id = accept_log.id
    order.order_source = 'customer'
    order.create_time = _datetime
    order.order_desc = u"用户自助充值,充值卡[ %s ]"%form.d.recharge_card
    db.add(order)
         
    account.expire_date = expire_date
    account.balance += balance
    account.time_length += card.times
    account.flow_length += card.flows
    account.status = 1
    
    card.card_status = CardUsed
    
    db.commit()
    redirect("/") 
示例#13
0
def account_open(db):
    form = forms.account_open_form()
    if not form.validates(source=request.forms):
        return render("card_open_form", form=form)
    if vcache.is_over(get_cookie("customer_id"),form.d.recharge_card):
         return render("card_open_form", form=form,msg=u"该充值卡一小时内密码输入错误超过5次,请一小时后再试") 

    card = db.query(models.SlcRechargerCard).filter_by(card_number=form.d.recharge_card).first()  
    check_result = check_card(card)
    if check_result['code'] > 0:
        return render('card_open_form',form=form,msg=check_result['data'])

    if utils.decrypt(card.card_passwd) != form.d.recharge_pwd:
        vcache.incr(get_cookie("customer_id"),form.d.recharge_card)
        errs = vcache.errs(get_cookie("customer_id"),form.d.recharge_card)
        return render('card_open_form',form=form,msg=u"充值卡密码错误%s次"%errs)
    
    vcache.clear(get_cookie("customer_id"),form.d.recharge_card)
    
    # start open
    accept_log = models.SlcRadAcceptLog()
    accept_log.accept_type = 'open'
    accept_log.accept_source = 'customer'
    accept_log.account_number = form.d.account_number
    accept_log.accept_time = utils.get_currtime()
    accept_log.operator_name = "customer"
    accept_log.accept_desc = u"用户自助开户:%s"%(form.d.account_number)
    db.add(accept_log)
    db.flush()
    db.refresh(accept_log)
    
    _datetime = utils.get_currtime()
    order_fee = 0
    balance = 0
    expire_date = utils.add_months(datetime.datetime.now(),card.months).strftime("%Y-%m-%d") 
    product = db.query(models.SlcRadProduct).get(form.d.product_id)
    # 预付费包月
    if product.product_policy == PPMonth:
        order_fee = decimal.Decimal(product.fee_price) * decimal.Decimal(card.months)
        order_fee = int(order_fee.to_integral_value())
    # 买断包月,买断时长,买断流量
    elif product.product_policy in (BOMonth,BOTimes,BOFlows):
        order_fee = int(product.fee_price)
    #预付费时长,预付费流量
    elif product.product_policy in (PPTimes,PPFlow):
        balance = card.fee_value
        expire_date = '3000-11-11'
    
    order = models.SlcMemberOrder()
    order.order_id = utils.gen_order_id()
    order.member_id = get_cookie("customer_id")
    order.product_id = product.id
    order.account_number = form.d.account_number
    order.order_fee = order_fee
    order.actual_fee = card.fee_value
    order.pay_status = 1
    order.accept_id = accept_log.id
    order.order_source = 'customer'
    order.create_time = _datetime
    order.order_desc = u"用户使用充值卡[ %s ]开户"%form.d.recharge_card
    db.add(order)
    
    account = models.SlcRadAccount()
    account.account_number = form.d.account_number
    account.ip_address = ''
    account.member_id = get_cookie("customer_id")
    account.product_id = order.product_id
    account.install_address = ''
    account.mac_addr = ''
    account.password = utils.encrypt(form.d.password)
    account.status = 1
    account.balance = balance
    account.time_length = int(product.fee_times)
    account.flow_length = int(product.fee_flows)
    account.expire_date = expire_date
    account.user_concur_number = product.concur_number
    account.bind_mac = product.bind_mac
    account.bind_vlan = product.bind_vlan
    account.vlan_id = 0
    account.vlan_id2 = 0
    account.create_time = _datetime
    account.update_time = _datetime
    db.add(account)
    
    clog = models.SlcRechargeLog()
    clog.member_id = get_cookie("customer_id")
    clog.card_number = card.card_number
    clog.account_number = form.d.account_number
    clog.recharge_status = 0
    clog.recharge_time = _datetime
    db.add(clog)
    
    card.card_status = CardUsed
    
    db.commit()
    redirect('/')
示例#14
0
def member_query(db, render):
    node_id = request.params.get('node_id')
    realname = request.params.get('realname')
    idcard = request.params.get('idcard')
    mobile = request.params.get('mobile')
    user_name = request.params.get('user_name')
    status = request.params.get('status')
    product_id = request.params.get('product_id')
    address = request.params.get('address')
    expire_days = request.params.get('expire_days')
    opr_nodes = get_opr_nodes(db)
    _query = db.query(
        models.SlcMember, models.SlcRadAccount,
        models.SlcRadProduct.product_name, models.SlcNode.node_desc).filter(
            models.SlcRadProduct.id == models.SlcRadAccount.product_id,
            models.SlcMember.member_id == models.SlcRadAccount.member_id,
            models.SlcNode.id == models.SlcMember.node_id)

    _now = datetime.datetime.now()

    if idcard:
        _query = _query.filter(models.SlcMember.idcard == idcard)
    if mobile:
        _query = _query.filter(models.SlcMember.mobile == mobile)
    if node_id:
        _query = _query.filter(models.SlcMember.node_id == node_id)
    else:
        _query = _query.filter(
            models.SlcMember.node_id.in_([i.id for i in opr_nodes]))
    if realname:
        _query = _query.filter(
            models.SlcMember.realname.like('%' + realname + '%'))
    if user_name:
        _query = _query.filter(
            models.SlcRadAccount.account_number.like('%' + user_name + '%'))

    #用户状态判断
    if status:
        if status == '4':
            _query = _query.filter(
                models.SlcRadAccount.expire_date <= _now.strftime("%Y-%m-%d"))
        elif status == '1':
            _query = _query.filter(
                models.SlcRadAccount.status == status,
                models.SlcRadAccount.expire_date >= _now.strftime("%Y-%m-%d"))
        else:
            _query = _query.filter(models.SlcRadAccount.status == status)

    if product_id:
        _query = _query.filter(models.SlcRadAccount.product_id == product_id)
    if address:
        _query = _query.filter(
            models.SlcMember.address.like('%' + address + '%'))
    if expire_days:
        _days = int(expire_days)
        td = datetime.timedelta(days=_days)
        edate = (_now + td).strftime("%Y-%m-%d")
        _query = _query.filter(models.SlcRadAccount.expire_date <= edate)
        _query = _query.filter(
            models.SlcRadAccount.expire_date >= _now.strftime("%Y-%m-%d"))

    if request.path == '/':
        return render("bus_member_list",
                      page_data=get_page_data(_query),
                      node_list=opr_nodes,
                      products=db.query(models.SlcRadProduct),
                      **request.params)
    elif request.path == "/export":
        data = Dataset()
        data.append((u'区域', u'姓名', u'证件号', u'邮箱', u'联系电话', u'地址', u'用户账号',
                     u'密码', u'资费', u'过期时间', u'余额(元)', u'时长(小时)', u'流量(MB)',
                     u'并发数', u'ip地址', u'状态', u'创建时间'))
        for i, j, _product_name, _node_desc in _query:
            data.append(
                (_node_desc, i.realname, i.idcard, i.email,
                 i.mobile, i.address, j.account_number,
                 utils.decrypt(j.password), _product_name, j.expire_date,
                 utils.fen2yuan(j.balance), utils.sec2hour(j.time_length),
                 utils.kb2mb(j.flow_length), j.user_concur_number,
                 j.ip_address, member_forms.user_state[j.status],
                 j.create_time))
        name = u"RADIUS-USER-" + datetime.datetime.now().strftime(
            "%Y%m%d-%H%M%S") + ".xls"
        return export_file(name, data)
示例#15
0
    def get(self):
        account = None
        try:
            account = self.authreg()
        except:
            import traceback
            self.render("error.html",msg=u"自动登录失败:%s"%traceback.format_exc())
            return

        #判断是否欠费,间隔指定时间再给其充值
        if account.flow_length <= 0:
            _interval = self.db.query(models.SlcWlanParam).filter_by(
                param_name = "wlan_free_interval"
            ).first() 
            interval = _interval and _interval.param_value or 10
            if can_gift(account.last_offline,int(interval)*60):
                product = self.db.query(models.SlcRadProduct).get(account.product_id)
                account.flow_length = int(product.fee_times)
                self.db.commit()

        username = account.account_number
        password = utils.decrypt(account.password)

        secret = self.settings.share_secret
        ac_addr = self.settings.ac_addr
        userIp = self.request.remote_ip
        
        try:
            cli = PortalClient(secret=secret)
            # req info 
            ri_req = PortalV2.newReqInfo(userIp,secret)
            ri_resp = yield cli.sendto(ri_req,ac_addr)
            
            if ri_resp.errCode > 0:
                print portalv2.AckInfoErrs[ri_resp.errCode]
            
            # req chellenge    
            rc_req = PortalV2.newReqChallenge(userIp,secret,serialNo=ri_req.serialNo)
            rc_resp = yield cli.sendto(rc_req,ac_addr)
            
            if not rc_resp.check_resp_auth(rc_req.auth):
                self.render("login.html",msg=u"认证请求失败")
                print (u"Challenge响应验证错误,消息被丢弃")
                return

            if rc_resp.errCode > 0:
                if rc_resp.errCode == 2:
                    self.set_user_cookie(username)
                    self.redirect("/")
                    return
                self.render("login.html",msg=portalv2.AckChallengeErrs[rc_resp.errCode])
                return
                
            challenge = rc_resp.get_challenge()
            
            # req auth
            ra_req = PortalV2.newReqAuth(
                userIp,
                username,
                password,
                rc_resp.reqId,
                challenge,
                secret,
                ac_addr[0],
                serialNo=ri_req.serialNo
            )
            ra_resp = yield cli.sendto(ra_req,ac_addr)
            if not ra_resp.check_resp_auth(ra_req.auth):
                self.render("login.html",msg=u"认证请求失败")
                print (u"认证响应验证错误,消息被丢弃")
                return

            if ra_resp.errCode > 0:
                if rc_resp.errCode == 2:
                    self.set_user_cookie(username)
                    self.redirect("/")
                    return                
                self.render("login.html",msg=portalv2.AckAuthErrs[ra_resp.errCode])
                return

            # aff_ack     
            aa_req = PortalV2.newAffAckAuth(userIp,secret,ac_addr[0],ra_req.serialNo,rc_resp.reqId)
            yield cli.sendto(aa_req,ac_addr,recv=False)
            
            log.msg('auth success')
        
            self.set_user_cookie(username)
            self.redirect("/")
            
        except Exception as err:
            self.render("login.html",msg=u"auth fail,%s"%str(err))
            print (u"auth fail %s"%str(err))
            import traceback
            traceback.print_exc()
        finally:
            cli.close()