コード例 #1
0
ファイル: account.py プロジェクト: ywysee/ToughRADIUS
def account_update_post(db, render):
    form = account_forms.account_update_form()
    if not form.validates(source=request.forms):
        return render("base_form", form=form)

    account = db.query(models.SlcRadAccount).get(form.d.account_number)
    account.ip_address = form.d.ip_address
    account.install_address = form.d.install_address
    account.user_concur_number = form.d.user_concur_number
    account.bind_mac = form.d.bind_mac
    account.bind_vlan = form.d.bind_vlan
    account.account_desc = form.d.account_desc
    if form.d.new_password:
        account.password = utils.encrypt(form.d.new_password)

    ops_log = models.SlcRadOperateLog()
    ops_log.operator_name = get_cookie("username")
    ops_log.operate_ip = get_cookie("login_ip")
    ops_log.operate_time = utils.get_currtime()
    ops_log.operate_desc = u'操作员(%s)修改上网账号信息:%s' % (get_cookie("username"), account.account_number)
    db.add(ops_log)

    db.commit()
    websock.update_cache("account", account_number=account.account_number)
    redirect(member_detail_url_formatter(account.account_number))
コード例 #2
0
ファイル: account.py プロジェクト: xcodest/ToughRADIUS
def account_update_post(db, render):
    form = account_forms.account_update_form()
    if not form.validates(source=request.forms):
        return render("base_form", form=form)

    account = db.query(models.SlcRadAccount).get(form.d.account_number)
    account.ip_address = form.d.ip_address
    account.install_address = form.d.install_address
    account.user_concur_number = form.d.user_concur_number
    account.bind_mac = form.d.bind_mac
    account.bind_vlan = form.d.bind_vlan
    account.account_desc = form.d.account_desc
    if form.d.new_password:
        account.password = utils.encrypt(form.d.new_password)

    ops_log = models.SlcRadOperateLog()
    ops_log.operator_name = get_cookie("username")
    ops_log.operate_ip = get_cookie("login_ip")
    ops_log.operate_time = utils.get_currtime()
    ops_log.operate_desc = u'操作员(%s)修改上网账号信息:%s' % (get_cookie("username"), account.account_number)
    db.add(ops_log)

    db.commit()
    websock.update_cache("account", account_number=account.account_number)
    redirect(member_detail_url_formatter(account.account_number))
コード例 #3
0
ファイル: websock.py プロジェクト: ywysee/ToughRADIUS
 def invoke_admin(self, ops, **kwargs):
     msg_id = utils.CurrentID()
     message = {'msg_id': msg_id, 'process': "admin_%s" % ops}
     callback = 'callback' in kwargs and kwargs.pop('callback') or None
     message.update(**kwargs)
     secure_msg = utils.encrypt(json.dumps(message).encode("utf-8"))
     self.factory.protocol.messages.append(secure_msg)
     if callback: self.factory.protocol.callbacks[msg_id] = callback
コード例 #4
0
ファイル: websock.py プロジェクト: Mark-Shine/ToughRADIUS
 def invoke_admin(self,ops,**kwargs):
     msg_id = utils.CurrentID()
     message = {
         'msg_id'  : msg_id,
         'process' : "admin_%s"%ops
     }
     callback = 'callback' in kwargs and kwargs.pop('callback') or None
     message.update(**kwargs)
     secure_msg = utils.encrypt(json.dumps(message).encode("utf-8"))
     self.factory.protocol.messages.append(secure_msg) 
     if callback:self.factory.protocol.callbacks[msg_id] = callback
