def process(self): user_body = self.parameters.get('body') if self.check_registed_user_by_email(user_body.get('email')): return { "code": 4010, "message": returncode['4010'], }, 400 logging.info("AddUserView. {}".format(user_body)) UserService.add_user(user_body.get('name'), user_body.get('email'), user_body.get('password'), user_body.get('source'), user_body.get('email_verified'), time.time() * 1000) db.session.commit() if not user_body['email_verified']: logging.error("email_verified false, So we need send an verify email to {}".format(user_body['email'])) # get user service info again, active it. user = UserService.get_user_by_email(user_body.get('email')) UserService.active_thunderservice(user.id, user.thunderservice_id, user.thunderservice_starttime, user.thunderservice_endtime) db.session.commit() return { "code": 200, "message": "add user success", }
def process(self): email = request.args.get('email') user = UserService.get_user_by_email(email) if user: #TODO Check if user_id is currently logged in reset_token = jwt.encode( { 'user_id': user.id, 'action': 'resetpassword', 'exp': datetime.datetime.utcnow() + datetime.timedelta(minutes=10) }, flask_app.config['SECRET_KEY']) reset_token = reset_token.decode("utf-8") print(reset_token) # send email to customer # if (send_simple_message(email,"重置密码",reset_token))==200: # return {"code":200,"message":"Send email success"} # else: # return{"code":4025,"message":returncode['4025']},401 else: return { "code": 4001, "message": returncode['4001'], }, 401
def process(self): user_body = self.parameters.get('body') if self.check_registed_user_by_email(user_body.get('email')): return { "code": 4010, "message": returncode['4010'], }, 400 logging.info("AddUserView. {}".format(user_body)) UserService.add_user(user_body.get('name'), user_body.get('email'), user_body.get('password'), user_body.get('appkey'), user_body.get('email_verified'), int(time.time())) db.session.commit() if not user_body.get('email_verified'): logging.error( "email_verified false, So we need send an verify email to {}". format(user_body['email'])) # get user service info again, active it. user = UserService.get_user_by_email(user_body.get('email')) UserService.active_thunderservice(user.id, user.thunderservice_id, user.thunderservice_starttime, user.thunderservice_endtime) db.session.commit() source = user_body.get('appkey') if user_body.get( 'appkey') else 'Unknown' KService_action = '101' KService.add_record(action=KService_action, parameter1=user.id, parameter2=source, timestamp=int(time.time())) return { "code": 200, "message": "add user success", }
def check_registed_user_by_email(self, user_email): if UserService.get_user_by_email(user_email): return True
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): 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
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