示例#1
0
    def login(self, *args):
        '''用户登录'''
        execution_handler = args[1]
        if execution_handler != '>>':
            return execution_handler

        else:
            account_client = args[0]['account']
            password_client = args[0]['password']
            #进行认证
            auth = Auth(db_obj)
            if auth.auth(account_client, password_client):
                new = "True"
                logger.info(account_client + '用户接入')
                self.request.send(new.encode())
                #防止粘包
                a = self.request.recv(1024)
                execution_handler = '/' + account_client + '>>'
                return execution_handler
            else:
                new = "用户名或者密码错误,请重新输入"
                self.request.send(new.encode())
                time.sleep(0.5)
            return False
TEST_PASSWORD = "******"

TEST_EAN = "0000000000000"

path = os.path.abspath(__file__)
ROOT = os.path.dirname(path)

db = DbService()

############ test auth ######################
auth = Auth(db)
token = auth.register(TEST_EAN, "test name", TEST_PASSWORD)

print "token = " + token
res = auth.auth(TEST_EAN, TEST_PASSWORD)
user_id = res[0]
if not res[0]:
    print 'auth not success', res[1]
    exit(1)

print "auth success", res[1]
token = res[1]

res = auth.check_token(TEST_EAN, token)
if not res:
    print 'check_token not success'
    exit(1)

print "check_token success", res