def process(self): self.other_function() user_id = self.parameters.get('user_id') user_info = UserService.get_user(user_id) thunderservice_password = UserService.get_user_service_password( user_id) route_info = RouteService.get_routes_by_group_ID( user_info.usergroup_id) logging.info("route_info:{}".format(route_info)) if (user_info): routes = list() for route in route_info: routes.append({ "id": route.id, "usergroup_id": route.usergroup_id, "sequence": route.sequence, "online": route.online, "domain": route.domain, "port": route.port, "servernameEN": route.servernameEN, "servernameCN": route.servernameCN, "password": thunderservice_password.oripassword }) user_service_info = { 'user_id': user_info.id, 'thunderservice_id': user_info.thunderservice_id, 'thunderservice_name': thunder_service_name[str(user_info.thunderservice_id)], 'thunderservice_starttime': user_info.thunderservice_starttime, 'thunderservice_endtime': user_info.thunderservice_endtime, 'usergroup_id': user_info.usergroup_id, 'thunderservice_oripassword': thunderservice_password.oripassword, 'thunderservice_client_amount': user_info.thunderservice_client_amount, 'thunderservice_traffic_amount': user_info.thunderservice_traffic_amount, 'thunderservice_up_traffic_used': user_info.thunderservice_up_traffic_used, 'thunderservice_down_traffic_used': user_info.thunderservice_down_traffic_used, "routes": routes } return { "code": 200, "message": "get user service success", "userServiceInfo": user_service_info } return 'None', 400
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
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
def process(self): # user_body = self.parameters.get('body') user_id = request.args.get('user_id') user = UserService.get_user(user_id) logging.info( f"AppGetUserView,(baseURL/app/getUserInfo?user_id=userid),user_id:{user_id}" ) if not user: return { "code": 4001, "message": returncode['4001'], }, 200 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_id)) 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 }) 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": "get user info success", "results": { "user_info": user_info, "ips": routes_info } } logging.info(f"AppGetUserView success,response:{resp}") return resp
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