def test_validate_invalid_password(self, user): """Invalid password.""" user.set_password("example") user.save() form = LoginForm(username=user.username, password="******") assert form.validate() is False assert "Invalid password" in form.password.errors
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 test_validate_success(self, user): """Login successful.""" user.set_password("example") user.save() form = LoginForm(username=user.username, password="******") assert form.validate() is True assert form.user == user
def test_validate_inactive_user(self, user): """Inactive user.""" user.active = False user.set_password("example") user.save() # Correct username and password, but user is not activated form = LoginForm(username=user.username, password="******") assert form.validate() is False assert "User not activated or not admin" in form.username.errors
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 sdk_config(): """About page.""" form = LoginForm(request.form) crypto_type = ['ECDSA', 'GM'] return render_template( "public/sdk_config.html", form=form, crypto_type=crypto_type, )
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, )
def about(): """About page.""" form = LoginForm(request.form) return render_template("public/about.html", form=form)
def test_validate_unknown_username(self, db): """Unknown username.""" form = LoginForm(username="******", password="******") assert form.validate() is False assert "Unknown username" in form.username.errors assert form.user is None