Пример #1
0
    def process(self):
        trackinginput = self.parameters.get('body')
        TrackingService.tracking(trackinginput)

        logging.info(
            f"支付网关收到支付宝的notify,需要执行thunderservice的发货动作: {trackinginput}")

        FinishOrderViewbody = self.parameters.get('body')
        order_id = str(FinishOrderViewbody.get('out_trade_no'))
        paymentSN = str(FinishOrderViewbody.get('trade_no'))
        paymentTime = str(FinishOrderViewbody.get('timestamp'))
        sign = str(FinishOrderViewbody.get('sign'))

        if self.check_sign(order_id, paymentSN, paymentTime, sign):

            order = OrderService.get_expressorder(order_id)
            if order:
                if order.thunderserviceStatus == "1":
                    logging.info(
                        f"已经开通了服务,可能是重复调用,不操作:thunder service already fulfilled"
                    )
                    return {
                        "code": 200,
                        "message": "thunder service already fulfilled"
                    }, 200

                try:
                    OrderService.mark_paid_order(order.id)
                    OrderService.make_fulfill(order.id)

                    #发送mqtt通知给app
                    message = {
                        "cmd_id": str(int(time.time() * 1000)),
                        "action": "payment_completed",
                        "timestamp": int(time.time()),
                        "expired_on": int(time.time()) + 300
                    }
                    send_single_message(user_id=order.user_id,
                                        message=json.dumps(message))

                    logging.info(f"开通服务成功:thunder service all set")
                    return {
                        "code": 200,
                        "message": "thunder service all set"
                    }, 200
                except:
                    logging.error(f"开通服务失败:5006")
                    return {"code": 5006, "message": returncode['5006']}, 200
            else:
                logging.error(f"开通服务失败:4013")
                return {"code": 4013, "message": returncode['4013']}, 200
        else:
            logging.error(f"开通服务失败:4027")
            return {"code": 4027, "message": returncode['4027']}, 200
Пример #2
0
    def process(self):
        data = request.get_json()
        if not data.get('pager'):
            pageNum = 1
            pageSize =10
        else:
            if data['pager'].get('pageNum'):
                pageNum = data['pager']['pageNum']
            else:
                pageNum = 1

            if data['pager'].get('pageSize'):
                pageSize = data['pager']['pageSize']
            else:
                pageSize = 10

        if data.get('searchData'):
            userID = data['searchData'].get('userID')
            content = data['searchData'].get('content')
            result = data['searchData'].get('result')
        else:
            userID = None
            content = None
            result = None

        list= TrackingService.search(pageNum,pageSize,userID,content,result)

        return (list)
Пример #3
0
    def process(self):
        trackinginput = self.parameters.get('body')
        user_body = self.parameters.get('body')
        print(user_body)
        try:
            user_id = user_body.get('user_id')
            diagnoses = user_body.get('diagnoses')
            feedback = user_body.get('feedback')
        except:
            return {
                "code": 5004,
                "message": returncode['5004'],
            }, 200

        trackingoutput = "接收feedback成功"
        TrackingService.tracking(trackinginput, trackingoutput, user_id)

        return {"code": 200, "message": "发送反馈信息成功", "results": {}}
