def login(): # login in func if current_user.is_authenticated: return redirect(url_for('public.home')) form = LoginForm() if form.validate_on_submit(): username_or_email = form.username.data password = form.password.data # remember = form.remember.data user = [ User.query.filter(User.username == username_or_email).first(), User.query.filter(User.email == username_or_email).first() ] if user[0]: if user[0].check_password(password): # login_user(user[0], remember) login_user(user[0]) flash('Welcome back.', 'info') return redirect_back() else: flash('账号或者密码错误,请重新输入!', 'warning') elif user[1]: if user[1].check_password(password): login_user(user[1]) flash('Welcome back.', 'info') return redirect_back() else: flash('账号或者密码错误,请重新输入!', 'warning') else: flash('No account.', 'warning') return render_template('public/login.html', form=form)
def home(): """Home page.""" form = LoginForm(request.form) current_app.logger.info("Hello from the home page!") # Handle logging in if request.method == "POST": if form.validate_on_submit(): login_user(form.user) flash("You are logged in.", "success") redirect_url = request.args.get("next") or url_for("user.members") return redirect(redirect_url) else: flash_errors(form) # TODO mock_data = ["byte32", "int", "bytes"] return render_template("public/home.html", form=form, mock_data=mock_data)
def home(): """Home page.""" form = LoginForm(request.form) current_app.logger.info("Hello from the home page!") # Handle logging in if request.method == "POST": if form.validate_on_submit(): login_user(form.user) flash("You are logged in.", "success") redirect_url = request.args.get("next") or url_for("user.members") return redirect(redirect_url) else: flash_errors(form) # TODO mock_data_type = ["byte32", "int", "bytes"] key_type = ["bitcoin", "ethereum"] trans_type = ["signature"] contracts = Contract.query.all() for contract in contracts: # load contract by path files = os.listdir(contract.path) payload = {} for file in files: f = open(contract.path + "/" + file).read() payload[file] = f contract.payload = payload return render_template( "public/home.html", form=form, mock_data_type=mock_data_type, trans_type=trans_type, key_type=key_type, contracts=contracts, )