Ejemplo n.º 1
0
    def _user_login(self, password):
        """
        用户登录验证模块,对用户对象进行判断,登录成功后返回一个新的用户对象
        :return:
        """
        # 对输入的密码加密
        _password = common.encrypt(password)

        for user, details in self.dict_user.items():
            # 找到用户名
            if user == self.username and not details["isdel"]:
                # 是否被锁定
                if details["islocked"] == 0:
                    # 账户未锁定,验证密码
                    if details["password"] == _password:
                        self.islogin = True
                        self.bindcard = details["bindcard"]
                        self.name = details["name"]
                        self.mobile = details["mobile"]
                        self.role = details["role"]
                        self.isdel = details["isdel"]
                        self.islocked = details["islocked"]
                        self.password = password
                        break
                    else:
                        # 密码错误,失败1次
                        self.trycount += 1
                else:
                    # 账户锁定了
                    self.islocked = 1
Ejemplo n.º 2
0
 def modify_password(self):
     """
     个人中心 - 修改密码
     :return:
     """
     _not_null_flag = False
     try:
         while not _not_null_flag:
             _new_password = input("输入新密码: ").strip()
             _confirm_password = input("再次输入确认密码:").strip()
             if not _new_password or not _confirm_password:
                 common.show_message("密码不能为空,请重新输入!", "ERROR")
                 continue
             if _new_password != _confirm_password:
                 common.show_message("两次输入密码不一致,请重新输入!", "NOTICE")
                 continue
             _not_null_flag = True
         self.password = _new_password
         _password = common.encrypt(self.password)
         self.dict_user[self.username]["password"] = _password
         self.update_user()
         common.show_message("密码修改成功!", "INFORMATIOM")
         return True
     except Exception as e:
         common.write_log(e)
         return False
Ejemplo n.º 3
0
def init_db_creditcard():
    _db_file = os.path.join(settings.DATABASE['dbpath'], "creditcard.db")
    with open(_db_file, "w+") as fc:
        for k, v in _creditcard_list.items():
            tmppassword = _creditcard_list[k]['password']
            encrypassword = common.encrypt(tmppassword)
            _creditcard_list[k]['password'] = encrypassword
        fc.write(json.dumps(_creditcard_list))
Ejemplo n.º 4
0
 def update_card(self):
     password = common.encrypt(self.password)
     self.credit_card[self.cardno]["password"] = password
     self.credit_card[self.cardno]["owner"] = self.owner
     self.credit_card[self.cardno]["credit_total"] = self.credit_total
     self.credit_card[self.cardno]["credit_balance"] = self.credit_balance
     self.credit_card[self.cardno]["frozenstatus"] = self.frozenstatus
     # 写入数据库
     dbapi.write_db_json(self.credit_card, self.__database)
Ejemplo n.º 5
0
def init_db_user():
    _db_file = os.path.join(Settings.DATABASE['dbpath'], "user.db")
    with open(_db_file, "w+") as fu:
        for k, v in _user_list.items():
            #对用户设置密码
            tmppassword = _user_list[k]['password']
            #对密码进行加密
            encrypassword = common.encrypt(tmppassword)
            #修改明文密码
            _user_list[k]['password'] = encrypassword
        fu.write(json.dumps(_user_list))
Ejemplo n.º 6
0
 def create_card(self):
     """
     新发行一张行用卡
     :return:
     """
     password = common.encrypt(self.password)
     self.credit_card[self.cardno] = dict(password=password,
                                          credit_total=self.credit_total,
                                          credit_balance=self.credit_balance,
                                          owner=self.owner,
                                          frozenstatus=self.frozenstatus)
     # 保存到数据库
     dbapi.write_db_json(self.credit_card, self.__database)