Пример #4
0
    def process(self):
        trackinginput = self.parameters.get('body')
        print("1", time.time() * 1000)
        user_body = self.parameters.get('body')
        user = UserService.get_user_by_email(user_body['email'])

        print("2", time.time() * 1000)

        logging.info("UserLoginView,email:{}".format(user_body['email']))
        if not user:
            return {
                       "code": 4001,
                       "message": returncode['4001'],
                   }, 401

        if (user_body['password'] == user.password):
            # if user.check_password(user_body['password']):
            print("3", time.time() * 1000)
            token = jwt.encode(
                {'user_id': user.id, 'exp': datetime.datetime.utcnow() + datetime.timedelta(minutes=300)},
                flask_app.config['SECRET_KEY'])
            refreshToken = jwt.encode({'user_id': user.id, 'type': 'refresh',
                                       'exp': datetime.datetime.utcnow() + datetime.timedelta(minutes=14400)},
                                      flask_app.config['SECRET_KEY'])
            UserService.save_token(user.id, token, refreshToken)
            db.session.commit()
            print("4", time.time() * 1000)

            pwresource = UserService.get_user_service_password(user.id)
            if pwresource:
                thunderservice_password = pwresource.oripassword
            else:
                thunderservice_password = '******'  # 万一没有,就拿这个顶
                logging.info(
                    "UserLoginView. This user :{} do not have thunderservice password, use reserved insteed".format(
                        user_body['email']))

            print("5", time.time() * 1000)

            routes = RouteService.get_routes_by_group_ID(user.usergroup_id)

            print("6", time.time() * 1000)

            routes_info = list()
            for route in routes:
                routes_info.append({
                    'id': route.id,
                    'usergroup_id': route.usergroup_id,
                    'sequence': route.sequence,
                    'online': route.online,
                    'domain': route.domain,
                    'port': route.port,
                    # 'ipaddress': route.ipaddress,
                    'servernameEN': route.servernameEN,
                    'servernameCN': route.servernameCN,
                    # 'routeStarttime': route.routeStarttime,
                    # 'trafficLimit': route.trafficLimit,
                    # 'trafficUsed': route.trafficUsed,
                    # 'trafficResetDay': route.trafficResetDay,
                    'password': thunderservice_password
                })
            print("7", time.time() * 1000)
            trackingoutput = "成功"
            TrackingService.tracking(trackinginput,trackingoutput, user.id)
            print("8", time.time() * 1000)
            return {
                "code": 200,
                "message": "login success",
                "results": {
                    "user": {
                        "user_id": user.id,
                        "thunderservice_id": user.thunderservice_id,
                        "thunderservice_endtime": user.thunderservice_endtime,
                        "usergroup_id": user.usergroup_id
                    },
                    "routes": routes_info,
                    "credential": {
                        "token": token.decode('UTF-8'),
                        "refreshToken": refreshToken.decode('UTF-8')
                    }
                }
            }

        return {
                   "code": 4002,
                   "message": returncode['4002'],
               }, 401
Пример #5
0
    def process(self):
        trackinginput = self.parameters.get('body')
        user_body = self.parameters.get('body')
        user = UserService.get_user_by_email(user_body['email'])

        logging.info(f"AppUserLoginView,request:{user_body}")
        if not user:
            logging.error("ERROR: AppUserLoginView: 4001")
            return {
                "code": 4001,
                "message": returncode['4001'],
            }, 200

        if (user_body['password'] == user.password):
            # if user.check_password(user_body['password']):
            token = jwt.encode(
                {
                    'user_id':
                    user.id,
                    'exp':
                    datetime.datetime.utcnow() +
                    datetime.timedelta(minutes=300)
                }, flask_app.config['SECRET_KEY'])
            refreshToken = jwt.encode(
                {
                    'user_id':
                    user.id,
                    'type':
                    'refresh',
                    'exp':
                    datetime.datetime.utcnow() +
                    datetime.timedelta(minutes=14400)
                }, flask_app.config['SECRET_KEY'])
            UserService.save_token(user.id, token, refreshToken)
            db.session.commit()

            pwresource = UserService.get_user_service_password(user.id)

            if pwresource:
                thunderservice_password = pwresource.oripassword
            else:
                thunderservice_password = '******'  # 万一没有,就拿这个顶
                logging.info(
                    "AppUserLoginView. This user :{} do not have thunderservice password, use reserved insteed"
                    .format(user_body['email']))

            if str(user.thunderservice_id) not in thunder_service_ID['FUFEI']:
                thunderservice_password = '******'

            routes = RouteService.get_routes_by_group_ID(user.usergroup_id)

            routes_info = list()
            for route in routes:
                routes_info.append({
                    'id': route.id,
                    'servernameEN': route.servernameEN,
                    'servernameCN': route.servernameCN,
                    'remoteAddr': route.domain,
                    'remotePort': route.port,
                    'password': thunderservice_password,
                    "ipv6": route.ipv6,
                    "statusCN": "正常",
                    "statusEN": "Available",
                    "isValid": route.online
                })

            trackingoutput = "成功"
            TrackingService.tracking(trackinginput, trackingoutput, user.id)

            device = user_body.get('deviceType') if user_body.get(
                'deviceType') else 'Unknown'
            thunderservice = user.thunderservice_id
            # if thunderservice in (thunder_service_ID['LOW_SPEED'] or thunder_service_ID['TRIAL']):
            KService_action = '102'
            # thunderservice exits and is a VIP
            if thunderservice and str(
                    thunderservice) in thunder_service_ID['FUFEI']:
                KService_action = '103'
            KService.add_record(action=KService_action,
                                parameter1=user.id,
                                parameter2=device,
                                timestamp=int(time.time()))

            thunderservice_name = thunder_service_name[str(thunderservice)]

            user_info = {
                "user_id":
                user.id,
                "name":
                user.email,
                "period":
                time.strftime("%Y-%m-%d",
                              time.localtime(user.thunderservice_endtime)),
                "invitationcode":
                user.individual_coupon,
                "client_group_id":
                user.thunderservice_id,
                "vip":
                thunderservice_name,
                "vip_en":
                thunder_service_nameEN[str(thunderservice)],
                "vip_level":
                user.usergroup_id,
                "validtime":
                2
            }

            user_mqtt = UserService.gen_user_mqtt(user_id=user.id)

            resp = {
                "code": 200,
                "message": "login success",
                "results": {
                    "user_info": user_info,
                    "mqtt": user_mqtt,
                    "ips": routes_info,
                    "credential": {
                        "token": token.decode('UTF-8'),
                        "refreshToken": refreshToken.decode('UTF-8')
                    }
                }
            }

            logging.info(f"AppUserLoginView success. response:{resp}")
            return resp

        logging.error("ERROR: AppUserLoginView: 4002")
        return {
            "code": 4002,
            "message": returncode['4002'],
        }, 200
