Exemplo n.º 1
0
    def post(self):
        args = self.request.arguments
        if 'givemejson' in args.keys():
            self._go_back_format = True

        pb2 = self.get_argument('pb2')
        rqmsg = msgws.rqUserLogin()
        msg = msgws.UserLogin()
        msg.head.ver = 160328
        msg.head.if_dt = int(time.time())
        try:
            rqmsg.ParseFromString(base64.b64decode(pb2))
            msg.head.idx = rqmsg.head.idx
            msg.head.if_st = 1
        except:
            msg.head.if_st = 46

        # 检查用户名密码是否合法
        strsql = 'select user_id,user_name,user_real_name,user_phonenumber,user_remark from {0}.user_list \
        where user_name="{1}" and user_password="******"'.format(
            self._db_name, rqmsg.user.replace('"', ''),
            rqmsg.pwd.replace('"', ''))
        record_total, buffer_tag, paging_idx, paging_total, cur = yield self.mydata_collector(
            strsql, need_fetch=1, need_paging=0)

        if record_total is None or record_total == 0:
            msg.head.if_st = 0
            msg.head.if_msg = 'Wrong username or password'
            yield self.write_event(121,
                                   'login from {0} failed'.format(
                                       self.request.remote_ip),
                                   2,
                                   user_name=rqmsg.user,
                                   app_unique=rqmsg.head.unique)
        else:
            for d in cur:
                msg.user_id = d[0]
                msg.user = d[1]
                msg.fullname = d[2] if d[2] is not None else ''
                msg.mobile = int(d[3]) if d[3] is not None else 0
                msg.remark = d[4] if d[4] is not None else ''
                break
            yield self.write_event(121,
                                   'login from {0} success'.format(
                                       self.request.remote_ip),
                                   2,
                                   user_name=rqmsg.user,
                                   app_unique=rqmsg.head.unique)

        self.write(mx.code_pb2(msg, self._go_back_format))
        self.finish()
Exemplo n.º 2
0
Arquivo: iftest.py Projeto: xyzj/lump
def test_userlogin():
    global user_id
    print('=== login ===')
    url = baseurl + 'userlogin'
    rqmsg = init_head(msgif.rqUserLogin())
    rqmsg.dev = 1
    rqmsg.unique = 'asdfhaskdfkaf'
    rqmsg.user = u'dgc'
    rqmsg.pwd = u'1234'
    # rqmsg.user = '******'
    # rqmsg.pwd = '123'
    data = {'pb2': base64.b64encode(rqmsg.SerializeToString())}
    # data = {'pb2': 'ChwQyOQJKg84NjA3MTYwMzA4MTQ0OTWgBsGv2ssFEAMaDzg2MDcxNjAzMDgxNDQ5NSIFYWRtaW4q\nBDEyMzQ=\n'}
    # r = tc.fetch(url, 'POST', body=urllib.urlencode(data), raise_error=True, request_timeout=10)
    r = pm.request('POST', url, fields=data, timeout=100.0, retries=False)
    # print(r)
    msg = msgif.UserLogin()
    msg.ParseFromString(base64.b64decode(r.data))
    user_id = msg.uuid
    print(msg)
    time.sleep(0)
