示例#1
0
    async def handle_login(self, request):
        try:
            user_devid = request.match_info.get("devid", "")
            countrycode = request.match_info.get("country", "us")
            confserverlog.info(
                "client with devid {} attempting login".format(user_devid)
            )
            if bumper.use_auth:
                if (
                    not user_devid == ""
                ):  # Performing basic "auth" using devid, super insecure
                    user = bumper.user_by_deviceid(user_devid)
                    if "checkLogin" in request.path:
                        self.check_token(
                            countrycode, user, request.query["accessToken"]
                        )
                    else:
                        # Deactivate old tokens and authcodes
                        bumper.user_revoke_expired_tokens(user["userid"])

                        body = {
                            "code": bumper.RETURN_API_SUCCESS,
                            "data": {
                                "accessToken": self.generate_token(
                                    user
                                ),  # generate a new token
                                "country": countrycode,
                                "email": "*****@*****.**",
                                "uid": "fuid_{}".format(user["userid"]),
                                "username": "******".format(user["userid"]),
                            },
                            "msg": "操作成功",
                            "time": bumper.get_milli_time(
                                datetime.utcnow().timestamp()
                            ),
                        }
                        return web.json_response(body)

                body = {
                    "code": bumper.ERR_USER_NOT_ACTIVATED,
                    "data": None,
                    "msg": "当前密码错误",
                    "time": bumper.get_milli_time(datetime.utcnow().timestamp()),
                }

                return web.json_response(body)

            else:
                return web.json_response(
                    self._auth_any(user_devid, countrycode, request)
                )

        except Exception as e:
            confserverlog.exception("{}".format(e))
示例#2
0
    async def handle_getAuthCode(self, request):
        try:

            user_devid = request.match_info.get("devid", "")
            if not user_devid == "":
                user = bumper.user_by_deviceid(user_devid)
                if user:
                    token = bumper.user_get_token(
                        user["userid"], request.query["accessToken"]
                    )
                    if token:
                        authcode = ""
                        if not "authcode" in token:
                            authcode = self.generate_authcode(
                                user,
                                request.match_info.get("country", "us"),
                                request.query["accessToken"],
                            )
                        else:
                            authcode = token["authcode"]

                        body = {
                            "code": bumper.RETURN_API_SUCCESS,
                            "data": {
                                "authCode": authcode,
                                "ecovacsUid": request.query["uid"],
                            },
                            "msg": "操作成功",
                            "time": bumper.get_milli_time(
                                datetime.utcnow().timestamp()
                            ),
                        }
                        return web.json_response(body)

            body = {
                "code": bumper.ERR_TOKEN_INVALID,
                "data": None,
                "msg": "当前密码错误",
                "time": bumper.get_milli_time(datetime.utcnow().timestamp()),
            }

            return web.json_response(body)

        except Exception as e:
            confserverlog.exception("{}".format(e))
示例#3
0
    async def handle_logout(self, request):                      
        try:
            body = {"code": "0000","data": None,"msg": "操作成功", "time": bumper.get_milli_time(time.time())}
            #TODO - when logging out close out any other connections MQTT/XMPP
            
            return web.json_response(body)        

        except Exception as e:
            logging.error('ConfServer: {}'.format(e))              
示例#4
0
def test_get_milli_time():
    assert_equals(
        bumper.get_milli_time(
            datetime.datetime(2018,
                              1,
                              1,
                              1,
                              0,
                              0,
                              0,
                              tzinfo=datetime.timezone.utc).timestamp()),
        1514768400000,
    )
示例#5
0
    async def handle_checkAgreement(self, request):
        try:
            body = {
                "code": bumper.RETURN_API_SUCCESS,
                "data": [],
                "msg": "操作成功",
                "time": bumper.get_milli_time(datetime.utcnow().timestamp()),
            }

            return web.json_response(body)

        except Exception as e:
            confserverlog.exception("{}".format(e))
