def process(self): user_body = self.parameters.get('body') user_id = self.parameters.get('user_id') current_userdata = UserService.get_user(user_id) if current_userdata: if user_body.get('id'): return { "code": 4012, "message": returncode['4012'] }, 400 logging.info("ModifyUserViewByID. UserService.modify_user_by_id:{}{}".format(user_id, user_body)) if user_body.get('usergroup_id'): if current_userdata.usergroup_id != user_body.get('usergroup_id'): old_usergroup_id = current_userdata.usergroup_id new_usergroup_id = user_body.get('usergroup_id') logging.info("UserID:{},need change usergroup_id from {} to {}".format(user_id, old_usergroup_id, new_usergroup_id)) UserService.delete_assigned_pwd(user_id) UserGroupService.decrease(old_usergroup_id) UserService.assign_new_pwd(user_id, new_usergroup_id) UserGroupService.increase(new_usergroup_id) UserService.modify_user_by_id(user_id, user_body) db.session.commit() return { "code": 200, "message": "modify user success" } else: return { "code": 4011, "message": returncode['4011'] }, 400
def process(self): newpassword = request.form['newpassword'] password_reset = request.referrer.split('?key=')[1] logging.info( f"用户要把密码更新为{len(newpassword)}长度的一个新密码,reset_key是{password_reset}") # 判断newpassword是否为空或者小于3字节 if len(str(newpassword)) < 3: logging.warning(f"用户更新密码失败,密码太短") return make_response( render_template('error.html', flag="too_short"), 200) # #判断password_reset是否还有效,如有效则取出来user_id user = UserService.get_user_by_pwreset(password_reset) if not user or (int(time.time()) - user.password_reset_timestamp > 24 * 3600): #密码重置链接已经超过24小时 logging.warning(f"用户更新密码失败,找不到用户,或者密码重置链接已经超过24小时") return make_response(render_template('error.html', flag="invalid"), 200) update_data = {"password_reset": '', "password_reset_timestamp": 0} UserService.modify_user_by_id(user.id, update_data) UserService.user_pwdreset_submit(user_id=user.id, newpassword=newpassword) db.session.commit() logging.info(f"{user.id}用户更新密码成功") return make_response( render_template('resetpassword.html', flag="success"), 200)
def process(self): user_body = self.parameters.get('body') user_id = user_body.get('user_id') thunderservice_id = user_body.get('thunderservice_id') service_start_date = user_body.get('service_start_date') service_end_date = user_body.get('service_end_date') update_data = { "membership": thunderservice_id, "membership_starttime": service_start_date, "membership_endtime": service_end_date } user_data = UserService.get_user(user_id) # same membership level, update period only if user_data.get('membership') == thunderservice_id: UserService.modify_user_by_id(user_id, update_data) db.session.commit() return { 'result': "User already have same service, modify date only. success" } # change membership level, delete old pwd and assign a new one new_usergroup_id = self.choose_best_usergroup(thunderservice_id) print("new_usergroup_id:", new_usergroup_id) UserService.delete_assigned_pwd(user_id) UserGroupService.decrease(user_data.get('usergroup')) update_data = { "usergroup": new_usergroup_id, "membership": thunderservice_id, "membership_starttime": service_start_date, "membership_endtime": service_end_date } UserService.modify_user_by_id(user_id, update_data) UserService.assign_new_pwd(user_id, new_usergroup_id) UserGroupService.increase(new_usergroup_id) db.session.commit() return {'result': "Active thunderservice success"}
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 make_fulfill(order_id): from application.services.user_service import UserService order = OrderModel.query.filter(OrderModel.id == order_id).first() user = UserService.get_user(order.user_id) if user: from application.models.thunderservice_model import ThunderserviceModel if user.thunderservice_id == order.thunderservice_id: # 相同的thunderservice,只修改到期时间 thunderservice = ThunderserviceModel.query.filter( ThunderserviceModel.id == order.thunderservice_id).first() duration = thunderservice.duration * 86400 user.thunderservice_endtime = user.thunderservice_endtime + duration # 标记本order已经完成了 order.thunderserviceStatus = '1' db.session.commit() # 增加记录到K线图 KService_action = '201' KService.add_record(action=KService_action, parameter1=order.amount, parameter2='Paid', timestamp=int(time.time())) return True else: #取user当前的thunderservice是否是付费service,如果是,记录还剩多少时间。 timeLeft = 0 if str(user.thunderservice_id) in thunder_service_ID['FUFEI']: timeLeft = user.thunderservice_endtime - int(time.time()) if timeLeft < 0: timeLeft = 0 thunderservice = ThunderserviceModel.query.filter( ThunderserviceModel.id == order.thunderservice_id).first() user_updatedata = { "thunderservice_id": order.thunderservice_id, "thunderservice_client_amount": thunderservice.defaultClientAmount, "thunderservice_traffic_amount": thunderservice.defaultTrafficAmount, } thunderservice_starttime = time.time() thunderservice_endtime = time.time() if thunderservice.id != 1: thunderservice_endtime = thunderservice_endtime + thunderservice.duration * 86400 + timeLeft UserService.modify_user_by_id(order.user_id, update_data=user_updatedata) db.session.commit() UserService.active_thunderservice(order.user_id, order.thunderservice_id, thunderservice_starttime, thunderservice_endtime) db.session.commit() order.thunderserviceStatus = '1' db.session.commit() # 增加记录到K线图 KService_action = '201' KService.add_record(action=KService_action, parameter1=order.amount, parameter2='Paid', timestamp=int(time.time())) return True else: return False