Ejemplo n.º 7
0
 def _pay_check(self, cost, password):
     """
     转账、提现时验证操作,判断卡的余额与支付密码是否正确。并返回错误类型码
     :param cost:  转账、提现金额(包含手续费)
     :param password: 支付密码
     :return: 错误码
     """
     totalfee = cost
     # 提现金额及手续费和大于余额,
     if totalfee > self.credit_balance:
         return Errorcode.BALANCE_NOT_ENOUGHT
     elif common.encrypt(password) != self.password:
         return Errorcode.CARD_PASS_ERROR
     else:
         return Errorcode.NO_ERROR
Ejemplo n.º 8
0
 def create_user(self):
     """
     新创建一个用户,将用户数据同步写入到数据库文件
     :return:
     """
     self.dict_user[self.username] = dict(
         password=common.encrypt(self.password),
         name=self.name,
         mobile=self.mobile,
         bindcard=self.bindcard,
         role=self.role,
         islocked=0,
         isdel=0,
     )
     dbapi.write_db_json(self.dict_user, self.__database)
Ejemplo n.º 9
0
def card_center(userobj):
    if userobj.islogin:
        # 重新load一下数据
        userobj.db_load()
        cardno = userobj.bindcard
        # 获得信用卡对象
        card = CreditCard(cardno)
    else:
        # 未登录信用卡
        input_flag = False
        while not input_flag:
            cardno = input("请输入信用卡卡号: ").strip().lower()
            if cardno.isnumeric():
                card = CreditCard(cardno)
                if card.card_is_exists:
                    pwd = input("请输入密码:")
                    if common.encrypt(pwd) == card.password:
                        common.show_message("登录成功", "NOTICE")
                        input_flag = True
                        continue
                else:
                    common.show_message("卡号不存在,请重新输入!", "ERROR")
                    continue
            else:
                common.show_message("卡号无效!", "ERROR")
                continue

    show_template = template.index_ATM
    quitflag = False
    while not quitflag:
        print(show_template.format(cardno=card.cardno))
        _choose = common.input_msg("请选择功能: ", ("1", "2", "3", "4", "5"))
        # 返回
        if _choose == "5":
            quitflag = True
            continue

        # 查看信用卡信息
        if _choose == "1":
            common.show_message(
                template.card_info.format(
                    cardno=card.cardno,
                    owner=card.owner,
                    total=card.credit_total,
                    balance=card.credit_balance,
                    status="正常" if card.frozenstatus == 0 else "冻结"), "NOTICE")
        # 提现
        if _choose == "2":
            if card.frozenstatus == 1:
                common.show_message("卡已冻结,请联系客服!", "ERROR")
            else:
                common.show_message(
                    "信用卡提现将收取 {0}% 的手续费!".format(settings.FETCH_MONEY_RATE *
                                                 100), "NOTICE")
                quitflag = False
                while not quitflag:
                    cost = common.input_msg("请输入要提现的金额(q返回):")
                    if cost.isnumeric():
                        cardpasswd = common.input_msg("请输入信用卡密码:")
                        # 执行提现操作
                        exe_result = card.fetch_money(float(cost), cardpasswd)
                        if exe_result == errorcode.NO_ERROR:
                            common.show_message("已完成提现!", "NOTICE")
                        if exe_result == errorcode.BALANCE_NOT_ENOUGHT:
                            common.show_message("信用卡可透支余额不足!", "ERROR")
                        if exe_result == errorcode.CARD_PASS_ERROR:
                            common.show_message("信用卡密码错误!", "ERROR")
                    elif cost == "q":
                        quitflag = True
                        continue
                    else:
                        common.show_message("输入错误!", "ERROR")
        # 转账
        if _choose == "3":
            if card.frozenstatus == 1:
                common.show_message("此卡已冻结,请联系客服!", "ERROR")
            else:
                common.show_message(
                    "信用卡转账将收取 {0}% 的手续费!".format(settings.FETCH_MONEY_RATE *
                                                 100), "NOTICE")
                quitflag = False
                while not quitflag:
                    trans_cardno = common.input_msg("请输入要转账的卡号(q返回):")
                    if trans_cardno.isnumeric():
                        # 生成一个卡对象, 验证卡号是否存在
                        trans_cardobj = CreditCard(trans_cardno)

                        # 卡号不存在返回主菜单
                        if not trans_cardobj.card_is_exists:
                            common.show_message("卡号不存在,请确认!", "ERROR")
                            quitflag = True
                            continue
                        else:
                            # 卡号存在
                            trans_cost = common.input_msg("请输入要转账的金额: ")

                            # 如果输入的均为数字
                            if trans_cost.isnumeric():
                                comfirm = common.input_msg(
                                    "确定要给卡号 {0} 转入人民币 {1} 元吗(y/n)?".format(
                                        trans_cardobj.cardno, trans_cost),
                                    ("y", "n"))
                                if comfirm == "y":
                                    cardpasswd = common.input_msg("请输入信用卡密码:")

                                    # 执行转账操作
                                    exe_result = card.translate_money(
                                        float(trans_cost), cardpasswd,
                                        trans_cardobj)

                                    if exe_result == errorcode.NO_ERROR:
                                        common.show_message("转账完成!", "NOTICE")
                                    if exe_result == errorcode.BALANCE_NOT_ENOUGHT:
                                        common.show_message(
                                            "信用卡可透支余额不足!", "ERROR")
                                    if exe_result == errorcode.CARD_PASS_ERROR:
                                        common.show_message(
                                            "信用卡密码错误!", "ERROR")
                            else:
                                common.show_message("输入错误!", "ERROR")

                    elif trans_cardno == "q":
                        quitflag = True
                        continue
                    else:
                        common.show_message("输入错误!", "ERROR")

        # 还款
        if _choose == "4":
            # 更新一下对账单信息
            card.recreate_statement()

            quitflag = False
            while not quitflag:
                # 获取对账单所有列表
                interest_list = card.load_statement_list()
                # 获取还未还款的记录并显示
                message_info = report.print_statement_list(
                    card.cardno, interest_list)

                # 如果有要还款的记录
                if len(message_info) > 0:
                    common.show_message(message_info, "NOTICE")
                    # 输入要还款的单号
                    serino_list = list()
                    for order in interest_list:
                        serino_list.append(list(order.keys())[0])
                    serino_list.append("q")
                    pay_serno = common.input_msg("请选择还款的16位账单号(q退出):",
                                                 tuple(serino_list))

                    if pay_serno == "q":
                        quitflag = True
                        continue
                    else:
                        for i in range(len(interest_list)):
                            for k, details in interest_list[i].items():
                                if k == pay_serno:
                                    # 显示指定单号的相信对账单信息
                                    common.show_message(
                                        report.print_statement_detail(
                                            card.cardno, pay_serno, details),
                                        "NOTICE")
                                    pay_fee = common.input_msg("请输入还款金额:")
                                    if pay_fee.isnumeric():
                                        # 更新已还款金额 = 现在还的金额 + 已经还的金额
                                        total_payed = details["payed"] + float(
                                            pay_fee)
                                        interest_list[i][pay_serno][
                                            "payed"] = total_payed

                                        # 全还了吗?需要还款数 = 消费总费用 + 利息
                                        need_pay = details["total"] + details[
                                            "interest"]
                                        if total_payed >= need_pay:
                                            # 还款数大于等于需要还款数,则更新已还款字段信息
                                            interest_list[i][pay_serno][
                                                "isfinished"] = 1
                                        else:
                                            # 没全部还款
                                            common.show_message(
                                                "您尚未全部还款,请在还款日前尽快还款!",
                                                "NOTICE")
                                        # 将还款后的信息写入数据库更新
                                        dbapi.write_statement_list(
                                            card.cardno, interest_list)

                                        # 还款成功
                                        common.show_message("还款成功", "NOTICE")
                                        # 是否继续
                                        iscontinue = common.input_msg(
                                            "继续还款吗(y/n)?", ("y", "n"))
                                        if iscontinue == "n":
                                            quitflag = True

                                    else:
                                        common.show_message(
                                            "输入数据不正确,请重新输入!", "ERROR")
                else:
                    common.show_message("无账单信息!", "NOTICE")
                    quitflag = True