コード例 #5
0
ファイル: customer.py プロジェクト: shtrend/ToughRADIUS
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("/")
コード例 #6
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("/")
コード例 #7
0
ファイル: member.py プロジェクト: shtrend/ToughRADIUS
def member_import_post(db, render):
    nodes = [(n.id, n.node_desc) for n in get_opr_nodes(db)]
    products = [(n.id, n.product_name) for n in get_opr_products(db)]
    iform = member_forms.user_import_form(nodes, products)
    node_id = request.params.get('node_id')
    product_id = request.params.get('product_id')
    upload = request.files.get('import_file')
    impctx = upload.file.read()
    lines = impctx.split("\n")
    _num = 0
    impusers = []
    for line in lines:
        _num += 1
        line = line.strip()
        if not line or "用户姓名" in line: continue
        attr_array = line.split(",")
        if len(attr_array) < 11:
            return render("bus_import_form", form=iform, msg=u"line %s error: length must 11 " % _num)

        vform = member_forms.user_import_vform()
        if not vform.validates(dict(
            realname=attr_array[0],
            idcard=attr_array[1],
            mobile=attr_array[2],
            address=attr_array[3],
            account_number=attr_array[4],
            password=attr_array[5],
            begin_date=attr_array[6],
            expire_date=attr_array[7],
            balance=attr_array[8],
            time_length=utils.hour2sec(attr_array[9]),
            flow_length=utils.mb2kb(attr_array[10]))):
            return render("bus_import_form", form=iform, msg=u"line %s error: %s" % (_num, vform.errors))

        impusers.append(vform)

    for form in impusers:
        try:
            member = models.SlcMember()
            member.node_id = node_id
            member.realname = form.d.realname
            member.idcard = form.d.idcard
            member.member_name = form.d.account_number
            member.password = md5(form.d.password.encode()).hexdigest()
            member.sex = '1'
            member.age = '0'
            member.email = ''
            member.mobile = form.d.mobile
            member.address = form.d.address
            member.create_time = form.d.begin_date + ' 00:00:00'
            member.update_time = utils.get_currtime()
            member.email_active = 0
            member.mobile_active = 0
            member.active_code = utils.get_uuid()
            db.add(member)
            db.flush()
            db.refresh(member)

            accept_log = models.SlcRadAcceptLog()
            accept_log.accept_type = 'open'
            accept_log.accept_source = 'console'
            _desc = u"用户导入账号:%s" % form.d.account_number
            accept_log.accept_desc = _desc
            accept_log.account_number = form.d.account_number
            accept_log.accept_time = member.update_time
            accept_log.operator_name = get_cookie("username")
            db.add(accept_log)
            db.flush()
            db.refresh(accept_log)

            order_fee = 0
            actual_fee = 0
            balance = 0
            time_length = 0
            flow_length = 0
            expire_date = form.d.expire_date
            product = db.query(models.SlcRadProduct).get(product_id)
            # 买断时长
            if product.product_policy == 3:
                time_length = int(form.d.time_length)
            # 买断流量
            elif product.product_policy == 5:
                flow_length = int(form.d.flow_length)
            # 预付费时长,预付费流量
            elif product.product_policy in (1, 4):
                balance = utils.yuan2fen(form.d.balance)
                expire_date = '3000-11-11'

            order = models.SlcMemberOrder()
            order.order_id = utils.gen_order_id()
            order.member_id = member.member_id
            order.product_id = product.id
            order.account_number = form.d.account_number
            order.order_fee = order_fee
            order.actual_fee = actual_fee
            order.pay_status = 1
            order.accept_id = accept_log.id
            order.order_source = 'console'
            order.create_time = member.update_time
            order.order_desc = u"用户导入开户"
            db.add(order)

            account = models.SlcRadAccount()
            account.account_number = form.d.account_number
            account.member_id = member.member_id
            account.product_id = order.product_id
            account.install_address = member.address
            account.ip_address = ''
            account.mac_addr = ''
            account.password = utils.encrypt(form.d.password)
            account.status = 1
            account.balance = balance
            account.time_length = time_length
            account.flow_length = flow_length
            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 = member.create_time
            account.update_time = member.update_time
            db.add(account)

        except Exception as e:
            return render("bus_import_form", form=iform, msg=u"error : %s" % str(e))

    db.commit()
    redirect("/member")
