Ejemplo n.º 1
0
def login(user_info_dict, user_file):
    while True:
        #global username
        username = input('请输入用户名:').strip()
        #用户名为空
        if len(username) == 0:
            print("用户名不能为空")
        # 用户名不存在
        elif username not in user_info_dict.keys():
            print('用户名不存在,请重新输入!')
        # 用户名存在
        else:
            # 判断登录次数
            if user_info_dict[username]['try_times'] >= 3:
                print('账户已经冻结,请联系管理员.')
                return False
            else:
                pwd = input('请输入密码:').strip()
                if user_info_dict[username]['pwd'] == pwd:
                    # 如果登录成功,将登录次数重置为 0
                    user_info_dict[username]['times'] = 0
                    print('恭喜您 %s,登录成功' % username)
                    dump_file.dump_file(user_info_dict, user_file)
                    return username
                else:
                    # 如果登录失败,登录次数加1
                    user_info_dict[username]['try_times'] += 1
                    times = user_info_dict[username]['try_times']
                    left_times = 3 - times
                    if left_times == 0:
                        print('账户已经冻结,请联系管理员')
                        dump_file.dump_file(user_info_dict, user_file)
                        return False
                    else:
                        print("密码输入错误,您还有 %s 次尝试机会..." % left_times)
Ejemplo n.º 2
0
def settlement(username):
    # 结算时调用的接口
    bool_value = True
    while bool_value:
        #total = print_shopping_cart(settings.shopping_cart)
        user_balance = int(settings.atm_user_data[username]['balance'])
        if total > user_balance:
            print("余额:{0}".format(user_balance))
            print("余额不足,请充值:")
            bool_value = False
        else:
            print("购物成功")
            settings.atm_user_data[username]['balance'] = int(user_balance -
                                                              total)
            bool_value = False
            dump_file.dump_file(settings.atm_user_data,
                                settings.atm_user_file_path)
            #print(settings.shopping_cart)
            for i in settings.shopping_cart:
                loger.loger(username, username, settings.time_now, i[0],
                            "-" + str(i[1]))
                loger.loger('ATM.var', username, settings.time_now, "-",
                            "info", 'buy ' + i[0])
        loger.loger('ATM.var', username, settings.time_now, '-', 'info',
                    'Exit MALL')
        settings.shopping_cart.clear()
Ejemplo n.º 3
0
def unlock_user(userinfo, user_path):
    while True:
        user = input("请输入用户名:").strip()
        if user in userinfo:
            userinfo[user]['try_times'] = 0
            print("用户%s已解锁" % user)
            dump_file.dump_file(userinfo, user_path)
            loger.loger('ATM.var', 'root', settings.time_now, '-', 'warning',
                        "unlock_user:%s" % user)
            return True
        else:
            print("查无此用户,请重新输入")
Ejemplo n.º 4
0
def chang_creadit(userinfo, user_path):
    while True:
        user = input("请输入用户名:").strip()
        if user in userinfo:
            credit = input("请输入用户额度:").strip()
            userinfo[user]['credit'] = credit
            print("用户%s额度已经调整" % user)
            dump_file.dump_file(userinfo, user_path)
            loger.loger('ATM.var', 'root', settings.time_now, '-', 'warning',
                        "chang_atm_user_credit:%s" % user)
            return True
        else:
            print("查无此用户")
Ejemplo n.º 5
0
def del_user(userinfo, user_path):
    while True:
        user = input("请输入用户名:").strip()
        if user in userinfo:
            if len(userinfo) > 1:
                del userinfo[user]
                print("用户%s已删除" % user)
                dump_file.dump_file(userinfo, user_path)
                loger.loger('ATM.var', 'root', settings.time_now, '-',
                            'warning', "del_user:%s" % user)
                return True
            else:
                print("没有更多的用户可删除")
        else:
            print("查无此用户,请重新输入")
Ejemplo n.º 6
0
def add_user(user_type,
             userinfo,
             user_path,
             try_times=0,
             credit=None,
             balance=None):
    break_flag = True
    while break_flag:
        new_user = input("请输入新用户名称:").strip()
        if len(new_user) == 0:
            continue
        if new_user in userinfo:
            print("用户名{0}已经存在,请重新输入!".format(new_user))
        else:
            new_user_login_pwd = input("请输入新用户密码:")
            if len(new_user_login_pwd) == 0: continue
            confirm_new_user_login_pwd = input("请再次新用户输入密码:")
            if len(confirm_new_user_login_pwd) == 0: continue
            if new_user_login_pwd == confirm_new_user_login_pwd:
                if user_type == 1:
                    userinfo[new_user] = {
                        "pwd": new_user_login_pwd,
                        "try_times": 0
                    }
                    loger.loger('ATM.var', 'root', settings.time_now, '-',
                                'info', "add_shop_user:%s" % new_user)
                    break_flag = False
                elif user_type == 2:
                    credit = int(input("请输入新用户额度:").strip())
                    userinfo[new_user] = {
                        "pwd": new_user_login_pwd,
                        "try_times": 0,
                        'credit': credit,
                        'balance': credit
                    }
                    loger.loger('ATM.var', 'root', settings.time_now, '-',
                                'info', "add_atm_user:%s" % new_user)
                    break_flag = False
                print("用户%s添加成功" % new_user)
                dump_file.dump_file(userinfo, user_path)
            else:
                print("两次输入登录密码不一致,请重新输入")