示例#6
0
    async def handle_homePageAlert(self, request):              
        try:
            nextAlert = bumper.get_milli_time((datetime.now() + timedelta(hours=12)).timestamp())
            
            body = {
                    "code": "0000",
                    "data": {
                        "clickSchemeUrl": None,
                        "clickWebUrl": None,
                        "hasCampaign": "N",
                        "imageUrl": None,
                        "nextAlertTime": nextAlert,
                        "serverTime": bumper.get_milli_time(time.time())
                    },
                    "msg": "操作成功",
                    "time": bumper.get_milli_time(time.time())
                }   
                                                    
            return web.json_response(body)          

        except Exception as e:
            logging.error('ConfServer: {}'.format(e))              
示例#7
0
    async def handle_checkAgreement(self, request):              
        try:
            body = {
                    "code": "0000",
                    "data": [],
                    "msg": "操作成功",
                    "time": bumper.get_milli_time(time.time())
                
                }     
                                                        
            return web.json_response(body)  

        except Exception as e:
            logging.error('ConfServer: {}'.format(e))              
示例#8
0
    async def handle_homePageAlert(self, request):
        try:
            nextAlert = bumper.get_milli_time(
                (datetime.now() + timedelta(hours=12)).timestamp()
            )

            body = {
                "code": bumper.RETURN_API_SUCCESS,
                "data": {
                    "clickSchemeUrl": None,
                    "clickWebUrl": None,
                    "hasCampaign": "N",
                    "imageUrl": None,
                    "nextAlertTime": nextAlert,
                    "serverTime": bumper.get_milli_time(datetime.utcnow().timestamp()),
                },
                "msg": "操作成功",
                "time": bumper.get_milli_time(datetime.utcnow().timestamp()),
            }

            return web.json_response(body)

        except Exception as e:
            confserverlog.exception("{}".format(e))
示例#9
0
    def check_token(self, countrycode, user, token):
        if bumper.check_token(user["userid"], token):
            body = {
                "code": bumper.RETURN_API_SUCCESS,
                "data": {
                    "accessToken": token,
                    "country": countrycode,
                    "email": "*****@*****.**",
                    "uid": "fuid_{}".format(user["userid"]),
                    "username": "******".format(user["userid"]),
                },
                "msg": "操作成功",
                "time": bumper.get_milli_time(datetime.utcnow().timestamp()),
            }
            return web.json_response(body)

        else:
            body = {
                "code": bumper.ERR_TOKEN_INVALID,
                "data": None,
                "msg": "当前密码错误",
                "time": bumper.get_milli_time(datetime.utcnow().timestamp()),
            }
            return web.json_response(body)
示例#10
0
    def _auth_any(self, devid, country, request):
        try:
            user_devid = devid
            countrycode = country
            user = bumper.user_by_deviceid(user_devid)
            bots = bumper.db_get().table("bots").all()

            if user:  # Default to user 0
                tmpuser = user
                bumper.user_add_device(tmpuser["userid"], user_devid)
            else:
                bumper.user_add("tmpuser")  # Add a new user
                tmpuser = bumper.user_get("tmpuser")
                bumper.user_add_device(tmpuser["userid"], user_devid)

            for bot in bots:  # Add all bots to the user
                bumper.user_add_bot(tmpuser["userid"], bot["did"])

            if "checkLogin" in request.path:  # If request was to check a token do so
                checkToken = self.check_token(
                    countrycode, tmpuser, request.query["accessToken"]
                )
                isGood = json.loads(checkToken.text)
                if isGood["code"] == "0000":
                    return isGood

            # Deactivate old tokens and authcodes
            bumper.user_revoke_expired_tokens(tmpuser["userid"])

            body = {
                "code": bumper.RETURN_API_SUCCESS,
                "data": {
                    "accessToken": self.generate_token(tmpuser),  # Generate a token
                    "country": countrycode,
                    "email": "*****@*****.**",
                    "uid": "fuid_{}".format(tmpuser["userid"]),
                    "username": "******".format(tmpuser["userid"]),
                },
                "msg": "操作成功",
                "time": bumper.get_milli_time(datetime.utcnow().timestamp()),
            }

            return body

        except Exception as e:
            confserverlog.exception("{}".format(e))