Exemplo n.º 3
0
    def post(self):
        pb2 = self.get_argument('pb2')
        rqmsg = msgws.rqUserLogin()
        msg = msgws.UserLogin()
        msg.head.ver = 160328
        msg.head.if_dt = int(time.time())
        try:
            rqmsg.ParseFromString(base64.b64decode(pb2))
            msg.head.idx = rqmsg.head.idx
            msg.head.if_st = 1
        except:
            msg.head.if_st = 46

        # 检查用户名密码是否合法
        strsql = 'select user_id,user_name,user_pwd,user_mobile,user_tel,user_email,user_remark from  {2}.user_info \
        where binary user_name="{0}" and user_pwd="{1}"'.format(rqmsg.user,rqmsg.pwd,self._db_uas)
        record_total, buffer_tag, paging_idx, paging_total, cur = yield self.mydata_collector(
            strsql,
            need_fetch=1,
            need_paging=0)
        if record_total is None or record_total == 0:
            yield self.add_eventlog(4, 0, 'Wrong username or password')
            msg.head.if_st = 47
            msg.head.if_msg = 'Wrong username or password'
        else:
            for d in cur:
                msg.user_id = d[0]
                msg.fullname=d[1]
                msg.mobile=d[3] if d[3] is not None else 0
                msg.tel=d[4] if d[4] is not None else ''
                msg.email=d[5] if d[5] is not None else ''
                msg.remark=d[6] if d[6] is not None else ''
                break
            yield self.add_eventlog(4, msg.user_id, 'successfully to login')
            msg.head.if_msg = 'successfully to login'
        print msg
        self.write(mx.convertProtobuf(msg))
        self.finish()
