def forget_pwd(): forget_pwd_form = ForgetPwdForm() if forget_pwd_form.validate_on_submit(): user = User.query.filter_by(email=forget_pwd_form.email.data).first() token = user.generate_confirmation_token() send_email(user.email, u'重设密码', 'auth/email/forgetpwd', user=user, token=token) flash(u'一封邮件已经发到您邮箱,请前往邮箱修改密码') return redirect(url_for('main.index')) return render_template('auth/forgetpwd.html', form=forget_pwd_form)
def resend_confirmation(): if not current_user.confirmed: token = current_user.generate_confirmation_token() send_email(current_user.email, u'激活账号', 'auth/email/confirm', user=current_user, token=token) flash(u'注册成功,一封邮件已经发到您邮箱,请前往邮箱激活')
def get(self): self.parser.add_argument( "email", type=inputs.regex( r'(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)'), required=True, location="json", help='email format is incorrect') args = self.parser.parse_args() token = generate_confirmation_token(args.email) confirm_url = config.domain + "/api/v1/mall/confirm?token=" + token html = ''' <p>Welcome! Thanks for signing up. Please follow this link to activate your account:</p> <p><a href=''' + confirm_url + '''>''' + confirm_url + '''</a></p> <br> <p>Cheers!</p>''' subject = "Please confirm your email" send_email(args.email, subject, html) return pretty_result(code.OK, msg='Account already confirmed. Please login.')
def post(self): self.parser.add_argument( "email", type=inputs.regex( r'(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)'), required=True, location="json", help='email format is incorrect') args = self.parser.parse_args() password = uuid.uuid4().hex[:8] mallUserInfo = MallUsersModel.query.filter_by(email=args.email).first() mallUserInfo.password = MallUsersModel.set_password( MallUsersModel, password) MallUsersModel.update(mallUserInfo) html = ''' <p>Welcome! Please keep your password:</p> <p>''' + password + '''</p> <br> <p>Cheers!</p>''' subject = "Your Password" send_email(args.email, subject, html) return pretty_result(code.OK, msg='Please login again.')
height) m_sponsor = set() for i in range(len(onduty)): sponsor = onduty[i].get('_id') m_sponsor.add(sponsor) print('m_sponsor_1 : ', m_sponsor) if node_public_key in m_sponsor: assert False, '[normal] First round send the proposal, close the process' print('block height :{},{}'.format(gte_height_2, gte_height_1 - 1)) onduty = obj.condition_find_onduty_sponsor(gte_height_2, height - arbiter_num) m_sponsor = set() for i in range(len(onduty)): sponsor = onduty[i].get('_id') m_sponsor.add(sponsor) print('m_sponsor_2 : ', m_sponsor) if node_public_key in m_sponsor: assert False, '[normal] Second round send the proposal, close the process' ''' 最后的两个集合的sponsor一致,发送邮件 ''' mail = _onduty_mail(node_public_key, gte_height_2, height) mail_vote = _get_vote(obj, node_public_key, gte_height_2, height) email.send_email(n.name + '连续不发送提案预警', email.html_table(mail) + email.html_table(mail_vote)) print('========== Test Finish ==========')
def post(self): """ 用户注册 :return: json """ self.parser.add_argument( "email", type=inputs.regex( r'(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)'), required=True, location="json", help='email format is incorrect') self.parser.add_argument( "username", type=str, required=True, location="json", help='username is required or format is incorrect') self.parser.add_argument( "inviterId", type=str, location="json", help='inviterId is required or format is incorrect') # self.parser.add_argument("phone", type=inputs.regex(r'((\+66|0)(\d{1,2}\-?\d{3}\-?\d{3,4}))|((\+๖๖|๐)([๐-๙]{1,2}\-?[๐-๙]{3}\-?[๐-๙]{3,4}))'), required=True, location="json", # help='phone is required or format is incorrect') # self.parser.add_argument("gender", type=str, required=True, location="json", # help='gender is required or format is incorrect') # self.parser.add_argument("birth", type=str, required=True, location="json", # help='birth is required or format is incorrect') self.parser.add_argument( "password", type=password_len, required=True, location="json", trim=True, help='password is required or format is incorrect') args = self.parser.parse_args() MallUserEmailInfo = MallUsersModel.query.filter_by( email=args.email).all() for item in MallUserEmailInfo: if item.id != args.id: return pretty_result(code.ERROR, msg='The email is exit!') # mallUser = MallUsersModel(email=args.email, username=args.username, password=MallUsersModel.set_password(MallUsersModel, getRSAtext(args.password)), # registered_on=int(time.time()),phone=args.phone.replace('-', ''), gender=args.gender,birthday=args.birth) mallUser = MallUsersModel(email=args.email, username=args.username, password=MallUsersModel.set_password( MallUsersModel, getRSAtext(args.password)), registered_on=int(time.time())) MallUsersModel.add(MallUsersModel, mallUser) token = generate_confirmation_token(args.email) confirm_url = config.domain + "/api/v1/mall/confirm?token=" + token html = ''' <p>Welcome! Thanks for signing up. Please follow this link to activate your account:</p> <p><a href=''' + confirm_url + '''>''' + confirm_url + '''</a></p> <br> <p>Cheers!</p>''' subject = "Please confirm your email" send_email(args.email, subject, html) if args.inviterId != 'undefined': try: inviteEmail = base64.b64decode(args.inviterId) inviter = InvitersModel(invite=inviteEmail, invited=args.email) InvitersModel.add(InvitersModel, inviter) userInfo = InvitersModel.query.filter_by( email=inviteEmail).first() userInfo.point = config.Inviter_Point InvitersModel.update(userInfo) except Exception as e: return pretty_result(code.OK, msg='inviterId is not correct') if mallUser.id: returnUser = { 'id': mallUser.id, 'username': mallUser.username, 'email': mallUser.email, 'phone': mallUser.phone, 'gender': mallUser.gender, 'birth': mallUser.birthday, 'confirmed': mallUser.confirmed, 'login_time': mallUser.login_time } return pretty_result(code.OK, data=returnUser, msg='User register successful') else: return pretty_result(code.ERROR, msg='User register failed')
db_tx = obj.findOne_tx_pool() # db count > 3 if len(db_txs) > 2 and db_tx[interface.height] > height - 1: tx_pool = db_txs[0] tx_pool_1 = db_txs[1] tx_pool_2 = db_txs[2] tx_1 = tx_pool.intersection(tx_pool_1) tx_2 = tx_1.intersection(tx_pool_2) if len(tx_2) == 0: obj.drop_tx_pool() else: obj.drop_tx_pool() mail_text = "<tr><td width=" + str( 100) + ">区块高度</td><td width=" + str( 100) + ">遗留交易数</td></tr>" mail_text = mail_text + "<tr><td>" + str( height - 1) + "</td><td>" + str( len(tx_2)) + "</td></tr>" email.send_email(n.name + '交易池遗留交易预警', email.html_table(mail_text)) else: obj.add_tx_pool(height - 1, txids) else: obj.add_tx_pool(height - 1, txids) else: obj.drop_tx_pool() print('========== Test Finish ==========')
from common import node, rpc, email from mongo import db_height_discrete if __name__ == '__main__': _time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time() + 28800)) n = node.Node() b, height = rpc.getblockcount(n.url) if b is False: email.send_email( n.name + '异常报告', email.html_table("<tr><td width=" + str(20) + ">时间</td><td width=" + str(200) + ">异常信息</td></tr><tr><td>" + str(_time) + "</td><td>" + str(height) + "</td></tr>")) assert b, '[warn_node_height.py] getblockcount error:{}'.format(height) obj = db_height_discrete.DetectorMongoDBCont(n.mongo_host, n.mongo_port, n.mongo_db) ''' detection of block height growth ''' print('======= detection of block height growth ========') discreteHeight = obj.findOne_discreteHeight() print('discreteHeight:{},basicHeight:{}'.format(discreteHeight, height)) if discreteHeight is None: obj.add_discrete_height(height) elif discreteHeight['height'] == height:
def run_case(): global email_on_off global error_count logger.debug("") logger.debug("") logger.debug( "----------------------------------------------------------------------------------------------" ) try: today = time.strftime("%Y_%m_%d-%H:%M:%S").split('-', 1)[0] if os.path.exists("../reports/%s" % today): logger.debug("已经有reportdate文件夹:%s" % today) else: os.mkdir(report_path) logger.debug("新建了reportdate文件夹:%s" % today) except: logger.debug("当天reportdate文件夹目录失败") try: ''' 不使用全局执行所有case # 使用os.path.join拼接地址 case_path = os.path.join(cur_path, "../case") # 获取当前目录下所有的文件名 lst = os.listdir(case_path) for c in lst: # 判断文件名是以.py结尾的;添加and c.find("DemoGet") == -1就是去掉DemoGet.py文件 if os.path.splitext(c)[1] == '.py' and c.find("__init__") == -1 and c.find("demo_project") == -1 : try: # 查看文件名 logger.debug(c) # 相当于在终端执行文件 python main.py os.system('python3 {}'.format(os.path.join(case_path, c))) except Exception as e: logger.debug("用例执行失败") logger.debug(e) ''' for i in range(len(actuator)): os.system('python3 {}'.format( os.path.join("../actuator", actuator[i]))) '''注意区分执行命令配置''' # os.system('python {}'.format(os.path.join("../actuator", actuator[i]))) try: opt = webdriver.ChromeOptions() # 把chrome设置成无界面模式,不论windows还是linux都可以,自动适配对应参数 opt.set_headless(True) # 创建chrome无界面对象 checkresult = webdriver.Chrome(options=opt) for i in range(len(os.listdir(report_path))): check_report_path = 'file://' + cur_path.replace( "execute", "reports/") + rpt_date_path + '/' + os.listdir( report_path)[i] print(check_report_path) checkresult.get(check_report_path) string1 = checkresult.find_element_by_xpath( "//*[@id='result_table']/tbody/tr[2]/td[4]").text string2 = checkresult.find_element_by_xpath( "//*[@id='result_table']/tbody/tr[2]/td[5]").text Fcount = int(string1) Ecount = int(string2) print("Fcount:" + string1 + " " + "Ecount:" + string2) all_Error_count = Fcount + Ecount error_count = error_count + all_Error_count print("error_count:%d" % error_count) except Exception as ex: logger.debug("检查错误识别失败") logger.error(ex) print(ex) except Exception as exx: logger.debug("运行出问题了") logger.error(str(exx)) email_on_off = 0 finally: logger.info("*********TEST END*********") # send test report by email if email_on_off == 1 and error_count != 0: email.send_email() logger.info( "email on and has error ,Doesn't send report email to developer." ) elif email_on_off == 1 and error_count == 0: logger.info( "email on but no error ,Doesn't send report email to developer." ) elif email_on_off == 0 and error_count != 0: logger.info( "has error but email off ,Doesn't send report email to developer." ) elif email_on_off == 0 and error_count == 0: logger.info( "no error and email off ,Doesn't send report email to developer." ) else: logger.info("Unknow state.") logger.debug("") logger.debug("")
# coding-UTF-8 import time from common import node, rpc, email ''' 检测 mainnet 和 did 区块高度报告 ''' if __name__ == '__main__': _time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time() + 28800)) n = node.Node() b, height = rpc.getblockcount(n.url) assert b, 'getblockcount error:{}'.format(height) b, neighbors = rpc.getneighbors(n.url) assert b, 'getneighbors error:{}'.format(neighbors) mailText = "<tr><td width=" + str(80) + ">时间</td><td width=" + str( 80) + ">区块高度</td><td width=" + str(80) + ">相邻节点数</td></tr>" mailText = mailText + "<tr><td>" + _time + "</td><td>" + str( height - 1) + "</td><td>" + str(len(neighbors)) + "</td></tr>" email.send_email(n.name + '报告信息', email.html_table(mailText)) print('========== Test Finish ==========')
v_mail = _viewoffset_mail(view_list) return v_mail if __name__ == '__main__': # 发送大于切换视图指定的数量 number = 2 n = node.Node() obj = db_onduty_info.OndutyMongoDBCont(n.mongo_host, n.mongo_port, n.mongo_db) info = obj.findOne_onduty_info() viewoffset_height = obj.findOne_onduty_viewoffset_height() db_height = '' if info is not None: db_height = info[interface.height] else: assert False, '[warn_onduty_viewoffset.py] mongodb not onduty_info' if viewoffset_height is not None: viewoffset_height = viewoffset_height[interface.height] else: viewoffset_height = n.public_dpos_height # 默认主网H2设置高度 v_mail = onduty_viewoffset(obj, n, viewoffset_height, db_height, number) if v_mail != '': email.send_email(n.name + '仲裁人切换视图预警', email.html_table(v_mail)) obj.add_onduty_viewoffset_height(db_height) print('========== Test Finish ==========')
if __name__ == '__main__': n = node.Node() b, height = rpc.getblockcount(n.url) assert b, 'getblockcount error:{}'.format(height) b, arbiters = rpc.getarbiterpeersinfo(n.url, height - 1) assert b, 'getarbiterpeersinfo error:{}'.format(arbiters) # print('arbiters :', arbiters) mailText = "<tr><td width=" + str(20) + ">序号</td><td width=" + str( 20) + ">区块高度</td><td width=" + str( 200) + ">ownerpublickey</td><td width=" + str( 200) + ">nodepublickey</td><td width=" + str( 20) + ">连接状态</td></tr>" print('arbiterpeersinfo:', arbiters) for i in range(len(arbiters)): arbiter = arbiters[i] owner_public_key = arbiter['ownerpublickey'] node_public_key = arbiter['nodepublickey'] state = arbiter['connstate'] mailText = mailText + "<tr><td>" + str(i + 1) + "</td><td>" + str( height - 1 ) + "</td><td>" + owner_public_key + "</td><td>" + node_public_key + "</td><td>" + state + "</td></tr>" print('teest :', mailText) email.send_email(n.name + '仲裁人直连报告', email.html_table(mailText))
onduty_height = n.public_dpos_height # 默认主网H2设置高度 # 区块范围内发送当值仲裁人的信息 # 当值轮值次数 onduty_count = obj.condition_find_onduty_count(onduty_height, db_height) # 签名次数 signer_count = obj.condition_find_signer_count(onduty_height, db_height) # 切换视图次数 viewoffset_count = obj.condition_find_viewoffset_count( onduty_height, db_height) print('onduty_count : ', onduty_count) print('signer_count : ', signer_count) print('viewoffset_count : ', viewoffset_count) # 发送报告 onduty_map = onduty_report(n, onduty_count, signer_count, viewoffset_count) on_mail = onduty_info_mail(onduty_map, onduty_height, db_height) v_mail = warn_onduty_viewoffset.onduty_viewoffset(obj, n, onduty_height, db_height, number) # print("=======send :", send_email.html_table(on_mail) + send_email.html_table(v_mail)) email.send_email(n.name + '仲裁人报告信息', email.html_table(on_mail) + email.html_table(v_mail)) obj.add_onduty_height(db_height) print('========== Test Finish ==========')