Пример #6
0
    def process(self):
        trackinginput = self.parameters.get('body')
        user_body = self.parameters.get('body')
        try:
            #检查入参
            try:
                email = user_body.get('email')
            except:
                raise Exception("5004")

            #检查是否有此用户,有的话,发送重置密码链接,否则发送推广链接。
            user = UserService.get_user_by_email(email)
            if user:
                #生成重置密码的唯一值
                password_reset = hashlib.md5(str(
                    time.time()).encode()).hexdigest()

                #构造邮件内容
                website_proxy = SettingService.get_setting_by_name(
                    'api_gateway_0')
                if website_proxy:
                    url = website_proxy.value
                    if url[-1:] != '/':
                        url += '/'
                    url = url + "app/passwordreset?key=" + password_reset
                else:
                    raise Exception('5007')

                subject = "ThunderNetwork密码重置邮件"
                text = f"<p>尊敬的用户:<br/><br/> \
                        您请求了密码重置,请点击<a href='{url}'> {url} </a>重新设置该账户在ThunderNetwork中的密码。\
                        <br/><br/> \
                        如果没有自动打开浏览器页面,也可以复制上述链接到浏览器中进行设置。 \
                        <br/><br/> \
                        本次密码重置的请求,在24小时内有效。"

                #发重置密码邮件
                if PushService.sendMail("user.id", email, {
                        "type": "passwordreset",
                        "subject": subject,
                        "text": text
                }):
                    #把password_reset写入到user表
                    update_data = {
                        "password_reset": password_reset,
                        "password_reset_timestamp": int(time.time())
                    }
                    UserService.modify_user_by_id(user.id, update_data)
                    db.session.commit()

                #操作结束
                trackingoutput = "发送找回密码邮件成功"
                TrackingService.tracking(trackinginput, trackingoutput)

            else:
                #发推广邮件
                PushService.sendMail("", email, "")

            return {
                "code": 200,
                "message": "已经为您的邮箱发送了重置密码的邮件,请根据邮件内容进行操作。",
                "results": {}
            }

        except Exception as ex:
            logging.error(ex)
            logging.error(returncode[ex.args[0]])
            return {"code": ex.args[0], "message": returncode[ex.args[0]]}, 200
Пример #7
0
    def process(self):
        trackinginput = self.parameters.get('body')
        user_body = self.parameters.get('body')
        logging.info(f"AppRefreshTokenView, request:{user_body}")
        print(user_body)
        try:
            user_id = user_body.get('user_id')
            refreshToken = user_body.get('refreshToken')
        except:
            logging.info(f"AppRefreshTokenView,result:5004")
            return {
                "code": 5004,
                "message": returncode['5004'],
            }, 200

        user = UserService.get_user(user_id)

        if not user:
            logging.info(f"AppRefreshTokenView,result:4011")
            return {
                "code": 4011,
                "message": returncode['4011'],
            }, 200

        print(refreshToken)
        print(user.refreshToken)
        # 判断刷新token是否还有效
        refreshTokenValid = True
        try:
            jwt.decode(refreshToken, config.settings.SECRET_KEY)
        except:
            refreshTokenValid = False

        if (refreshTokenValid and refreshToken == user.refreshToken):
            token = jwt.encode(
                {
                    'user_id':
                    user.id,
                    'exp':
                    datetime.datetime.utcnow() +
                    datetime.timedelta(minutes=300)
                }, flask_app.config['SECRET_KEY'])
            refreshToken = jwt.encode(
                {
                    'user_id':
                    user.id,
                    'type':
                    'refresh',
                    'exp':
                    datetime.datetime.utcnow() +
                    datetime.timedelta(minutes=14400)
                }, flask_app.config['SECRET_KEY'])
            UserService.save_token(user.id, token, refreshToken)
            db.session.commit()

            trackingoutput = "刷新token成功"
            TrackingService.tracking(trackinginput, trackingoutput, user.id)

            thunderservice_name = thunder_service_name[str(
                user.thunderservice_id)]
            thunderservice_nameEN = thunder_service_nameEN[str(
                user.thunderservice_id)]

            user_info = {
                "user_id":
                user.id,
                "name":
                user.email,
                "period":
                time.strftime("%Y-%m-%d",
                              time.localtime(user.thunderservice_endtime)),
                "invitationcode":
                user.individual_coupon,
                "client_group_id":
                user.thunderservice_id,
                "vip":
                thunderservice_name,
                "vip_en":
                thunderservice_nameEN,
                "vip_level":
                user.usergroup_id,
                "validtime":
                2
            }

            resp = {
                "code": 200,
                "message": "refresh token success",
                "results": {
                    "user_info": user_info,
                    "credential": {
                        "token": token.decode('UTF-8'),
                        "refreshToken": refreshToken.decode('UTF-8')
                    }
                }
            }

            logging.info(f"AppRefreshTokenView success, result:{resp}")
            return resp

        logging.info(f"ERROR: AppRefreshTokenView fail,result:4005")
        return {
            "code": 4005,
            "message": returncode['4005'],
        }, 200