Exemplo n.º 4
0
Arquivo: user.py Projeto: xyzj/lump
    def post(self):
        args = self.request.arguments
        if 'formatmydata' in args.keys():
            self._go_back_format = True
        if 'tcsport' in args.keys():
            self._db_name = 'mydb{0}'.format(args.get('tcsport')[0])

        pb2 = self.get_argument('pb2')
        rqmsg = msgws.rqUserLogin()
        msg = msgws.UserLogin()
        msg.head.ver = 160328
        msg.head.if_dt = int(time.time())
        try:
            rqmsg.ParseFromString(base64.b64decode(pb2))
            msg.head.idx = rqmsg.head.idx
            msg.head.if_st = 1
        except:
            msg.head.if_st = 46

        # 检查用户名密码是否合法
        strsql = 'select user_name,user_real_name,user_phonenumber,user_operator_code,is_user_user_operator_code from {0}.user_list \
        where user_name="{1}" and user_password="******"'.format(
            self._db_name, rqmsg.user.replace('"', ''),
            rqmsg.pwd.replace('"', ''))

        record_total, buffer_tag, paging_idx, paging_total, cur = yield self.mydata_collector(
            strsql, need_fetch=1, need_paging=0)

        if record_total is None or record_total == 0:
            contents = 'login from {0} failed'.format(self.request.remote_ip)
            msg.head.if_st = 40
            msg.head.if_msg = 'Wrong username or password'
        else:
            d = cur[0]
            # 判断用户是否已经登录
            if len(libiisi.cache_user) > 0:
                a = libiisi.cache_user.keys()
                for k in a:
                    ud = libiisi.cache_user.get(k)
                    if ud is not None:
                        # 注销已登录用户
                        if ud['user_name'] == rqmsg.user and ud[
                                'source_dev'] == rqmsg.dev:
                            contents = 'logout by sys because login from {0}'.format(
                                self.request.remote_ip)
                            user_name = libiisi.cache_user[k]['user_name']
                            self.write_event(122,
                                             contents,
                                             2,
                                             user_name=user_name,
                                             app_unique=rqmsg.head.unique)
                            del libiisi.cache_user[k]
                            break
            contents = 'login from {0} success'.format(self.request.remote_ip)
            user_uuid = uuid.uuid1().hex
            msg.uuid = user_uuid
            msg.fullname = d[1] if d[1] is not None else ''
            msg.is_user_operator_code = d[4] if d[4] is not None else 0
            msg.code = d[3] if d[3] is not None else ""
            zmq_addr = libiisi.m_config.getData('zmq_port')
            if zmq_addr.find(':') > -1:
                msg.zmq = '{0},{1}'.format(
                    zmq_addr.split(':')[0],
                    int(zmq_addr.split(':')[0]) + 1)
            else:
                msg.zmq = '{0},{1}'.format(zmq_addr, int(zmq_addr) + 1)

            user_auth = 0
            _area_r = []
            _area_w = []
            _area_x = []
            try:
                strsql = 'select r,w,x,d from {0}.user_rwx where user_name="{1}"'.format(
                    self._db_name, rqmsg.user)
                record_total1, buffer_tag1, paging_idx1, paging_total1, cur1 = yield self.mydata_collector(
                    strsql, need_fetch=1, need_paging=0)

                if record_total1 > 0:
                    for d in cur1:
                        if int(d[3]) == 1:
                            user_auth = 15
                            _area_r = [0]
                            _area_w = [0]
                            _area_x = [0]
                        else:
                            user_auth = 0
                            if d[0] is not None:
                                if len(d[0].split(';')[:-1]) > 0:
                                    user_auth += 4
                                    _area_r = [
                                        int(a) for a in d[0].split(';')[:-1]
                                    ]
                            if d[1] is not None:
                                if len(d[1].split(';')[:-1]) > 0:
                                    user_auth += 2
                                    _area_w = [
                                        int(a) for a in d[1].split(';')[:-1]
                                    ]
                            if d[2] is not None:
                                if len(d[2].split(';')[:-1]) > 0:
                                    user_auth += 1
                                    _area_x = [
                                        int(a) for a in d[2].split(';')[:-1]
                                    ]
                else:
                    contents = 'login failed, database version error.'
                    msg.uuid = ''
                    msg.head.if_st = 0
                    msg.head.if_msg = 'login failed, database version error.'
                del cur1
            except:
                user_auth = 15
                _area_r = [0]
                _area_w = [0]
                _area_x = [0]
            msg.auth = user_auth
            msg.area_r.extend(_area_r)
            msg.area_w.extend(_area_w)
            msg.area_x.extend(_area_x)
            msg.tcs = int(libiisi.cfg_tcs_port)
            # 加入用户缓存{uuid:dict()}
            libiisi.cache_user[user_uuid] = dict(
                user_name=rqmsg.user,
                user_auth=user_auth,
                login_time=time.time(),
                active_time=time.time(),
                user_db=self._db_name,
                area_id=0,
                source_dev=rqmsg.dev,
                unique=rqmsg.unique,
                remote_ip=self.request.remote_ip,
                area_r=set(_area_r),
                area_w=set(_area_w),
                area_x=set(_area_x),
                is_buildin=0)
            del _area_r, _area_w, _area_x

        del cur, strsql

        try:
            x = []
            if len(libiisi.cache_user[user_uuid]["area_r"]) > 0:
                x.append("r")
            if len(libiisi.cache_user[user_uuid]["area_w"]) > 0:
                x.append("w")
            if len(libiisi.cache_user[user_uuid]["area_x"]) > 0:
                x.append("x")
            yield self.update_cache(','.join(x), user_uuid)
            del x
        except Exception as ex:
            pass

        # 登录工作流
        if rqmsg.dev == 3:
            retry = False
            args = {'user_name': rqmsg.user, 'user_password': rqmsg.pwd}
            url = '{0}/mobileLogin?{1}'.format(libiisi.cfg_fs_url,
                                               urlencode(args))
            try:
                rep = yield self.thc.fetch(url,
                                           raise_error=True,
                                           request_timeout=10)
                # rep = utils.m_httpclinet_pool.request('GET',
                #                                       baseurl,
                #                                       fields=args,
                #                                       timeout=2.0,
                #                                       retries=False)
                dom = xmld.parseString(rep.body)
                root = dom.documentElement
                msg.flow_data = root.firstChild.wholeText
                del dom, root
            except Exception as ex:
                print(ex)
                if not retry:
                    retry = True
                    try:
                        rep = yield self.thc.fetch(url,
                                                   raise_error=False,
                                                   request_timeout=3)
                        dom = xmld.parseString(rep.body)
                        root = dom.documentElement
                        msg.flow_data = root.firstChild.wholeText
                        del dom, root
                    except:
                        msg.flow_data = ''
                else:
                    msg.flow_data = ''
                    # print(str(ex))

        self.write(mx.code_pb2(msg, self._go_back_format))
        self.finish()
        self.write_event(121,
                         contents,
                         2,
                         user_name=rqmsg.user,
                         app_unique=rqmsg.head.unique)
        del rqmsg, msg