예제 #1
0
def login():
    Session = create_session()
    error_num = 0
    login_status = 0
    while error_num < 5:
        error_num += 1
        tips = f'{error_num:-^20}'
        print(tips)
        login_name = input('登录名:').strip()
        login_password_tmp = input('登陆密码:').strip()

        obj = Session.query(LoginMsg).filter_by(login_name=login_name).first()

        if not obj:
            error = ERROR[3]
            print(f'\n{error:!^40}\n')
        else:
            if obj.login_password == md5_msg(login_password_tmp):
                print(f'{login_name} 登录成功')
                login_status = 1
                return obj.id, login_status
            else:
                warning = WARNING[3]
                print(f'\n{warning:-^60}\n')
    else:
        warning = WARNING[0]
        print(f'\n{warning:-^60}\n')
        return None, login_status
예제 #2
0
def get_account_obj():
    account_obj_ls = get_account_obj_list()
    if account_obj_ls:
        for account_obj in account_obj_ls:
            user_id, user_type, user_name = admin.AdminModels(
                obj=account_obj,
                session=models.create_session()).view_simple_msg()
            user_password = '******'
            account_simple_msg = f'|{user_id:<9}|{user_name:<20}|{user_password:<20}|{user_type}'
            print(account_simple_msg)
        return 1
    else:
        warning = WARNING[1]
        print(f'\n{warning:-^60}\n')
        return 0
예제 #3
0
 def inner(*args, **kwargs):
     Session = models.create_session()
     obj = Session.query(
         models.LoginMsg).filter_by(login_name=name).first()
     _password = obj.login_password
     error_num = 0
     while error_num < 3:
         error_num += 1
         tips = f'{error_num:-^20}'
         print(tips)
         password = input('请输入管理员密码:').strip()
         if _password == md5_msg(password):
             return func(*args, **kwargs)
         else:
             print('密码错误')
     else:
         print('错误次数太多!!!')
예제 #4
0
 def inner(*args, **kwargs):
     Session = create_session()
     obj = Session.query(LoginMsg).filter_by(login_name=name).first()
     _password = obj.login_password
     error_num = 0
     while error_num < 3:
         error_num += 1
         tips = f'{error_num:-^20}'
         print(tips)
         # password = input('请输入管理员密码:').strip()
         password = getpass.getpass('请输入管理员密码:')
         if _password == md5_msg(password):
             return func(*args, **kwargs)
         else:
             warning = WARNING[3]
             print(f'\n{warning:-^60}\n')
     else:
         warning = WARNING[0]
         print(f'\n{warning:-^60}\n')
예제 #5
0
class AdminLoginMsg:

    Session = models.create_session()
    login_name = ADMINISTRATOR

    def __init__(self, login_password):
        self.login_password = login_password

    @logger_a
    def create_admin_account(self):
        obj = models.LoginMsg(login_name=self.login_name,
                              login_password=md5_msg(self.login_password))
        find_obj = self.Session.query(
            models.LoginMsg).filter_by(login_name=self.login_name).first()
        # 避免创建重复的管理员账户
        if not find_obj:
            self.Session.add(obj)
            self.Session.commit()
        else:
            print('WARNING:管理员密码已设置,请不要重复设置')
예제 #6
0
def get_account_obj_list():
    Session = models.create_session()
    obj = Session.query(
        models.LoginMsg).filter_by(login_name=ADMINISTRATOR).first()
    obj_account_list = obj.account_msg
    return obj_account_list
예제 #7
0
#!/usr/bin/env python3
# coding=utf-8

"""
@File:auth.py
@Author:seeker0720
@Date:2019/10/7 19:20
@Instructions:
"""
import getpass
from core.models import create_session, LoginMsg
from core.common import md5_msg
from conf.settings import WARNING,ERROR

Session = create_session()


def log_inner(func):
    def wrapper(*args, **kwargs):
        error_num = 0
        while error_num < 5:
            error_num += 1
            tips = f'{error_num:-^20}'
            print(tips)
            login_name = input('登录名:').strip()
            login_password_tmp = input('登陆密码:').strip()
            obj = Session.query(LoginMsg).filter_by(login_name=login_name).first()

            if not obj:
                print('用户不存在')
            else:
예제 #8
0
def run():
    while True:
        common.options()
        common.tips()
        choice = input('请输入选项对应的数字(1~4):').strip()
        if choice == 'q' or choice == 'Q':
            choice = '0'
        if not choice.isdigit():
            error = ERROR[0]
            print(f'\n{error:!^40}\n')
            continue
        if not int(choice) in range(5):
            error = ERROR[0]
            print(f'\n{error:!^40}\n')
            continue
        if choice == '1':
            # common.get_account_obj()
            if common.get_account_obj() == 0:
                continue
            user_id = input('选择对应的 USER_ID 查看全部信息:').strip()

            if user_id.isdigit():
                user_id = user_id
                session = models.create_session()
                obj = session.query(models.AccountMsg).filter_by(id=user_id).first()
                if not obj:
                    error = ERROR[1]
                    print(f'\n{error:!^40}\n')
                    continue
                try:
                    user_id, user_type, user_name, user_password = Am(obj=obj, session=session).view_detail_msg()
                except TypeError:
                    pass
                else:
                    common.output_detail_msg(user_id=user_id,
                                             user_name=user_name,
                                             user_password=user_password,
                                             user_type=user_type)
            else:
                error = ERROR[2]
                print(f'\n{error:!^40}\n')
        elif choice == '2':
            session = models.create_session()
            Aa(session=session).insert_msg()
        elif choice == '3':
            # common.get_account_obj()
            if common.get_account_obj() == 0:
                continue
            user_id = input('选择要修改信息的 USER_ID :').strip()

            if user_id.isdigit():
                user_id = user_id
                session = models.create_session()
                obj = session.query(models.AccountMsg).filter_by(
                    id=user_id).first()
                if not obj:
                    error = ERROR[1]
                    print(f'\n{error:!^40}\n')
                    continue
                new_password = input('输入新的密码:').strip()
                if new_password:
                    Am(obj=obj, session=session).modify_password(new_password=new_password)
            else:
                error = ERROR[2]
                print(f'\n{error:!^40}\n')
        elif choice == '4':
            # common.get_account_obj()
            if common.get_account_obj() == 0:
                continue
            user_id = input('选择要删除信息的 USER_ID :').strip()

            if user_id.isdigit():
                user_id = user_id
                session = models.create_session()
                obj = session.query(models.AccountMsg).filter_by(
                    id=user_id).first()
                if not obj:
                    error = ERROR[1]
                    print(f'\n{error:!^40}\n')
                    continue
                Am(obj=obj, session=session).delete_msg()
            else:
                error = ERROR[2]
                print(f'\n{error:!^40}\n')
        else:
            break
예제 #9
0
class TmpBase:
    Session = models.create_session()
    login_name = ADMINISTRATOR