コード例 #8
0
ファイル: member.py プロジェクト: shtrend/ToughRADIUS
def member_open_post(db, render):
    nodes = [(n.id, n.node_desc) for n in get_opr_nodes(db)]
    products = [(n.id, n.product_name) for n in get_opr_products(db)]
    form = member_forms.user_open_form(nodes, products)
    if not form.validates(source=request.forms):
        return render("bus_open_form", form=form)

    if db.query(models.SlcRadAccount).filter_by(account_number=form.d.account_number).count() > 0:
        return render("bus_open_form", form=form, msg=u"上网账号%s已经存在" % form.d.account_number)

    if form.d.ip_address and db.query(models.SlcRadAccount).filter_by(ip_address=form.d.ip_address).count() > 0:
        return render("bus_open_form", form=form, msg=u"ip%s已经被使用" % form.d.ip_address)

    if db.query(models.SlcMember).filter_by(
        member_name=form.d.member_name).count() > 0:
        return render("bus_open_form", form=form, msg=u"用户名%s已经存在" % form.d.member_name)

    member = models.SlcMember()
    member.node_id = form.d.node_id
    member.realname = form.d.realname
    member.member_name = form.d.member_name or form.d.account_number
    mpwd = form.d.member_password or form.d.password
    member.password = md5(mpwd.encode()).hexdigest()
    member.idcard = form.d.idcard
    member.sex = '1'
    member.age = '0'
    member.email = ''
    member.mobile = form.d.mobile
    member.address = form.d.address
    member.create_time = utils.get_currtime()
    member.update_time = utils.get_currtime()
    member.email_active = 0
    member.mobile_active = 0
    member.active_code = utils.get_uuid()
    member.member_desc = form.d.member_desc
    db.add(member)
    db.flush()
    db.refresh(member)

    accept_log = models.SlcRadAcceptLog()
    accept_log.accept_type = 'open'
    accept_log.accept_source = 'console'
    accept_log.account_number = form.d.account_number
    accept_log.accept_time = member.create_time
    accept_log.operator_name = get_cookie("username")
    accept_log.accept_desc = u"用户新开户:(%s)%s" % (member.member_name, member.realname)
    db.add(accept_log)
    db.flush()
    db.refresh(accept_log)

    order_fee = 0
    balance = 0
    expire_date = form.d.expire_date
    product = db.query(models.SlcRadProduct).get(form.d.product_id)
    # 预付费包月
    if product.product_policy == 0:
        order_fee = decimal.Decimal(product.fee_price) * decimal.Decimal(form.d.months)
        order_fee = int(order_fee.to_integral_value())
    # 买断包月,买断流量
    elif product.product_policy in (2, 5):
        order_fee = int(product.fee_price)
    # 预付费时长,预付费流量
    elif product.product_policy in (1, 4):
        balance = utils.yuan2fen(form.d.fee_value)
        expire_date = '3000-11-11'

    order = models.SlcMemberOrder()
    order.order_id = utils.gen_order_id()
    order.member_id = member.member_id
    order.product_id = product.id
    order.account_number = form.d.account_number
    order.order_fee = order_fee
    order.actual_fee = utils.yuan2fen(form.d.fee_value)
    order.pay_status = 1
    order.accept_id = accept_log.id
    order.order_source = 'console'
    order.create_time = member.create_time
    order.order_desc = u"用户新开账号"
    db.add(order)

    account = models.SlcRadAccount()
    account.account_number = form.d.account_number
    account.ip_address = form.d.ip_address
    account.member_id = member.member_id
    account.product_id = order.product_id
    account.install_address = member.address
    account.mac_addr = ''
    account.password = utils.encrypt(form.d.password)
    account.status = form.d.status
    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 = member.create_time
    account.update_time = member.create_time
    account.account_desc = member.member_desc
    db.add(account)

    db.commit()
    redirect(member_detail_url_formatter(account.account_number))
コード例 #9
0
def encrypt_data(db):
    msg_data = request.params.get('data')
    return dict(code=0, data=utils.encrypt(msg_data))
コード例 #10
0
ファイル: admin.py プロジェクト: Mark-Shine/ToughRADIUS
def encrypt_data(db):    
    msg_data = request.params.get('data')
    return dict(code=0,data=utils.encrypt(msg_data))