Пример #8
0
    def process(self):
        trackinginput = self.parameters.get('body')
        user_body = self.parameters.get('body')
        user = UserService.get_user_by_email(user_body['email'])

        logging.info("UserLoginView,email:{}".format(user_body['email']))
        if not user:
            return {
                "code": 4001,
                "message": returncode['4001'],
            }, 401

        if (user_body['password'] == user.password):
            # if user.check_password(user_body['password']):
            token = jwt.encode(
                {
                    'user_id':
                    user.id,
                    'exp':
                    datetime.datetime.utcnow() +
                    datetime.timedelta(minutes=300)
                }, flask_app.config['SECRET_KEY'])
            refreshToken = jwt.encode(
                {
                    'user_id':
                    user.id,
                    'type':
                    'refresh',
                    'exp':
                    datetime.datetime.utcnow() +
                    datetime.timedelta(minutes=14400)
                }, flask_app.config['SECRET_KEY'])
            UserService.save_token(user.id, token, refreshToken)
            db.session.commit()

            pwresource = UserService.get_user_service_password(user.id)
            if pwresource:
                thunderservice_password = pwresource.oripassword
            else:
                thunderservice_password = '******'  # 万一没有,就拿这个顶
                logging.info(
                    "UserLoginView. This user :{} do not have thunderservice password, use reserved insteed"
                    .format(user_body['email']))

            routes = RouteService.get_routes_by_group_ID(user.usergroup_id)

            routes_info = list()
            for route in routes:
                routes_info.append({
                    'id': route.id,
                    # 'usergroup_id': route.usergroup_id,
                    'sequence': route.sequence,
                    # 'online': route.online,
                    'domain': route.domain,
                    'port': route.port,
                    # 'ipaddress': route.ipaddress,
                    'servernameEN': route.servernameEN,
                    'servernameCN': route.servernameCN,
                    # 'routeStarttime': route.routeStarttime,
                    # 'trafficLimit': route.trafficLimit,
                    # 'trafficUsed': route.trafficUsed,
                    # 'trafficResetDay': route.trafficResetDay,
                    'password': thunderservice_password
                })
            trackingoutput = "成功"
            TrackingService.tracking(trackinginput, trackingoutput, user.id)

            device = user_body.get('device') if user_body.get(
                'device') else 'Unknown'
            thunderservice = user.thunderservice_id
            # if thunderservice in (thunder_service_ID['LOW_SPEED'] or thunder_service_ID['TRIAL']):
            KService_action = '102'
            # thunderservice exits and is a VIP
            if thunderservice and str(
                    thunderservice) in thunder_service_ID['FUFEI']:
                KService_action = '103'
            KService.add_record(action=KService_action,
                                parameter1=user.id,
                                parameter2=device,
                                timestamp=int(time.time()))

            thunderservice_name = thunder_service_name[str(thunderservice)]

            return {
                "code": 200,
                "message": "login success",
                "results": {
                    "user_info": {
                        "user_id": user.id,
                        "thunderservice_id": user.thunderservice_id,
                        "thunderservice_name": thunderservice_name,
                        "thunderservice_endtime": user.thunderservice_endtime,
                        "usergroup_id": user.usergroup_id
                    },
                    "routes": routes_info,
                    "credential": {
                        "token": token.decode('UTF-8'),
                        "refreshToken": refreshToken.decode('UTF-8')
                    }
                }
            }

        return {
            "code": 4002,
            "message": returncode['4002'],
        }, 401