예제 #1
0
파일: token.py 프로젝트: jcsy521/ydws
    def post(self):
        """Check the sid and return token.
        """
        status = ErrorCode.SUCCESS
        token = u'' 
        try:
            data = DotDict(json_decode(self.request.body))
            sid = data.sid
            timestamp = str(data.timestamp)
            sign = data.sign
            logging.info("[TOKEN] Request, data: %s", data)
        except Exception as e:
            status = ErrorCode.DATA_FORMAT_INVALID
            logging.exception("[TOKEN] Invalid data format, body: %s.",
                              self.request.body)
            self.write_ret(status)
            return

        try:
            sp = self.db.get("SELECT sid, password, cid, mobile FROM T_SP"
                             " WHERE sid = %s ",
                             sid)
            if (not sp) or (not sp.get('cid','')): 
                status = ErrorCode.SID_NOT_EXISTED
                logging.info("[TOKEN] Get token failed. sid: %s, Message: %s.",
                             sid, ErrorCode.ERROR_MESSAGE[status])
                self.write_ret(status)
                return

            password = sp.password                
            if (not sign) or not OpenapiHelper.check_sign(sign, password, timestamp):
                is_valid = False
            else:
                is_valid = True

            if is_valid:
                token = OpenapiHelper.get_token(self.redis, sp)
            else:                                       
                status = ErrorCode.SIGN_ILLEGAL
                logging.info("[TOKEN] Get token failed. Message: %s.",
                             ErrorCode.ERROR_MESSAGE[status])                   
                                                
            self.write_ret(status,
                           dict_=dict(token=token))

        except Exception as e:
            logging.exception("[TOKEN] Get token failed. sid: %s. Exception: %s",
                              sid, e.args)
            status = ErrorCode.FAILED
            self.write_ret(status)
예제 #2
0
파일: test.py 프로젝트: jcsy521/ydws
    def post(self):
        """Get last infomation of a terminal.
        """
        status = ErrorCode.SUCCESS
        sign = ""
        try:
            data = DotDict(json_decode(self.request.body))
            password = data.password
            timestamp = str(data.timestamp)
            logging.info("[TEST] Request, data:%s", data)
        except Exception as e:
            status = ErrorCode.DATA_FORMAT_INVALID
            logging.exception("[TEST] Invalid data format, body: %s. Exception: %s", self.request.body, e.args)
            self.write_ret(status)
            return

        try:
            sign = OpenapiHelper.get_sign(password, timestamp)
            self.write_ret(status, dict_=dict(sign=sign))

        except Exception as e:
            logging.exception(
                "[TEST] Get sign failed. password: %s, timestamp:%s, Exception: %s", password, timestamp, e.args
            )
            status = ErrorCode.FAILED
            self.write_ret(status)