コード例 #11
0
ファイル: member.py プロジェクト: travislee8964/ToughRADIUS
def member_import_post(db, render):
    nodes = [(n.id, n.node_desc) for n in get_opr_nodes(db)]
    products = [(n.id, n.product_name) for n in get_opr_products(db)]
    iform = member_forms.user_import_form(nodes, products)
    node_id = request.params.get('node_id')
    product_id = request.params.get('product_id')
    upload = request.files.get('import_file')
    impctx = upload.file.read()
    lines = impctx.split("\n")
    _num = 0
    impusers = []
    for line in lines:
        _num += 1
        line = line.strip()
        if not line or "用户姓名" in line: continue
        attr_array = line.split(",")
        if len(attr_array) < 11:
            return render("bus_import_form",
                          form=iform,
                          msg=u"line %s error: length must 11 " % _num)

        vform = member_forms.user_import_vform()
        if not vform.validates(
                dict(realname=attr_array[0],
                     idcard=attr_array[1],
                     mobile=attr_array[2],
                     address=attr_array[3],
                     account_number=attr_array[4],
                     password=attr_array[5],
                     begin_date=attr_array[6],
                     expire_date=attr_array[7],
                     balance=attr_array[8],
                     time_length=utils.hour2sec(attr_array[9]),
                     flow_length=utils.mb2kb(attr_array[10]))):
            return render("bus_import_form",
                          form=iform,
                          msg=u"line %s error: %s" % (_num, vform.errors))

        impusers.append(vform)

    for form in impusers:
        try:
            member = models.SlcMember()
            member.node_id = node_id
            member.realname = form.d.realname
            member.idcard = form.d.idcard
            member.member_name = form.d.account_number
            member.password = md5(form.d.password.encode()).hexdigest()
            member.sex = '1'
            member.age = '0'
            member.email = ''
            member.mobile = form.d.mobile
            member.address = form.d.address
            member.create_time = form.d.begin_date + ' 00:00:00'
            member.update_time = utils.get_currtime()
            member.email_active = 0
            member.mobile_active = 0
            member.active_code = utils.get_uuid()
            db.add(member)
            db.flush()
            db.refresh(member)

            accept_log = models.SlcRadAcceptLog()
            accept_log.accept_type = 'open'
            accept_log.accept_source = 'console'
            _desc = u"用户导入账号:%s" % form.d.account_number
            accept_log.accept_desc = _desc
            accept_log.account_number = form.d.account_number
            accept_log.accept_time = member.update_time
            accept_log.operator_name = get_cookie("username")
            db.add(accept_log)
            db.flush()
            db.refresh(accept_log)

            order_fee = 0
            actual_fee = 0
            balance = 0
            time_length = 0
            flow_length = 0
            expire_date = form.d.expire_date
            product = db.query(models.SlcRadProduct).get(product_id)
            # 买断时长
            if product.product_policy == 3:
                time_length = int(form.d.time_length)
            # 买断流量
            elif product.product_policy == 5:
                flow_length = int(form.d.flow_length)
            # 预付费时长,预付费流量
            elif product.product_policy in (1, 4):
                balance = utils.yuan2fen(form.d.balance)
                expire_date = '3000-11-11'

            order = models.SlcMemberOrder()
            order.order_id = utils.gen_order_id()
            order.member_id = member.member_id
            order.product_id = product.id
            order.account_number = form.d.account_number
            order.order_fee = order_fee
            order.actual_fee = actual_fee
            order.pay_status = 1
            order.accept_id = accept_log.id
            order.order_source = 'console'
            order.create_time = member.update_time
            order.order_desc = u"用户导入开户"
            db.add(order)

            account = models.SlcRadAccount()
            account.account_number = form.d.account_number
            account.member_id = member.member_id
            account.product_id = order.product_id
            account.install_address = member.address
            account.ip_address = ''
            account.mac_addr = ''
            account.password = utils.encrypt(form.d.password)
            account.status = 1
            account.balance = balance
            account.time_length = time_length
            account.flow_length = flow_length
            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 = member.create_time
            account.update_time = member.update_time
            db.add(account)

        except Exception as e:
            return render("bus_import_form",
                          form=iform,
                          msg=u"error : %s" % str(e))

    db.commit()
    redirect("/member")
コード例 #12
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('/')
コード例 #13
0
ファイル: account.py プロジェクト: ywysee/ToughRADIUS
def account_open(db, render):
    products = [(n.id, n.product_name) for n in get_opr_products(db)]
    form = account_forms.account_open_form(products)
    if not form.validates(source=request.forms):
        return render("bus_open_form", form=form)

    if db.query(models.SlcRadAccount).filter_by(
        account_number=form.d.account_number).count() > 0:
        return render("bus_open_form", form=form, msg=u"上网账号已经存在")

    if form.d.ip_address and db.query(models.SlcRadAccount).filter_by(ip_address=form.d.ip_address).count() > 0:
        return render("bus_open_form", form=form, msg=u"ip%s已经被使用" % form.d.ip_address)

    accept_log = models.SlcRadAcceptLog()
    accept_log.accept_type = 'open'
    accept_log.accept_source = 'console'
    accept_log.account_number = form.d.account_number
    accept_log.accept_time = utils.get_currtime()
    accept_log.operator_name = get_cookie("username")
    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 = form.d.expire_date
    product = db.query(models.SlcRadProduct).get(form.d.product_id)
    # 预付费包月
    if product.product_policy == 0:
        order_fee = decimal.Decimal(product.fee_price) * decimal.Decimal(form.d.months)
        order_fee = int(order_fee.to_integral_value())
    # 买断包月,买断时长,买断流量
    elif product.product_policy in (2, 3, 5):
        order_fee = int(product.fee_price)
    # 预付费时长,预付费流量
    elif product.product_policy in (1, 4):
        balance = utils.yuan2fen(form.d.fee_value)
        expire_date = '3000-11-11'

    order = models.SlcMemberOrder()
    order.order_id = utils.gen_order_id()
    order.member_id = form.d.member_id
    order.product_id = product.id
    order.account_number = form.d.account_number
    order.order_fee = order_fee
    order.actual_fee = utils.yuan2fen(form.d.fee_value)
    order.pay_status = 1
    order.accept_id = accept_log.id
    order.order_source = 'console'
    order.create_time = _datetime
    order.order_desc = u"用户增开账号"
    db.add(order)

    account = models.SlcRadAccount()
    account.account_number = form.d.account_number
    account.ip_address = form.d.ip_address
    account.member_id = int(form.d.member_id)
    account.product_id = order.product_id
    account.install_address = form.d.address
    account.mac_addr = ''
    account.password = utils.encrypt(form.d.password)
    account.status = form.d.status
    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
    account.account_desc = form.d.account_desc
    db.add(account)

    db.commit()
    redirect(member_detail_url_formatter(account.account_number))
