Ejemplo n.º 1
0
class Auth:
    """
    用于做登录和注册
    """

    # 单例模式,防止连续登录而创建多个socket连接
    __instance = None
    def __new__(cls, *args, **kwargs):
        if not cls.__instance:
            obj = object.__new__(cls)
            cls.__instance = obj
        return cls.__instance

    def __init__(self):
        self.socket = MySocketClient()  # 拿到了sk 连接
        self.username = None

    def login(self):
        username = input('username: '******'password: '******'t recognize space, so don't input space just in case
        if username.strip() and password.strip():
            self.socket.mysend({'username': '******',
                            'password': '******', 'operation': 'login' })
        ret = self.socket.sk.recv(1024)  # 获得登录结果

    def register(self):
        username = input('username: '******'password: '******'ensure_password: '******'username': '******',
                            'password': '******', 'operation': 'register'})

        ret = self.socket.sk.recv(1024)  # 获得注册结果
Ejemplo n.º 2
0
class Auth:
    def __init__(self):
        self.socket = MySocketClient()  # 组合:一个对象的属性是另一个类的对象
        self.username = None

    def login(self):
        username = input('username:'******'password:'******'username': username,
                'password': password,
                'operation': 'login'
            }
            self.socket.mysend(msg)
        ret = self.socket.sk.recv(1024)
        return ret

    def register(self):
        username = input('username:'******'password:'******'password_ensure:')
        if username.strip() and password1.strip() and password1 == password2:
            # send
            msg = {
                'username': username,
                'password': password1,
                'operation': 'register'
            }
            self.socket.mysend(msg)
        ret = self.socket.sk.recv(1024)
        return ret
Ejemplo n.º 3
0
class Auth:
    def __init__(self):
        self.sk = MySocketClient()  #感觉这里直接用self=MySocketClient()
        self.username = None

    def login(self):
        username = input('username:'******'password:'******'username': username, 'password': password})
Ejemplo n.º 4
0
 def __new__(cls, *args, **kwargs):
     if not cls.__instance:
         obj = object.__new__(cls)
         obj.socket = MySocketClient()
         obj.username = None
         cls.__instance = obj
     return cls.__instance
Ejemplo n.º 5
0
class Auth:
    __instance = None

    def __new__(cls, *args, **kwargs):
        if not cls.__instance:
            obj = object.__new__(cls)
            cls.__instance = obj
        return cls.__instance

    def __init__(self):
        self.socket = MySocketClient()
        self.username = None

    def login(self):
        username = input('username: '******'password: '******'username': username,
                'password': password,
                'operation': 'login'
            })
        ret = self.socket.sk.recv(1024)  #登录成功的结果
        return ret

    def register(self):
        username = input('username: '******'password: '******'password: '******'username': username,
                'password': password1,
                'operation': 'register'
            })
        ret = self.socket.sk.recv(1024)  #注册成功的结果
        return ret
Ejemplo n.º 6
0
class Auth(object):
    __instance = None

    def __new__(cls, *args, **kwargs):
        '''单例模式,为了防止重复登录连接'''
        if not cls.__instance:
            obj = object.__new__(cls)
            cls.__instance = obj
        return cls.__instance

    def __init__(self):
        self.socket = MySocketClient()
        self.username = None

    def login(self):
        username = input('username: '******'password: '******'username': username,
                'password': passwd,
                'operation': 'login'
            })
        ret = self.socket.sk.recv(1024)  # 登录的结果

    def register(self):
        username = input('username: '******'password: '******'password_ensure: ')
        if username.strip() and passwd.strip() and passwd == passwd1:
            self.socket.mysend({
                'username': username,
                'password': passwd,
                'operation': 'register'
            })
        ret = self.socket.sk.recv(1024)  # 注册的结果
Ejemplo n.º 7
0
class Auth:
    __instance = None

    def __new__(cls, *args, **kwargs):
        #单例模式
        if not cls.__instance:
            obj = object.__new__(cls)
            cls.__instance = obj
        return cls.__instance

    def __init__(self):
        self.socket = MySocketClient()
        self.username = None

    def login(self):
        username = input('请输入用户名:')
        password = input('请输入密码:')
        if username.strip() and password.strip():
            self.socket.mysend({
                'username': username,
                'password': password,
                'operation': 'login'
            })
        else:
            print('用户名,密码不能为空')
            return
        ret = self.socket.myrecv()
        print(ret)

    def register(self):
        while True:
            username = input('请输入要注册的用户名:')
            passworld1 = input('请输入密码:')
            passworld2 = input('请确认密码:')
            if username == '' or passworld1 == '':
                print('用户名,密码不能为空')
            elif username.strip() and passworld1.strip() == passworld2.strip():
                self.socket.mysend({
                    'username': username,
                    'password': passworld2,
                    'operation': 'register'
                })
                ret = self.socket.myrecv()
                print(ret)
                return
            else:
                print('密码输入错误')
Ejemplo n.º 8
0
 def __init__(self):
     self.socket = MySocketClient()
     self.username = None
Ejemplo n.º 9
0
 def __init__(self):
     self.socket = MySocketClient()  # 组合:一个对象的属性是另一个类的对象
     self.username = None
Ejemplo n.º 10
0
 def __init__(self):
     self.sk = MySocketClient()  #感觉这里直接用self=MySocketClient()
     self.username = None