示例#11
0
 async def handle_getAuthCode(self, request):                      
     try:
         countrycode = request.match_info.get('country', "us")       
         body = {
                 "code": "0000",
                 "data": {
                 "authCode": "{}_tempauthcode".format(countrycode), #countrycode_randomchars(32)
                 "ecovacsUid": "fuid_{}".format(''.join(random.sample(string.ascii_letters,6))) #Date(14)_RandomChars(32)
                 },
                 "msg": "操作成功",
                 "time": bumper.get_milli_time(time.time())
                 }         
                                                     
         return web.json_response(body)      
     
     except Exception as e:
         logging.error('ConfServer: {}'.format(e))              
示例#12
0
    async def handle_checkVersion(self, request):
        try:
            body = {
                "code": bumper.RETURN_API_SUCCESS,
                "data": {
                    "c": None,
                    "img": None,
                    "r": 0,
                    "t": None,
                    "u": None,
                    "ut": 0,
                    "v": None,
                },
                "msg": "操作成功",
                "time": bumper.get_milli_time(datetime.utcnow().timestamp()),
            }

            return web.json_response(body)

        except Exception as e:
            confserverlog.exception("{}".format(e))
示例#13
0
    async def handle_checkVersion(self, request):              
        try:
            body = {
                    "code": "0000",
                    "data": {
                        "c": None,
                        "img": None,
                        "r": 0,
                        "t": None,
                        "u": None,
                        "ut": 0,
                        "v": None
                    },
                    "msg": "操作成功",
                    "time": bumper.get_milli_time(time.time())
                }        
                                                        
            return web.json_response(body)            

        except Exception as e:
            logging.error('ConfServer: {}'.format(e))              
示例#14
0
 async def handle_login(self, request):              
     try:
         #Could implement basic auth if you wanted, or just accept anything    
         countrycode = request.match_info.get('country', "us")            
         body = {
                 "code": "0000",
                 "data": {
                 "accessToken": "tempaccesstoken", #Random chars 32 length
                 "country": countrycode,
                 "email": "*****@*****.**",
                 "uid": "fuid_{}".format(''.join(random.sample(string.ascii_letters,6))), #Date(14)_RandomChars(32)
                 "username": "******".format(''.join(random.sample(string.ascii_letters,6))) #Random chars 8
                 },
                 "msg": "操作成功",
                 "time": bumper.get_milli_time(time.time())
                 }    
                                             
         return web.json_response(body)
     
     except Exception as e:
         logging.error('ConfServer: {}'.format(e))              
示例#15
0
 async def handle_checkLogin(self, request):              
     try:
         # The app seems to remember it's last uid and accessToken
         # If these don't match, it fails
         countrycode = request.match_info.get('country', "us")            
         body = {
                 "code": "0000",
                 "data": {
                 "accessToken": "tempaccesstoken", #Random chars 32 length
                 "country": countrycode,
                 "email": "*****@*****.**",
                 "uid": "fuid_{}".format(''.join(random.sample(string.ascii_letters,6))), #Date(14)_RandomChars(32)
                 "username": "******".format(''.join(random.sample(string.ascii_letters,6))) #Random chars 8
                 },
                 "msg": "操作成功",
                 "time": bumper.get_milli_time(time.time())
                 }    
                                             
         return web.json_response(body)        
     
     except Exception as e:
         logging.error('ConfServer: {}'.format(e))  
示例#16
0
    async def handle_logout(self, request):
        try:
            user_devid = request.match_info.get("devid", "")
            if not user_devid == "":
                user = bumper.user_by_deviceid(user_devid)
                if user:
                    if bumper.check_token(user["userid"], request.query["accessToken"]):
                        # Deactivate old tokens and authcodes
                        bumper.user_revoke_token(
                            user["userid"], request.query["accessToken"]
                        )

            body = {
                "code": bumper.RETURN_API_SUCCESS,
                "data": None,
                "msg": "操作成功",
                "time": bumper.get_milli_time(datetime.utcnow().timestamp()),
            }

            return web.json_response(body)

        except Exception as e:
            confserverlog.exception("{}".format(e))