Exemplo n.º 1
0
def auth(user_type):
    login_info_dis = ['用户名', '密码']
    username, password = input_handle(login_info_dis)
    if username in dbssc('select username from account where rule = %s' %
                         (user_type)):
        if password == dbssv(
                'select password from account where username = %s' %
            (username)) and dbssv(
                'select account_status from account where username = %s' %
                (username)) == 'open':
            userdata['auth_status'] = True
            userdata['userid'] = dbssv(
                'select userid from account where username = %s' % (username))
            userdata['user_type'] = user_type
            log.info('用户 %s 认证登陆成功' % (username))
            return True
        elif dbssv('select account_status from account where username = %s' %
                   (username)) == 'locked':
            log.warn('用户 %s 账户锁定 请求认证失败' % (username))
            print('用户 %s 账户锁定 请求认证失败' % (username))
            return False
        else:
            log.warn('用户 %s 密码错误 请求认证失败' % (username))
            print('用户 %s 密码错误 请求认证失败' % (username))
            return False
    else:
        log.warn('用户 %s 不存在 请求认证失败' % (username))
        print('用户 %s 不存在 请求认证失败' % (username))
        return False
Exemplo n.º 2
0
def dbapi(command):
    """
    数据库接口
    :param command:   接收sql语句传入
    :return: 
    """
    if setting.DBMODE == 'filedb':
        log.info('dbsql: %s'%command.replace('\\',''))
        result = db.sqlapi(setting.DBNAME,command)
        log.debug(result)
        return result
    elif setting.DBMODE == 'mysql':
        pass #todo
Exemplo n.º 3
0
def cencel_account():
    """
    销户
    :return: 
    """
    cencel_account_dis = ['账户名']
    cencel_account_name = input_handle(cencel_account_dis)[0]
    log.debug('销户的账户名%s' % cencel_account_name)

    if cencel_account_name not in dbssc('select username from account'):
        print('账户不存在')
        log.info('账户 %s 不存在' % cencel_account_name)
    else:
        db('delete from party where userid = %d ' %
           (dbssc('select userid from account where username = %s' %
                  (cencel_account_name))[0]))
        db('delete from account where username = %s' % cencel_account_name)
Exemplo n.º 4
0
def uinstall_atmdb():
    """
    清理删除atmdb数据库
    :param dbname:
    :return:
    """
    log.info('------------- database %s drop'%dbname)

    if db('show databases') is not None:
        if dbname in db('show databases'):
            db('drop database %s'%dbname)
            log.info('database %s is drop' % dbname)
        else:
            print('database %s does not exist'%dbname)
            log.warn('database %s does not exist'%dbname)
    else:
        log.warn('database %s does not exist' % dbname)
    log.info('------------- database %s drop end' % dbname)
Exemplo n.º 5
0
def init_atmdb():
    """
    初始化atm数据库
    :return:
    """
    log.info('------------- database %s init'%dbname)
    db('create database %s'%dbname)
    log.info('database %s created'%dbname)
    db('create table account \(userid int auto_increment,'
       'username str not null unique,account_status str,password str,rule str,create_time str\)')
    log.info('init super admin info')
    db('insert into account values \(\'\',admin,open,admin,admin,%s\)'%setting.now)
    log.info('table account created')
    db('create table party \(party_id int auto_increment,'
       'userid int ,card_num str,card_type str,create_time str,card_balance float,card_limit float\)')
    log.info('table party created')
    db('create table transaction_rate \(rate_id int auto_increment,'
       'transaction_type str,transaction_rate float\)')
    db('insert into transaction_rate values \(\'\',withdraw,%s\)' % setting.CASH_WITHDRAWAL_RATE)
    db('insert into transaction_rate values \(\'\',transfer,%s\)' % setting.TRANSFER_RATE)
    db('insert into transaction_rate values \(\'\',repayment,0\)' )
    db('insert into transaction_rate values \(\'\',payment,0\)' )
    log.info('table transaction_rate created')
    db('create table transaction (transaction_id int auto_increment,'
       'transaction_type str,party_id int,counterparty_id int,amount float,tx_amount_dis str,txdate str,txdesc str)')
    log.info('table transaction created')
    log.info('------------- database %s init end' % dbname)