Ejemplo n.º 7
0
def change_pwd(userinfo, user_path):
    while True:
        user = input("请输入用户:").strip()
        if user in userinfo:
            old_pwd = input("请输入旧密码:").strip()
            if old_pwd == userinfo[user]['pwd']:
                new_pwd = input("请输入新密码:").strip()
                confirm_pwd = input("请再输入一遍新密码:").strip()
                if new_pwd == confirm_pwd:
                    userinfo[user]['pwd'] = new_pwd
                    print("密码修改成功!")
                    dump_file.dump_file(userinfo, user_path)
                    loger.loger('ATM.var', 'root', settings.time_now, '-',
                                'warning', "chang_user_pwd:%s" % user)
                    return True
                else:
                    print("新密码前后输入不一致!请重新输入!")
            else:
                print("旧密码错误,请重新输入!")
        else:
            print("查无此用户,请重新输入")
Ejemplo n.º 8
0
def transact_amount(account,tran_type):
    if tran_type == 1:
        withdraw = int(input("取钱:").strip())
        user_balance = int(settings.atm_user_data[account]['balance'])
        if withdraw > user_balance:
            print("余额:{0}".format(user_balance))
            print("余额不足,请充值:")
            loger.loger('ATM.var',account,settings.time_now,'-','error','withdraw Balance Insufficient')
        else:
            settings.atm_user_data[account]['balance'] = int(user_balance - (withdraw*1.05))
            dump_file.dump_file(settings.atm_user_data, settings.atm_user_file_path)
            loger.loger(account,account,settings.time_now,'withdraw',"-"+str(withdraw),withdraw*0.05)
            loger.loger('ATM.var',account,settings.time_now,'-','info','withdraw'+"-"+str(withdraw))
    elif tran_type == 2:
        repay = int(input("还款:").strip())
        user_balance = int(settings.atm_user_data[account]['balance'])
        settings.atm_user_data[account]['balance'] = int(user_balance + repay)
        dump_file.dump_file(settings.atm_user_data, settings.atm_user_file_path)
        loger.loger(account,account,settings.time_now,'repay',"+"+str(repay))
        loger.loger('ATM.var',account,settings.time_now,'-','info','repay'+"+"+str(repay))
    elif tran_type == 3:
        transfer = input("转入帐号").strip()
        if transfer in settings.atm_user_data:
            trans_money = int(input("转入金额").strip())
            user_balance = int(settings.atm_user_data[account]['balance'])
            if trans_money > user_balance:
                print("余额:{0}".format(user_balance))
                print("余额不足,请充值:")
                loger.loger('ATM.var',account,settings.time_now,'-','error','transfer Balance Insufficient')
            else:
                transfer_balance = int(settings.atm_user_data[transfer]['balance'])
                withdraw_balance = int(settings.atm_user_data[account]['balance'])
                if  settings.atm_user_data[transfer] == settings.atm_user_data[account]:
                    print("**********转账人与收账人不能相同**********")
                    loger.loger('ATM.var',account,settings.time_now,'-','error','Transfer and accounts can not be the same')
                else:
                    settings.atm_user_data[transfer]['balance'] = int(user_balance + trans_money)
                    settings.atm_user_data[account]['balance'] = int(user_balance - trans_money)
                    dump_file.dump_file(settings.atm_user_data, settings.atm_user_file_path)
                    loger.loger(account,account,settings.time_now,'transfer',"-"+str(trans_money))
                    loger.loger(transfer,transfer,settings.time_now,'transfer',"+"+str(trans_money))
                    loger.loger('ATM.var',account,settings.time_now,'-','info','transfer'+"-"+str(trans_money))
                    loger.loger('ATM.var',transfer,settings.time_now,'-','info','transfer'+"-"+str(trans_money))
        else:
            print("转入帐号不存在")
            loger.loger('ATM.var',account,settings.time_now,'-','error','transfer account nonexistent')
Ejemplo n.º 9
0
import os, sys
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(base_dir)
from public import dump_file
from configs import settings

dump_file.dump_file(settings.atm_user, settings.atm_user_file_path)
dump_file.dump_file(settings.shop_user, settings.shop_user_file_path)
dump_file.dump_file(settings.manager_user, settings.manager_user_file_path)