def login(): if request.method == 'GET': return render_template('sign_in.html') else: username = request.form['username'] password = request.form['password'] role = request.form['role'] mysql = Mysql_service() name, real_pass, role, email, address, account, credit = mysql.getUserInfoByUsername( username) if password == real_pass: if role == 'Product': session['username'] = name return render_template('signin_sailer_index.html', username=name, email=email, address=address) if role == 'Transport': session['username'] = name return render_template('signin_trans_index.html', username=name, email=email, address=address) if role == 'Sale': session['username'] = name return render_template('signin_custs_index.html', username=name, email=email, address=address) else: print("======登录失败======") # 这里还没有考虑怎么样的返回界面 return render_template('sign_in.html', res="fail")
def signin_sailer_system(): username = session['username'] mysql = Mysql_service() [name, password, role, email, address, account, credit] = mysql.getUserInfoByUsername(username) return render_template('signin_sailer_system.html', username=username, credit=credit)
def register(): if request.method == 'GET': return render_template('register.html') else: username = request.form['name'] email = request.form['email'] password = request.form['password'] role = request.form['role'] # add into the mysql mysql = Mysql_service() mysql.register(username, password, email, role) return redirect(url_for('login'))
def change_2(): if request.method == 'GET': return render_template('signin_trans_index.html') else: username = request.form['username'] email = request.form['email'] address = request.form['address'] # 不同的身份返回不同的界面所以要进行判断 role = request.form['role'] # 修改个人信息,这个界面只有在刚刚登陆成功之后才能成功运行,没有留有借口进行返回 mysql = Mysql_service() mysql.modify_user_info(username=username, email=email, address=address) print("======成功修改======") if role == 'Transport': return render_template('signin_trans_index.html', username=username, email=email, address=address)
hash(block):计算给定的block的哈希值 返回:十六进制的字符串 proof_of_work(self, hash:str):挖矿 返回:nonce new_node(self, address):新建用户节点 valid_chain(self, chain):判断chain是否合法 返回:合法True否则False valid_chains(self):获取整个网络节点的合法链 返回:有替换返回True反之False """ mysql=Mysql_service() class Blockchain(object): def __init__(self): # 当前交易总数 self.num = 0 self.chain = [] # self.Blockchain.getchain() self.getchain() self.nodes = set() self.get_all_host() self.cur_transactions = [] self.get_cur_tran() # 创建创世区块 self.new_block(nonce=self.proof_of_work('1'), previous_hash='1')