コード例 #14
0
    def authreg(self):
        mp_openid = self.get_argument("mp_openid",None)
        mp_username = self.get_argument("mp_username",mp_openid)
        mp_product_id = self.get_argument("product_id",None)
        mp_node_id = self.get_argument("node_id",None)

        if not mp_openid:
            raise WeixinError(u"微信id为空")

        member = self.db.query(models.SlcMember).filter(
            models.SlcMember.weixin_id==mp_openid
        ).first()
        product = self.db.query(models.SlcRadProduct).get(mp_product_id)
        node = self.db.query(models.SlcNode).get(mp_node_id)

        if not product or not node:
            raise WeixinError(u"资费套餐或区域节点不存在")

        account = None

        if member:
            account = self.db.query(models.SlcRadAccount).filter_by(
                account_number=member.member_name).first()
            print member.member_name
            print 'account:',account
        else:
            rand_account = self.rand_number()
            rand_pwd = self.rand_number(True)
            member = models.SlcMember()
            member.weixin_id = mp_openid
            member.node_id = mp_node_id
            member.realname = rand_account
            member.member_name = rand_account
            mpwd = rand_pwd
            member.password = md5(mpwd.encode()).hexdigest()
            member.idcard = mp_openid
            member.sex = '1'
            member.age = '0'
            member.email = ''
            member.mobile = ''
            member.address = ''
            member.create_time = utils.get_currtime()
            member.update_time = utils.get_currtime()
            member.email_active = 0
            member.mobile_active = 0
            member.active_code = utils.get_uuid()
            self.db.add(member)
            self.db.flush()
            self.db.refresh(member)

            accept_log = models.SlcRadAcceptLog()
            accept_log.accept_type = 'open'
            accept_log.accept_source = 'weixin'
            accept_log.account_number = rand_account
            accept_log.accept_time = member.create_time
            accept_log.operator_name = rand_account
            accept_log.accept_desc = u"用户微信新开户:(%s)%s"%(member.member_name,member.realname)
            self.db.add(accept_log)
            self.db.flush()
            self.db.refresh(accept_log)

            order = models.SlcMemberOrder()
            order.order_id = utils.gen_order_id()
            order.member_id = member.member_id
            order.product_id = product.id
            order.account_number = rand_account
            order.order_fee = 0
            order.actual_fee = 0
            order.pay_status = 1
            order.accept_id = accept_log.id
            order.order_source = 'console'
            order.create_time = member.create_time
            order.order_desc = u"用户微信新开账号"
            self.db.add(order)

            account = models.SlcRadAccount()
            account.account_number = rand_account
            account.ip_address = ''
            account.member_id = member.member_id
            account.product_id = order.product_id
            account.install_address = member.address
            account.mac_addr = ''
            account.password = utils.encrypt(rand_pwd)
            account.status = 1
            account.balance = 0
            account.time_length = int(product.fee_times)
            account.flow_length = int(product.fee_flows)
            account.expire_date = '3000-12-30'
            account.user_concur_number = 1
            account.bind_mac = product.bind_mac
            account.bind_vlan = product.bind_vlan
            account.vlan_id = 0
            account.vlan_id2 = 0
            account.create_time = member.create_time
            account.update_time = member.create_time
            self.db.add(account)
            self.db.commit()

        return account

        
コード例 #15
0
 def gencardpwd(clen=8):
     r = list('1234567890abcdefghijklmnopqrstuvwxyz')
     rg = utils.random_generator
     return utils.encrypt(''.join([rg.choice(r) for _ in range(clen)]))
コード例 #16
0
ファイル: customer.py プロジェクト: Mark-Shine/ToughRADIUS
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('/')
コード例 #17
0
ファイル: card.py プロジェクト: shtrend/ToughRADIUS
 def gencardpwd(clen=8):
     r = list('1234567890abcdefghijklmnopqrstuvwxyz')
     rg = utils.random_generator
     return utils.encrypt(''.join([rg.choice(r) for _ in range(clen)]))