def login(): """Does the login via OpenID. Has to call into `oid.try_login` to start the OpenID machinery. """ # if we are already logged in, go back to were we came from if logged_in_user() is not None: return redirect(oid.get_next_url()) if request.method == 'POST': openid = request.form.get('openid') if not re.findall('^https*://', openid): openid = 'http://' + openid if openid: pape_req = pape.Request([]) x = oid.try_login(openid, ask_for=['email', 'nickname'], ask_for_optional=['fullname'], extensions=[pape_req]) return x form = LoginForm() if form.validate_on_submit(): return redirect(oid.get_next_uril()) msg = oid.fetch_error() if msg: flash(msg) elif fns_util.pu_time(): flash('Please enter an openid') return render_template('login.html', next=oid.get_next_url(), error=oid.fetch_error(), form=form, version=version.__version__)
def login_view(): form = LoginForm(request.form) if request.method == 'POST' and form.validate(): user = form.get_user() login.login_user(user) return redirect(url_for('auteur')) return render_template('authors/login_form.html', form=form)
def signin(): form = LoginForm() # flash("Hello") if form.validate_on_submit(): message = f"Login required for {form.username.data}. " +\ f"Remember me {form.remember_me.data}" flash(message) return redirect(url_for("home")) return render_template("signin.html", form=form)
def login(): form = LoginForm(request.form) if form.validate(): if form.email.data == form.email.data: return redirect(url_for('viewentries')) else: flash_errors(form) print("If you have no account, sign up") return render_template('login.html', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('índex')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() if user is None or not user.check_password(form.password.data): flash('Invalid username or password') return redirect(url_for('login')) login_user(user, remember=form.remember_me.data) return redirect(url_for('index')) return render_template('login.html', title='Sign In', form=form)
def login(): languagess = Languages.query.all() if current_user.is_authenticated: return redirect(url_for('adm')) form = LoginForm() if form.validate_on_submit(): user = Users.query.filter_by(username=form.username.data).first() if user and user.password == form.password.data: login_user(user) return redirect(url_for("adm")) else: flash("login invalido") return render_template('login.html', form=form, languagess=languagess)
def login(): logout_user() form = LoginForm() if request.method == 'POST': if form.validate_on_submit(): username = request.form['username'] password = request.form['password'] user = tblUser.query.filter_by(username=username).first() while user is not None: isMatch = bcrypt.check_password_hash(user.password, password) if isMatch is True: login_user(user) return redirect('/') return 'Password is incorrect' return 'Username does not exist' return render_template('views/login.html', form=form)
def login(): '''Authenticate if the user info is correct and then log the user in or redirect or redirect them to the sign up pagedown ''' error = None form = LoginForm(request.form) if form.validate(): user = session.query(User).filter_by(email=form.email.data).first() global current_user_id current_user_id = user.id if form.email.data == form.email.data: return redirect(url_for('viewentries')) else: flash_errors(form) print("If you have no account, sign up") return render_template('login.html', form=form)
def login(): """ This route contains the login page and the login form. When submitted, we verify if the user exists in the database and his credentials are correct. :return: """ form = LoginForm() if request.method == 'POST' and form.validate_on_submit(): user = user_model.get_user_by_username(form.username.data) if user is not None and user.verify_password(form.password.data): login_user(user, form.remember_me.data) # If the user wanted to access from a different page instead of the home page, we can keep track of # of this url so as to redirect the user back next_url = request.args.get('next') if next_url is None or not next_url.startswith('/'): # check that the next_url is a relative URL next_url = url_for('index') return redirect(next_url) flash("Invalid username or password", "error") return render_template('login.html', form=form)
def test_login(self): email = "*****@*****.**" password = "******" with app.app_context(): form = LoginForm() form.email.data = email form.password.data = password with app.test_client() as client: resp = client.post(f"/login", data=form.data, follow_redirects=True) html = resp.get_data(as_text=True) self.assertEqual(resp.status_code, 200) self.assertIn("Johnny Doe", html)
def test_invalid_email_invalidates_form(): form = LoginForm(email='not an email', password='******') assert not form.validate()
def test_validate_success_login_form(): form = LoginForm(email=tconst.ADMIN_EMAIL, password=tconst.ADMIN_PASSWORD) assert form.validate()