From imonikemohammed at gmail.com Mon Jul 1 11:14:33 2019 From: imonikemohammed at gmail.com (Abdul Mohammed) Date: Mon, 1 Jul 2019 16:14:33 +0100 Subject: [Flask] Unable to set current_user.authenticated to True Message-ID: Hello everyone, I am trying to toggle between "Sign in" and "Sign out" links using the current_user.is_authenticated variable such that when it returns False, the "Sign in" is displayed and when True the "Sign out" link is displayed. At some point in the login code I set current_user.authenticated = True. The thing is that by the I am successfully logged in and presented with the next view, it is the "Sign in" link that is still displayed. When I check current_user.is_authenticated, it returns False, even though I had explicitly set it to True. Please can anyone point out what I am might be doing wrong? Here is my code: I have a base.html file that contains the "Sign in" and "Sign out" links that is extended by the other templates: {% block page_content %}{% endblock %} When the app first loads in the browser it displays a login form, login.html: {% extends "base.html" %} {% block content %} {% import "bootstrap/wtf.html" as wtf %} {% block title %}Flasky - Login{% endblock %} {% block page_content %}
{{ wtf.quick_form(form) }}
{% endblock %} {% endblock %} When a user logs in, it loads a template dashboard.html that displays a map. The top part looks like this: {% extends "base.html" %} {% block page_content %} Lagos Map ... ... And these are the relevant routes: @app.route('/',methods=['GET','POST']) def index(): form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user is not None and user.check_password(form.password.data): user.authenticated = True current_user = user db.session.add(current_user) db.session.commit() login_user(current_user, form.remember_me.data) return redirect(request.args.get('next') or url_for('dashboard')) flash('Invalid username or password.') return render_template('auth/login.html', form=form) @app.route('/dashboard') def dashboard(): return render_template("dashboard.html") Thank you for your time. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lenikmutungi at gmail.com Mon Jul 1 13:03:04 2019 From: lenikmutungi at gmail.com (Leni Kadali Mutungi) Date: Mon, 1 Jul 2019 20:03:04 +0300 Subject: [Flask] Unable to set current_user.authenticated to True In-Reply-To: References: Message-ID: <177572e2-a71d-a250-e6ec-defcce5b5161@gmail.com> I think you mean to set it as `current_user.is_authenticated = True`. On 7/1/19 6:14 PM, Abdul Mohammed wrote: > Hello everyone, > ????????????????? I am trying to toggle between "Sign in" and "Sign > out" links using the current_user.is_authenticated variable such that > when it returns False, the "Sign in" is displayed and when True the > "Sign out" link is displayed. At some point in the login code I set > current_user.authenticated = True. The thing is that by the I am > successfully logged?in and presented with the next view, it is the > "Sign in" link that is still displayed. When I check > current_user.is_authenticated, it returns False, even though I had > explicitly set it to True. Please can anyone point out what I am might > be doing?wrong? Here is my code: > > I have a base.html file that contains the "Sign in" and "Sign out" > links that is extended by the other templates: > > > > > {% block page_content %}{% endblock %} > > > > ?When the app first loads in the browser it displays a login form, > login.html: > > ?{% extends "base.html" %} > > {% block content %} > ??? {% import "bootstrap/wtf.html" as wtf %} > ??? {% block title %}Flasky - Login{% endblock %} > ??? {% block page_content %} > ??? > ???
> ??? ??? {{ wtf.quick_form(form) }} > ???
> ??? {% endblock %} > {% endblock %} > > When a user logs in, it loads a template dashboard.html that displays > a map. The top part looks like this: > > {% extends "base.html" %} > > {% block page_content %} > > ? > ?? Lagos Map > ?? href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > ?? crossorigin=""/> > ?? > ?? > ?? href="https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css" > /> > ?? href="https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css" > /> > ?? > ?? > ? ... > ? ... > > And these are the relevant routes: > > @app.route('/',methods=['GET','POST']) > def index(): > ?? ?? form = LoginForm() > ????? if form.validate_on_submit(): > ??? ????? user = User.query.filter_by(email=form.email.data).first() > ??? ????? if user is not None and user.check_password(form.password.data): > ??? ??? ????? user.authenticated = True > ??? ??? ????? current_user = user > ??? ??? ????? db.session.add(current_user) > ??? ??? ????? db.session.commit() > ??? ??? ????? login_user(current_user, form.remember_me.data) > ??? ??? ?? ?? return redirect(request.args.get('next') or > url_for('dashboard')) > ??? ????? flash('Invalid username or password.') > ?????? return render_template('auth/login.html', form=form) > > @app.route('/dashboard') > def dashboard(): > ????? return render_template("dashboard.html") > > Thank you for your time. > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask -- -- Kind regards, Leni Kadali Mutungi From sidwoodstock at gmail.com Mon Jul 1 18:14:24 2019 From: sidwoodstock at gmail.com (sidwoodstock .) Date: Mon, 1 Jul 2019 15:14:24 -0700 Subject: [Flask] Flask Digest, Vol 49, Issue 1 (Unable to set current_user.authenticated to True) In-Reply-To: References: Message-ID: At a cursory glance I would say that user.is_authenticated is not the same as user.authenticated.. Are you using Flask-Login? -Scott Woodstock On Mon, Jul 1, 2019 at 9:01 AM wrote: > Send Flask mailing list submissions to > flask at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/flask > or, via email, send a message with subject or body 'help' to > flask-request at python.org > > You can reach the person managing the list at > flask-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Flask digest..." > > > Today's Topics: > > 1. Unable to set current_user.authenticated to True (Abdul Mohammed) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Mon, 1 Jul 2019 16:14:33 +0100 > From: Abdul Mohammed > To: flask at python.org > Subject: [Flask] Unable to set current_user.authenticated to True > Message-ID: > 8j1pq2hW1ZdAVHA at mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > Hello everyone, > I am trying to toggle between "Sign in" and "Sign out" > links using the current_user.is_authenticated variable such that when it > returns False, the "Sign in" is displayed and when True the "Sign out" link > is displayed. At some point in the login code I set > current_user.authenticated = True. The thing is that by the I am > successfully logged in and presented with the next view, it is the "Sign > in" link that is still displayed. When I check > current_user.is_authenticated, it returns False, even though I had > explicitly set it to True. Please can anyone point out what I am might be > doing wrong? Here is my code: > > I have a base.html file that contains the "Sign in" and "Sign out" links > that is extended by the other templates: > > > > > {% block page_content %}{% endblock %} > > > > When the app first loads in the browser it displays a login form, > login.html: > > {% extends "base.html" %} > > {% block content %} > {% import "bootstrap/wtf.html" as wtf %} > {% block title %}Flasky - Login{% endblock %} > {% block page_content %} > >
> {{ wtf.quick_form(form) }} >
> {% endblock %} > {% endblock %} > > When a user logs in, it loads a template dashboard.html that displays a > map. The top part looks like this: > > {% extends "base.html" %} > > {% block page_content %} > > > Lagos Map > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > crossorigin=""/> > > > /> > /> > > > ... > ... > > And these are the relevant routes: > > @app.route('/',methods=['GET','POST']) > def index(): > form = LoginForm() > if form.validate_on_submit(): > user = User.query.filter_by(email=form.email.data).first() > if user is not None and user.check_password(form.password.data): > user.authenticated = True > current_user = user > db.session.add(current_user) > db.session.commit() > login_user(current_user, form.remember_me.data) > return redirect(request.args.get('next') or > url_for('dashboard')) > flash('Invalid username or password.') > return render_template('auth/login.html', form=form) > > @app.route('/dashboard') > def dashboard(): > return render_template("dashboard.html") > > Thank you for your time. > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/flask/attachments/20190701/9674ee57/attachment-0001.html > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > > ------------------------------ > > End of Flask Digest, Vol 49, Issue 1 > ************************************ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From imonikemohammed at gmail.com Tue Jul 2 11:34:34 2019 From: imonikemohammed at gmail.com (Abdul Mohammed) Date: Tue, 2 Jul 2019 16:34:34 +0100 Subject: [Flask] Flask Digest, Vol 49, Issue 2 In-Reply-To: References: Message-ID: Hello Thanks Leni, Scott for replying. I had tried that previously. user.is_authenticated cannot be set. It throws an error. I had stumbled upon a tutorial where user.authenticated had been set and so thought that was the proper way to modify the value of user.is_authenticated. When I set user.authenticated in the code, the app didn't throw any errors which further bolstered my previous beliefs. It's just that setting it seems to have no effect or its effect is reversed by the time login_user(user) logs you in to the next view. Just after setting user.authenticated to True, I issue a print statement to check the the value user.is_authenticated and it shows True. By the time login_user(user) logs me in, I issue another print statement and user.is_authenticated has reverted to False. On Mon, Jul 1, 2019 at 11:15 PM wrote: > Send Flask mailing list submissions to > flask at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/flask > or, via email, send a message with subject or body 'help' to > flask-request at python.org > > You can reach the person managing the list at > flask-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Flask digest..." > > > Today's Topics: > > 1. Re: Unable to set current_user.authenticated to True > (Leni Kadali Mutungi) > 2. Re: Flask Digest, Vol 49, Issue 1 (Unable to set > current_user.authenticated to True) (sidwoodstock .) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Mon, 1 Jul 2019 20:03:04 +0300 > From: Leni Kadali Mutungi > To: flask at python.org > Subject: Re: [Flask] Unable to set current_user.authenticated to True > Message-ID: <177572e2-a71d-a250-e6ec-defcce5b5161 at gmail.com> > Content-Type: text/plain; charset=utf-8; format=flowed > > I think you mean to set it as `current_user.is_authenticated = True`. > > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > > Hello everyone, > > ????????????????? I am trying to toggle between "Sign in" and "Sign > > out" links using the current_user.is_authenticated variable such that > > when it returns False, the "Sign in" is displayed and when True the > > "Sign out" link is displayed. At some point in the login code I set > > current_user.authenticated = True. The thing is that by the I am > > successfully logged?in and presented with the next view, it is the > > "Sign in" link that is still displayed. When I check > > current_user.is_authenticated, it returns False, even though I had > > explicitly set it to True. Please can anyone point out what I am might > > be doing?wrong? Here is my code: > > > > I have a base.html file that contains the "Sign in" and "Sign out" > > links that is extended by the other templates: > > > > > > > > > > {% block page_content %}{% endblock %} > > > > > > > > ?When the app first loads in the browser it displays a login form, > > login.html: > > > > ?{% extends "base.html" %} > > > > {% block content %} > > ??? {% import "bootstrap/wtf.html" as wtf %} > > ??? {% block title %}Flasky - Login{% endblock %} > > ??? {% block page_content %} > > ??? > > ???
> > ??? ??? {{ wtf.quick_form(form) }} > > ???
> > ??? {% endblock %} > > {% endblock %} > > > > When a user logs in, it loads a template dashboard.html that displays > > a map. The top part looks like this: > > > > {% extends "base.html" %} > > > > {% block page_content %} > > > > ? > > ?? Lagos Map > > ?? > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > ?? crossorigin=""/> > > ?? > > ?? > > ?? > href=" > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css" > > > /> > > ?? > href=" > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css" > > > /> > > ?? > > ?? > > ? ... > > ? ... > > > > And these are the relevant routes: > > > > @app.route('/',methods=['GET','POST']) > > def index(): > > ?? ?? form = LoginForm() > > ????? if form.validate_on_submit(): > > ??? ????? user = User.query.filter_by(email=form.email.data).first() > > ??? ????? if user is not None and > user.check_password(form.password.data): > > ??? ??? ????? user.authenticated = True > > ??? ??? ????? current_user = user > > ??? ??? ????? db.session.add(current_user) > > ??? ??? ????? db.session.commit() > > ??? ??? ????? login_user(current_user, form.remember_me.data) > > ??? ??? ?? ?? return redirect(request.args.get('next') or > > url_for('dashboard')) > > ??? ????? flash('Invalid username or password.') > > ?????? return render_template('auth/login.html', form=form) > > > > @app.route('/dashboard') > > def dashboard(): > > ????? return render_template("dashboard.html") > > > > Thank you for your time. > > > > _______________________________________________ > > Flask mailing list > > Flask at python.org > > https://mail.python.org/mailman/listinfo/flask > > -- > -- Kind regards, > Leni Kadali Mutungi > > > > ------------------------------ > > Message: 2 > Date: Mon, 1 Jul 2019 15:14:24 -0700 > From: "sidwoodstock ." > To: flask at python.org > Subject: Re: [Flask] Flask Digest, Vol 49, Issue 1 (Unable to set > current_user.authenticated to True) > Message-ID: > < > CALovGGPvjb8Zh+BKOx6kj7+ZQ71fj1BJv5WRYbrxxijyFnMKgQ at mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > At a cursory glance I would say that user.is_authenticated is not the same > as user.authenticated.. > > Are you using Flask-Login? > > -Scott Woodstock > > On Mon, Jul 1, 2019 at 9:01 AM wrote: > > > Send Flask mailing list submissions to > > flask at python.org > > > > To subscribe or unsubscribe via the World Wide Web, visit > > https://mail.python.org/mailman/listinfo/flask > > or, via email, send a message with subject or body 'help' to > > flask-request at python.org > > > > You can reach the person managing the list at > > flask-owner at python.org > > > > When replying, please edit your Subject line so it is more specific > > than "Re: Contents of Flask digest..." > > > > > > Today's Topics: > > > > 1. Unable to set current_user.authenticated to True (Abdul Mohammed) > > > > > > ---------------------------------------------------------------------- > > > > Message: 1 > > Date: Mon, 1 Jul 2019 16:14:33 +0100 > > From: Abdul Mohammed > > To: flask at python.org > > Subject: [Flask] Unable to set current_user.authenticated to True > > Message-ID: > > > 8j1pq2hW1ZdAVHA at mail.gmail.com> > > Content-Type: text/plain; charset="utf-8" > > > > Hello everyone, > > I am trying to toggle between "Sign in" and "Sign out" > > links using the current_user.is_authenticated variable such that when it > > returns False, the "Sign in" is displayed and when True the "Sign out" > link > > is displayed. At some point in the login code I set > > current_user.authenticated = True. The thing is that by the I am > > successfully logged in and presented with the next view, it is the "Sign > > in" link that is still displayed. When I check > > current_user.is_authenticated, it returns False, even though I had > > explicitly set it to True. Please can anyone point out what I am might be > > doing wrong? Here is my code: > > > > I have a base.html file that contains the "Sign in" and "Sign out" links > > that is extended by the other templates: > > > > > > > > > > {% block page_content %}{% endblock %} > > > > > > > > When the app first loads in the browser it displays a login form, > > login.html: > > > > {% extends "base.html" %} > > > > {% block content %} > > {% import "bootstrap/wtf.html" as wtf %} > > {% block title %}Flasky - Login{% endblock %} > > {% block page_content %} > > > >
> > {{ wtf.quick_form(form) }} > >
> > {% endblock %} > > {% endblock %} > > > > When a user logs in, it loads a template dashboard.html that displays a > > map. The top part looks like this: > > > > {% extends "base.html" %} > > > > {% block page_content %} > > > > > > Lagos Map > > > > > > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > crossorigin=""/> > > > > > > > /> > > > /> > > > > > > ... > > ... > > > > And these are the relevant routes: > > > > @app.route('/',methods=['GET','POST']) > > def index(): > > form = LoginForm() > > if form.validate_on_submit(): > > user = User.query.filter_by(email=form.email.data).first() > > if user is not None and > user.check_password(form.password.data): > > user.authenticated = True > > current_user = user > > db.session.add(current_user) > > db.session.commit() > > login_user(current_user, form.remember_me.data) > > return redirect(request.args.get('next') or > > url_for('dashboard')) > > flash('Invalid username or password.') > > return render_template('auth/login.html', form=form) > > > > @app.route('/dashboard') > > def dashboard(): > > return render_template("dashboard.html") > > > > Thank you for your time. > > -------------- next part -------------- > > An HTML attachment was scrubbed... > > URL: < > > > http://mail.python.org/pipermail/flask/attachments/20190701/9674ee57/attachment-0001.html > > > > > > > ------------------------------ > > > > Subject: Digest Footer > > > > _______________________________________________ > > Flask mailing list > > Flask at python.org > > https://mail.python.org/mailman/listinfo/flask > > > > > > ------------------------------ > > > > End of Flask Digest, Vol 49, Issue 1 > > ************************************ > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/flask/attachments/20190701/9252979c/attachment.html > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > > ------------------------------ > > End of Flask Digest, Vol 49, Issue 2 > ************************************ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From imonikemohammed at gmail.com Tue Jul 2 12:07:15 2019 From: imonikemohammed at gmail.com (Abdul Mohammed) Date: Tue, 2 Jul 2019 17:07:15 +0100 Subject: [Flask] Flask Digest, Vol 49, Issue 2 In-Reply-To: References: Message-ID: Oh yes Scott I am using flask_login...or at least trying to use it. Regards On Tue, Jul 2, 2019 at 4:34 PM Abdul Mohammed wrote: > Hello > Thanks Leni, Scott for replying. I had tried that previously. > user.is_authenticated cannot be set. It throws an error. > I had stumbled upon a tutorial where user.authenticated had been set and > so thought that was the proper way to modify the value > of user.is_authenticated. When I set user.authenticated in the code, the > app didn't throw any errors which further bolstered my > previous beliefs. It's just that setting it seems to have no effect or its > effect is reversed by the time login_user(user) logs you in to > the next view. Just after setting user.authenticated to True, I issue a > print statement to check the the value user.is_authenticated > and it shows True. By the time login_user(user) logs me in, I issue > another print statement and user.is_authenticated has reverted > to False. > > On Mon, Jul 1, 2019 at 11:15 PM wrote: > >> Send Flask mailing list submissions to >> flask at python.org >> >> To subscribe or unsubscribe via the World Wide Web, visit >> https://mail.python.org/mailman/listinfo/flask >> or, via email, send a message with subject or body 'help' to >> flask-request at python.org >> >> You can reach the person managing the list at >> flask-owner at python.org >> >> When replying, please edit your Subject line so it is more specific >> than "Re: Contents of Flask digest..." >> >> >> Today's Topics: >> >> 1. Re: Unable to set current_user.authenticated to True >> (Leni Kadali Mutungi) >> 2. Re: Flask Digest, Vol 49, Issue 1 (Unable to set >> current_user.authenticated to True) (sidwoodstock .) >> >> >> ---------------------------------------------------------------------- >> >> Message: 1 >> Date: Mon, 1 Jul 2019 20:03:04 +0300 >> From: Leni Kadali Mutungi >> To: flask at python.org >> Subject: Re: [Flask] Unable to set current_user.authenticated to True >> Message-ID: <177572e2-a71d-a250-e6ec-defcce5b5161 at gmail.com> >> Content-Type: text/plain; charset=utf-8; format=flowed >> >> I think you mean to set it as `current_user.is_authenticated = True`. >> >> On 7/1/19 6:14 PM, Abdul Mohammed wrote: >> > Hello everyone, >> > ????????????????? I am trying to toggle between "Sign in" and "Sign >> > out" links using the current_user.is_authenticated variable such that >> > when it returns False, the "Sign in" is displayed and when True the >> > "Sign out" link is displayed. At some point in the login code I set >> > current_user.authenticated = True. The thing is that by the I am >> > successfully logged?in and presented with the next view, it is the >> > "Sign in" link that is still displayed. When I check >> > current_user.is_authenticated, it returns False, even though I had >> > explicitly set it to True. Please can anyone point out what I am might >> > be doing?wrong? Here is my code: >> > >> > I have a base.html file that contains the "Sign in" and "Sign out" >> > links that is extended by the other templates: >> > >> > >> > >> > >> > {% block page_content %}{% endblock %} >> > >> > >> > >> > ?When the app first loads in the browser it displays a login form, >> > login.html: >> > >> > ?{% extends "base.html" %} >> > >> > {% block content %} >> > ??? {% import "bootstrap/wtf.html" as wtf %} >> > ??? {% block title %}Flasky - Login{% endblock %} >> > ??? {% block page_content %} >> > ??? >> > ???
>> > ??? ??? {{ wtf.quick_form(form) }} >> > ???
>> > ??? {% endblock %} >> > {% endblock %} >> > >> > When a user logs in, it loads a template dashboard.html that displays >> > a map. The top part looks like this: >> > >> > {% extends "base.html" %} >> > >> > {% block page_content %} >> > >> > ? >> > ?? Lagos Map >> > ?? > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" >> > >> integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" >> > ?? crossorigin=""/> >> > ?? >> > ?? >> > ?? > > href=" >> https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css" >> >> > /> >> > ?? > > href=" >> https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css" >> >> > /> >> > ?? >> > ?? >> > ? ... >> > ? ... >> > >> > And these are the relevant routes: >> > >> > @app.route('/',methods=['GET','POST']) >> > def index(): >> > ?? ?? form = LoginForm() >> > ????? if form.validate_on_submit(): >> > ??? ????? user = User.query.filter_by(email=form.email.data).first() >> > ??? ????? if user is not None and >> user.check_password(form.password.data): >> > ??? ??? ????? user.authenticated = True >> > ??? ??? ????? current_user = user >> > ??? ??? ????? db.session.add(current_user) >> > ??? ??? ????? db.session.commit() >> > ??? ??? ????? login_user(current_user, form.remember_me.data) >> > ??? ??? ?? ?? return redirect(request.args.get('next') or >> > url_for('dashboard')) >> > ??? ????? flash('Invalid username or password.') >> > ?????? return render_template('auth/login.html', form=form) >> > >> > @app.route('/dashboard') >> > def dashboard(): >> > ????? return render_template("dashboard.html") >> > >> > Thank you for your time. >> > >> > _______________________________________________ >> > Flask mailing list >> > Flask at python.org >> > https://mail.python.org/mailman/listinfo/flask >> >> -- >> -- Kind regards, >> Leni Kadali Mutungi >> >> >> >> ------------------------------ >> >> Message: 2 >> Date: Mon, 1 Jul 2019 15:14:24 -0700 >> From: "sidwoodstock ." >> To: flask at python.org >> Subject: Re: [Flask] Flask Digest, Vol 49, Issue 1 (Unable to set >> current_user.authenticated to True) >> Message-ID: >> < >> CALovGGPvjb8Zh+BKOx6kj7+ZQ71fj1BJv5WRYbrxxijyFnMKgQ at mail.gmail.com> >> Content-Type: text/plain; charset="utf-8" >> >> At a cursory glance I would say that user.is_authenticated is not the same >> as user.authenticated.. >> >> Are you using Flask-Login? >> >> -Scott Woodstock >> >> On Mon, Jul 1, 2019 at 9:01 AM wrote: >> >> > Send Flask mailing list submissions to >> > flask at python.org >> > >> > To subscribe or unsubscribe via the World Wide Web, visit >> > https://mail.python.org/mailman/listinfo/flask >> > or, via email, send a message with subject or body 'help' to >> > flask-request at python.org >> > >> > You can reach the person managing the list at >> > flask-owner at python.org >> > >> > When replying, please edit your Subject line so it is more specific >> > than "Re: Contents of Flask digest..." >> > >> > >> > Today's Topics: >> > >> > 1. Unable to set current_user.authenticated to True (Abdul Mohammed) >> > >> > >> > ---------------------------------------------------------------------- >> > >> > Message: 1 >> > Date: Mon, 1 Jul 2019 16:14:33 +0100 >> > From: Abdul Mohammed >> > To: flask at python.org >> > Subject: [Flask] Unable to set current_user.authenticated to True >> > Message-ID: >> > > > 8j1pq2hW1ZdAVHA at mail.gmail.com> >> > Content-Type: text/plain; charset="utf-8" >> > >> > Hello everyone, >> > I am trying to toggle between "Sign in" and "Sign out" >> > links using the current_user.is_authenticated variable such that when it >> > returns False, the "Sign in" is displayed and when True the "Sign out" >> link >> > is displayed. At some point in the login code I set >> > current_user.authenticated = True. The thing is that by the I am >> > successfully logged in and presented with the next view, it is the "Sign >> > in" link that is still displayed. When I check >> > current_user.is_authenticated, it returns False, even though I had >> > explicitly set it to True. Please can anyone point out what I am might >> be >> > doing wrong? Here is my code: >> > >> > I have a base.html file that contains the "Sign in" and "Sign out" links >> > that is extended by the other templates: >> > >> > >> > >> > >> > {% block page_content %}{% endblock %} >> > >> > >> > >> > When the app first loads in the browser it displays a login form, >> > login.html: >> > >> > {% extends "base.html" %} >> > >> > {% block content %} >> > {% import "bootstrap/wtf.html" as wtf %} >> > {% block title %}Flasky - Login{% endblock %} >> > {% block page_content %} >> > >> >
>> > {{ wtf.quick_form(form) }} >> >
>> > {% endblock %} >> > {% endblock %} >> > >> > When a user logs in, it loads a template dashboard.html that displays a >> > map. The top part looks like this: >> > >> > {% extends "base.html" %} >> > >> > {% block page_content %} >> > >> > >> > Lagos Map >> > > > >> > >> > >> integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" >> > crossorigin=""/> >> > >> > >> > > > /> >> > > > /> >> > >> > >> > ... >> > ... >> > >> > And these are the relevant routes: >> > >> > @app.route('/',methods=['GET','POST']) >> > def index(): >> > form = LoginForm() >> > if form.validate_on_submit(): >> > user = User.query.filter_by(email=form.email.data).first() >> > if user is not None and >> user.check_password(form.password.data): >> > user.authenticated = True >> > current_user = user >> > db.session.add(current_user) >> > db.session.commit() >> > login_user(current_user, form.remember_me.data) >> > return redirect(request.args.get('next') or >> > url_for('dashboard')) >> > flash('Invalid username or password.') >> > return render_template('auth/login.html', form=form) >> > >> > @app.route('/dashboard') >> > def dashboard(): >> > return render_template("dashboard.html") >> > >> > Thank you for your time. >> > -------------- next part -------------- >> > An HTML attachment was scrubbed... >> > URL: < >> > >> http://mail.python.org/pipermail/flask/attachments/20190701/9674ee57/attachment-0001.html >> > > >> > >> > ------------------------------ >> > >> > Subject: Digest Footer >> > >> > _______________________________________________ >> > Flask mailing list >> > Flask at python.org >> > https://mail.python.org/mailman/listinfo/flask >> > >> > >> > ------------------------------ >> > >> > End of Flask Digest, Vol 49, Issue 1 >> > ************************************ >> > >> -------------- next part -------------- >> An HTML attachment was scrubbed... >> URL: < >> http://mail.python.org/pipermail/flask/attachments/20190701/9252979c/attachment.html >> > >> >> ------------------------------ >> >> Subject: Digest Footer >> >> _______________________________________________ >> Flask mailing list >> Flask at python.org >> https://mail.python.org/mailman/listinfo/flask >> >> >> ------------------------------ >> >> End of Flask Digest, Vol 49, Issue 2 >> ************************************ >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gergely at polonkai.eu Tue Jul 2 13:01:20 2019 From: gergely at polonkai.eu (Gergely Polonkai) Date: Tue, 2 Jul 2019 19:01:20 +0200 Subject: [Flask] Unable to set current_user.authenticated to True In-Reply-To: <177572e2-a71d-a250-e6ec-defcce5b5161@gmail.com> References: <177572e2-a71d-a250-e6ec-defcce5b5161@gmail.com> Message-ID: Hello, I assume you are using Flask-Login (either directly or via another extension like Flask-Security). If this is the case, you can import login_user and call it like login_user(user). If that does not work, you may want to check if the user is active (ie. not disabled), as it is the most common culprit when a user can?t be logged in. Best, Gergely On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, wrote: > I think you mean to set it as `current_user.is_authenticated = True`. > > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > > Hello everyone, > > I am trying to toggle between "Sign in" and "Sign > > out" links using the current_user.is_authenticated variable such that > > when it returns False, the "Sign in" is displayed and when True the > > "Sign out" link is displayed. At some point in the login code I set > > current_user.authenticated = True. The thing is that by the I am > > successfully logged in and presented with the next view, it is the > > "Sign in" link that is still displayed. When I check > > current_user.is_authenticated, it returns False, even though I had > > explicitly set it to True. Please can anyone point out what I am might > > be doing wrong? Here is my code: > > > > I have a base.html file that contains the "Sign in" and "Sign out" > > links that is extended by the other templates: > > > > > > > > > > {% block page_content %}{% endblock %} > > > > > > > > When the app first loads in the browser it displays a login form, > > login.html: > > > > {% extends "base.html" %} > > > > {% block content %} > > {% import "bootstrap/wtf.html" as wtf %} > > {% block title %}Flasky - Login{% endblock %} > > {% block page_content %} > > > >
> > {{ wtf.quick_form(form) }} > >
> > {% endblock %} > > {% endblock %} > > > > When a user logs in, it loads a template dashboard.html that displays > > a map. The top part looks like this: > > > > {% extends "base.html" %} > > > > {% block page_content %} > > > > > > Lagos Map > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > crossorigin=""/> > > > > > > > href=" > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css" > > > /> > > > href=" > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css" > > > /> > > > > > > ... > > ... > > > > And these are the relevant routes: > > > > @app.route('/',methods=['GET','POST']) > > def index(): > > form = LoginForm() > > if form.validate_on_submit(): > > user = User.query.filter_by(email=form.email.data).first() > > if user is not None and > user.check_password(form.password.data): > > user.authenticated = True > > current_user = user > > db.session.add(current_user) > > db.session.commit() > > login_user(current_user, form.remember_me.data) > > return redirect(request.args.get('next') or > > url_for('dashboard')) > > flash('Invalid username or password.') > > return render_template('auth/login.html', form=form) > > > > @app.route('/dashboard') > > def dashboard(): > > return render_template("dashboard.html") > > > > Thank you for your time. > > > > _______________________________________________ > > Flask mailing list > > Flask at python.org > > https://mail.python.org/mailman/listinfo/flask > > -- > -- Kind regards, > Leni Kadali Mutungi > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sidwoodstock at gmail.com Wed Jul 3 12:19:20 2019 From: sidwoodstock at gmail.com (sidwoodstock .) Date: Wed, 3 Jul 2019 09:19:20 -0700 Subject: [Flask] Unable to set current_user.authenticated to True In-Reply-To: References: Message-ID: Also, if Gergely's suggestion doesn't work, you could try removing your variable assignment of current_user = user. I see no practical reason to do this, and since current_user is a built-in (and very handy) variable, maybe that is somehow related to your issue? > > current_user = user and then just call login_user directly with your user you already have at hand: > > login_user(user, form.remember_me.data) -Scott On Wed, Jul 3, 2019 at 9:03 AM wrote: > Send Flask mailing list submissions to > flask at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/flask > or, via email, send a message with subject or body 'help' to > flask-request at python.org > > You can reach the person managing the list at > flask-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Flask digest..." > > > Today's Topics: > > 1. Re: Unable to set current_user.authenticated to True > (Gergely Polonkai) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Tue, 2 Jul 2019 19:01:20 +0200 > From: Gergely Polonkai > To: Leni Kadali Mutungi > Cc: flask > Subject: Re: [Flask] Unable to set current_user.authenticated to True > Message-ID: > zxtk3bMO+n-+-y3Q at mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > Hello, > > I assume you are using Flask-Login (either directly or via another > extension like Flask-Security). If this is the case, you can import > login_user and call it like login_user(user). > > If that does not work, you may want to check if the user is active (ie. not > disabled), as it is the most common culprit when a user can?t be logged in. > > Best, > Gergely > > On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, > wrote: > > > I think you mean to set it as `current_user.is_authenticated = True`. > > > > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > > > Hello everyone, > > > I am trying to toggle between "Sign in" and "Sign > > > out" links using the current_user.is_authenticated variable such that > > > when it returns False, the "Sign in" is displayed and when True the > > > "Sign out" link is displayed. At some point in the login code I set > > > current_user.authenticated = True. The thing is that by the I am > > > successfully logged in and presented with the next view, it is the > > > "Sign in" link that is still displayed. When I check > > > current_user.is_authenticated, it returns False, even though I had > > > explicitly set it to True. Please can anyone point out what I am might > > > be doing wrong? Here is my code: > > > > > > I have a base.html file that contains the "Sign in" and "Sign out" > > > links that is extended by the other templates: > > > > > > > > > > > > > > > {% block page_content %}{% endblock %} > > > > > > > > > > > > When the app first loads in the browser it displays a login form, > > > login.html: > > > > > > {% extends "base.html" %} > > > > > > {% block content %} > > > {% import "bootstrap/wtf.html" as wtf %} > > > {% block title %}Flasky - Login{% endblock %} > > > {% block page_content %} > > > > > >
> > > {{ wtf.quick_form(form) }} > > >
> > > {% endblock %} > > > {% endblock %} > > > > > > When a user logs in, it loads a template dashboard.html that displays > > > a map. The top part looks like this: > > > > > > {% extends "base.html" %} > > > > > > {% block page_content %} > > > > > > > > > Lagos Map > > > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > > > > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > > crossorigin=""/> > > > > > > > > > > > href=" > > > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > " > > > > > /> > > > > > href=" > > > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > " > > > > > /> > > > > > > > > > ... > > > ... > > > > > > And these are the relevant routes: > > > > > > @app.route('/',methods=['GET','POST']) > > > def index(): > > > form = LoginForm() > > > if form.validate_on_submit(): > > > user = User.query.filter_by(email=form.email.data).first() > > > if user is not None and > > user.check_password(form.password.data): > > > user.authenticated = True > > > current_user = user > > > db.session.add(current_user) > > > db.session.commit() > > > login_user(current_user, form.remember_me.data) > > > return redirect(request.args.get('next') or > > > url_for('dashboard')) > > > flash('Invalid username or password.') > > > return render_template('auth/login.html', form=form) > > > > > > @app.route('/dashboard') > > > def dashboard(): > > > return render_template("dashboard.html") > > > > > > Thank you for your time. > > > > > > _______________________________________________ > > > Flask mailing list > > > Flask at python.org > > > https://mail.python.org/mailman/listinfo/flask > > > > -- > > -- Kind regards, > > Leni Kadali Mutungi > > > > _______________________________________________ > > Flask mailing list > > Flask at python.org > > https://mail.python.org/mailman/listinfo/flask > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > > ------------------------------ > > End of Flask Digest, Vol 49, Issue 5 > ************************************ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gergely at polonkai.eu Thu Jul 4 00:25:40 2019 From: gergely at polonkai.eu (Gergely Polonkai) Date: Thu, 4 Jul 2019 06:25:40 +0200 Subject: [Flask] Unable to set current_user.authenticated to True In-Reply-To: References: Message-ID: No, modifying current_user directly is not possible (at least it won?t propagate outside the function). current_user is a proxy object that points to the logged in user in the current request. If you assign a different value to it, its proxy nature goes away which is definitely not what you want: in extreme cases it might introduce security issues where users can access each the data of other. On Wed, 3 Jul 2019, 18:19 sidwoodstock ., wrote: > Also, if Gergely's suggestion doesn't work, you could try removing your > variable assignment of current_user = user. I see no practical reason to do > this, and since current_user is a built-in (and very handy) variable, maybe > that is somehow related to your issue? > > > > current_user = user > > and then just call login_user directly with your user you already have at > hand: > > > > login_user(user, form.remember_me.data) > > -Scott > > On Wed, Jul 3, 2019 at 9:03 AM wrote: > >> Send Flask mailing list submissions to >> flask at python.org >> >> To subscribe or unsubscribe via the World Wide Web, visit >> https://mail.python.org/mailman/listinfo/flask >> or, via email, send a message with subject or body 'help' to >> flask-request at python.org >> >> You can reach the person managing the list at >> flask-owner at python.org >> >> When replying, please edit your Subject line so it is more specific >> than "Re: Contents of Flask digest..." >> >> >> Today's Topics: >> >> 1. Re: Unable to set current_user.authenticated to True >> (Gergely Polonkai) >> >> >> ---------------------------------------------------------------------- >> >> Message: 1 >> Date: Tue, 2 Jul 2019 19:01:20 +0200 >> From: Gergely Polonkai >> To: Leni Kadali Mutungi >> Cc: flask >> Subject: Re: [Flask] Unable to set current_user.authenticated to True >> Message-ID: >> > zxtk3bMO+n-+-y3Q at mail.gmail.com> >> Content-Type: text/plain; charset="utf-8" >> >> Hello, >> >> I assume you are using Flask-Login (either directly or via another >> extension like Flask-Security). If this is the case, you can import >> login_user and call it like login_user(user). >> >> If that does not work, you may want to check if the user is active (ie. >> not >> disabled), as it is the most common culprit when a user can?t be logged >> in. >> >> Best, >> Gergely >> >> On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, >> wrote: >> >> > I think you mean to set it as `current_user.is_authenticated = True`. >> > >> > On 7/1/19 6:14 PM, Abdul Mohammed wrote: >> > > Hello everyone, >> > > I am trying to toggle between "Sign in" and "Sign >> > > out" links using the current_user.is_authenticated variable such that >> > > when it returns False, the "Sign in" is displayed and when True the >> > > "Sign out" link is displayed. At some point in the login code I set >> > > current_user.authenticated = True. The thing is that by the I am >> > > successfully logged in and presented with the next view, it is the >> > > "Sign in" link that is still displayed. When I check >> > > current_user.is_authenticated, it returns False, even though I had >> > > explicitly set it to True. Please can anyone point out what I am might >> > > be doing wrong? Here is my code: >> > > >> > > I have a base.html file that contains the "Sign in" and "Sign out" >> > > links that is extended by the other templates: >> > > >> > > >> > > >> > > >> > > {% block page_content %}{% endblock %} >> > > >> > > >> > > >> > > When the app first loads in the browser it displays a login form, >> > > login.html: >> > > >> > > {% extends "base.html" %} >> > > >> > > {% block content %} >> > > {% import "bootstrap/wtf.html" as wtf %} >> > > {% block title %}Flasky - Login{% endblock %} >> > > {% block page_content %} >> > > >> > >
>> > > {{ wtf.quick_form(form) }} >> > >
>> > > {% endblock %} >> > > {% endblock %} >> > > >> > > When a user logs in, it loads a template dashboard.html that displays >> > > a map. The top part looks like this: >> > > >> > > {% extends "base.html" %} >> > > >> > > {% block page_content %} >> > > >> > > >> > > Lagos Map >> > > > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" >> > > >> > >> integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" >> > > crossorigin=""/> >> > > >> > > >> > > > > > href=" >> > >> https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css >> " >> > >> > > /> >> > > > > > href=" >> > >> https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css >> " >> > >> > > /> >> > > >> > > >> > > ... >> > > ... >> > > >> > > And these are the relevant routes: >> > > >> > > @app.route('/',methods=['GET','POST']) >> > > def index(): >> > > form = LoginForm() >> > > if form.validate_on_submit(): >> > > user = User.query.filter_by(email=form.email.data).first() >> > > if user is not None and >> > user.check_password(form.password.data): >> > > user.authenticated = True >> > > current_user = user >> > > db.session.add(current_user) >> > > db.session.commit() >> > > login_user(current_user, form.remember_me.data) >> > > return redirect(request.args.get('next') or >> > > url_for('dashboard')) >> > > flash('Invalid username or password.') >> > > return render_template('auth/login.html', form=form) >> > > >> > > @app.route('/dashboard') >> > > def dashboard(): >> > > return render_template("dashboard.html") >> > > >> > > Thank you for your time. >> > > >> > > _______________________________________________ >> > > Flask mailing list >> > > Flask at python.org >> > > https://mail.python.org/mailman/listinfo/flask >> > >> > -- >> > -- Kind regards, >> > Leni Kadali Mutungi >> > >> > _______________________________________________ >> > Flask mailing list >> > Flask at python.org >> > https://mail.python.org/mailman/listinfo/flask >> > >> -------------- next part -------------- >> An HTML attachment was scrubbed... >> URL: < >> http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html >> > >> >> ------------------------------ >> >> Subject: Digest Footer >> >> _______________________________________________ >> Flask mailing list >> Flask at python.org >> https://mail.python.org/mailman/listinfo/flask >> >> >> ------------------------------ >> >> End of Flask Digest, Vol 49, Issue 5 >> ************************************ >> > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > On Wed, 3 Jul 2019, 18:19 sidwoodstock ., wrote: > Also, if Gergely's suggestion doesn't work, you could try removing your > variable assignment of current_user = user. I see no practical reason to do > this, and since current_user is a built-in (and very handy) variable, maybe > that is somehow related to your issue? > > > > current_user = user > > and then just call login_user directly with your user you already have at > hand: > > > > login_user(user, form.remember_me.data) > > -Scott > > On Wed, Jul 3, 2019 at 9:03 AM wrote: > >> Send Flask mailing list submissions to >> flask at python.org >> >> To subscribe or unsubscribe via the World Wide Web, visit >> https://mail.python.org/mailman/listinfo/flask >> or, via email, send a message with subject or body 'help' to >> flask-request at python.org >> >> You can reach the person managing the list at >> flask-owner at python.org >> >> When replying, please edit your Subject line so it is more specific >> than "Re: Contents of Flask digest..." >> >> >> Today's Topics: >> >> 1. Re: Unable to set current_user.authenticated to True >> (Gergely Polonkai) >> >> >> ---------------------------------------------------------------------- >> >> Message: 1 >> Date: Tue, 2 Jul 2019 19:01:20 +0200 >> From: Gergely Polonkai >> To: Leni Kadali Mutungi >> Cc: flask >> Subject: Re: [Flask] Unable to set current_user.authenticated to True >> Message-ID: >> > zxtk3bMO+n-+-y3Q at mail.gmail.com> >> Content-Type: text/plain; charset="utf-8" >> >> Hello, >> >> I assume you are using Flask-Login (either directly or via another >> extension like Flask-Security). If this is the case, you can import >> login_user and call it like login_user(user). >> >> If that does not work, you may want to check if the user is active (ie. >> not >> disabled), as it is the most common culprit when a user can?t be logged >> in. >> >> Best, >> Gergely >> >> On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, >> wrote: >> >> > I think you mean to set it as `current_user.is_authenticated = True`. >> > >> > On 7/1/19 6:14 PM, Abdul Mohammed wrote: >> > > Hello everyone, >> > > I am trying to toggle between "Sign in" and "Sign >> > > out" links using the current_user.is_authenticated variable such that >> > > when it returns False, the "Sign in" is displayed and when True the >> > > "Sign out" link is displayed. At some point in the login code I set >> > > current_user.authenticated = True. The thing is that by the I am >> > > successfully logged in and presented with the next view, it is the >> > > "Sign in" link that is still displayed. When I check >> > > current_user.is_authenticated, it returns False, even though I had >> > > explicitly set it to True. Please can anyone point out what I am might >> > > be doing wrong? Here is my code: >> > > >> > > I have a base.html file that contains the "Sign in" and "Sign out" >> > > links that is extended by the other templates: >> > > >> > > >> > > >> > > >> > > {% block page_content %}{% endblock %} >> > > >> > > >> > > >> > > When the app first loads in the browser it displays a login form, >> > > login.html: >> > > >> > > {% extends "base.html" %} >> > > >> > > {% block content %} >> > > {% import "bootstrap/wtf.html" as wtf %} >> > > {% block title %}Flasky - Login{% endblock %} >> > > {% block page_content %} >> > > >> > >
>> > > {{ wtf.quick_form(form) }} >> > >
>> > > {% endblock %} >> > > {% endblock %} >> > > >> > > When a user logs in, it loads a template dashboard.html that displays >> > > a map. The top part looks like this: >> > > >> > > {% extends "base.html" %} >> > > >> > > {% block page_content %} >> > > >> > > >> > > Lagos Map >> > > > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" >> > > >> > >> integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" >> > > crossorigin=""/> >> > > >> > > >> > > > > > href=" >> > >> https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css >> " >> > >> > > /> >> > > > > > href=" >> > >> https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css >> " >> > >> > > /> >> > > >> > > >> > > ... >> > > ... >> > > >> > > And these are the relevant routes: >> > > >> > > @app.route('/',methods=['GET','POST']) >> > > def index(): >> > > form = LoginForm() >> > > if form.validate_on_submit(): >> > > user = User.query.filter_by(email=form.email.data).first() >> > > if user is not None and >> > user.check_password(form.password.data): >> > > user.authenticated = True >> > > current_user = user >> > > db.session.add(current_user) >> > > db.session.commit() >> > > login_user(current_user, form.remember_me.data) >> > > return redirect(request.args.get('next') or >> > > url_for('dashboard')) >> > > flash('Invalid username or password.') >> > > return render_template('auth/login.html', form=form) >> > > >> > > @app.route('/dashboard') >> > > def dashboard(): >> > > return render_template("dashboard.html") >> > > >> > > Thank you for your time. >> > > >> > > _______________________________________________ >> > > Flask mailing list >> > > Flask at python.org >> > > https://mail.python.org/mailman/listinfo/flask >> > >> > -- >> > -- Kind regards, >> > Leni Kadali Mutungi >> > >> > _______________________________________________ >> > Flask mailing list >> > Flask at python.org >> > https://mail.python.org/mailman/listinfo/flask >> > >> -------------- next part -------------- >> An HTML attachment was scrubbed... >> URL: < >> http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html >> > >> >> ------------------------------ >> >> Subject: Digest Footer >> >> _______________________________________________ >> Flask mailing list >> Flask at python.org >> https://mail.python.org/mailman/listinfo/flask >> >> >> ------------------------------ >> >> End of Flask Digest, Vol 49, Issue 5 >> ************************************ >> > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From imonikemohammed at gmail.com Thu Jul 4 11:22:42 2019 From: imonikemohammed at gmail.com (Abdul Mohammed) Date: Thu, 4 Jul 2019 16:22:42 +0100 Subject: [Flask] Flask Digest, Vol 49, Issue 5 In-Reply-To: References: Message-ID: Thanks Gergely for the response. Yes I am using Flask-Login and I think directly because this is how I import it: from flask_login import login_user My problem is not that I can't log in. I can log in fine. The problem is essentially that I can not log out. I am trying to use the value of current_user.is_authenticated to determine whether to show the "Sign in" or "Sign out" link. If True, it shows "Sign out" and "Sign in" when False. For some reason, the value remains False after I have logged in so the "Sign out" link never displays and so I am trapped in the app (Please save me!!!) because I can't log out. I hope I have made my problems clearer. Regards On Wed, Jul 3, 2019 at 5:04 PM wrote: > Send Flask mailing list submissions to > flask at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/flask > or, via email, send a message with subject or body 'help' to > flask-request at python.org > > You can reach the person managing the list at > flask-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Flask digest..." > > > Today's Topics: > > 1. Re: Unable to set current_user.authenticated to True > (Gergely Polonkai) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Tue, 2 Jul 2019 19:01:20 +0200 > From: Gergely Polonkai > To: Leni Kadali Mutungi > Cc: flask > Subject: Re: [Flask] Unable to set current_user.authenticated to True > Message-ID: > zxtk3bMO+n-+-y3Q at mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > Hello, > > I assume you are using Flask-Login (either directly or via another > extension like Flask-Security). If this is the case, you can import > login_user and call it like login_user(user). > > If that does not work, you may want to check if the user is active (ie. not > disabled), as it is the most common culprit when a user can?t be logged in. > > Best, > Gergely > > On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, > wrote: > > > I think you mean to set it as `current_user.is_authenticated = True`. > > > > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > > > Hello everyone, > > > I am trying to toggle between "Sign in" and "Sign > > > out" links using the current_user.is_authenticated variable such that > > > when it returns False, the "Sign in" is displayed and when True the > > > "Sign out" link is displayed. At some point in the login code I set > > > current_user.authenticated = True. The thing is that by the I am > > > successfully logged in and presented with the next view, it is the > > > "Sign in" link that is still displayed. When I check > > > current_user.is_authenticated, it returns False, even though I had > > > explicitly set it to True. Please can anyone point out what I am might > > > be doing wrong? Here is my code: > > > > > > I have a base.html file that contains the "Sign in" and "Sign out" > > > links that is extended by the other templates: > > > > > > > > > > > > > > > {% block page_content %}{% endblock %} > > > > > > > > > > > > When the app first loads in the browser it displays a login form, > > > login.html: > > > > > > {% extends "base.html" %} > > > > > > {% block content %} > > > {% import "bootstrap/wtf.html" as wtf %} > > > {% block title %}Flasky - Login{% endblock %} > > > {% block page_content %} > > > > > >
> > > {{ wtf.quick_form(form) }} > > >
> > > {% endblock %} > > > {% endblock %} > > > > > > When a user logs in, it loads a template dashboard.html that displays > > > a map. The top part looks like this: > > > > > > {% extends "base.html" %} > > > > > > {% block page_content %} > > > > > > > > > Lagos Map > > > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > > > > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > > crossorigin=""/> > > > > > > > > > > > href=" > > > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > " > > > > > /> > > > > > href=" > > > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > " > > > > > /> > > > > > > > > > ... > > > ... > > > > > > And these are the relevant routes: > > > > > > @app.route('/',methods=['GET','POST']) > > > def index(): > > > form = LoginForm() > > > if form.validate_on_submit(): > > > user = User.query.filter_by(email=form.email.data).first() > > > if user is not None and > > user.check_password(form.password.data): > > > user.authenticated = True > > > current_user = user > > > db.session.add(current_user) > > > db.session.commit() > > > login_user(current_user, form.remember_me.data) > > > return redirect(request.args.get('next') or > > > url_for('dashboard')) > > > flash('Invalid username or password.') > > > return render_template('auth/login.html', form=form) > > > > > > @app.route('/dashboard') > > > def dashboard(): > > > return render_template("dashboard.html") > > > > > > Thank you for your time. > > > > > > _______________________________________________ > > > Flask mailing list > > > Flask at python.org > > > https://mail.python.org/mailman/listinfo/flask > > > > -- > > -- Kind regards, > > Leni Kadali Mutungi > > > > _______________________________________________ > > Flask mailing list > > Flask at python.org > > https://mail.python.org/mailman/listinfo/flask > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > > ------------------------------ > > End of Flask Digest, Vol 49, Issue 5 > ************************************ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From imonikemohammed at gmail.com Thu Jul 4 11:55:18 2019 From: imonikemohammed at gmail.com (Abdul Mohammed) Date: Thu, 4 Jul 2019 16:55:18 +0100 Subject: [Flask] Flask Digest, Vol 49, Issue 6 In-Reply-To: References: Message-ID: Thanks Scott. I just explained to Gergely that my problem is not logging in but getting the value of current_user.is_authenticated to change to True so that I can log out. I wasn't originally doing the current_user = user assignment. I could log in with either current_user or user. When the value of current_user.is_authenticated wouldn't change to True, I added it because i was just trying to see whether it would solve my problem. I will get rid of it but the problem is likely to remain. On Thu, Jul 4, 2019 at 5:26 AM wrote: > Send Flask mailing list submissions to > flask at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/flask > or, via email, send a message with subject or body 'help' to > flask-request at python.org > > You can reach the person managing the list at > flask-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Flask digest..." > > > Today's Topics: > > 1. Re: Unable to set current_user.authenticated to True > (sidwoodstock .) > 2. Re: Unable to set current_user.authenticated to True > (Gergely Polonkai) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Wed, 3 Jul 2019 09:19:20 -0700 > From: "sidwoodstock ." > To: flask at python.org > Subject: Re: [Flask] Unable to set current_user.authenticated to True > Message-ID: > KV78LHGK2k8hA at mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > Also, if Gergely's suggestion doesn't work, you could try removing your > variable assignment of current_user = user. I see no practical reason to do > this, and since current_user is a built-in (and very handy) variable, maybe > that is somehow related to your issue? > > > > current_user = user > > and then just call login_user directly with your user you already have at > hand: > > > > login_user(user, form.remember_me.data) > > -Scott > > On Wed, Jul 3, 2019 at 9:03 AM wrote: > > > Send Flask mailing list submissions to > > flask at python.org > > > > To subscribe or unsubscribe via the World Wide Web, visit > > https://mail.python.org/mailman/listinfo/flask > > or, via email, send a message with subject or body 'help' to > > flask-request at python.org > > > > You can reach the person managing the list at > > flask-owner at python.org > > > > When replying, please edit your Subject line so it is more specific > > than "Re: Contents of Flask digest..." > > > > > > Today's Topics: > > > > 1. Re: Unable to set current_user.authenticated to True > > (Gergely Polonkai) > > > > > > ---------------------------------------------------------------------- > > > > Message: 1 > > Date: Tue, 2 Jul 2019 19:01:20 +0200 > > From: Gergely Polonkai > > To: Leni Kadali Mutungi > > Cc: flask > > Subject: Re: [Flask] Unable to set current_user.authenticated to True > > Message-ID: > > > zxtk3bMO+n-+-y3Q at mail.gmail.com> > > Content-Type: text/plain; charset="utf-8" > > > > Hello, > > > > I assume you are using Flask-Login (either directly or via another > > extension like Flask-Security). If this is the case, you can import > > login_user and call it like login_user(user). > > > > If that does not work, you may want to check if the user is active (ie. > not > > disabled), as it is the most common culprit when a user can?t be logged > in. > > > > Best, > > Gergely > > > > On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, > > wrote: > > > > > I think you mean to set it as `current_user.is_authenticated = True`. > > > > > > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > > > > Hello everyone, > > > > I am trying to toggle between "Sign in" and "Sign > > > > out" links using the current_user.is_authenticated variable such that > > > > when it returns False, the "Sign in" is displayed and when True the > > > > "Sign out" link is displayed. At some point in the login code I set > > > > current_user.authenticated = True. The thing is that by the I am > > > > successfully logged in and presented with the next view, it is the > > > > "Sign in" link that is still displayed. When I check > > > > current_user.is_authenticated, it returns False, even though I had > > > > explicitly set it to True. Please can anyone point out what I am > might > > > > be doing wrong? Here is my code: > > > > > > > > I have a base.html file that contains the "Sign in" and "Sign out" > > > > links that is extended by the other templates: > > > > > > > > > > > > > > > > > > > > {% block page_content %}{% endblock %} > > > > > > > > > > > > > > > > When the app first loads in the browser it displays a login form, > > > > login.html: > > > > > > > > {% extends "base.html" %} > > > > > > > > {% block content %} > > > > {% import "bootstrap/wtf.html" as wtf %} > > > > {% block title %}Flasky - Login{% endblock %} > > > > {% block page_content %} > > > > > > > >
> > > > {{ wtf.quick_form(form) }} > > > >
> > > > {% endblock %} > > > > {% endblock %} > > > > > > > > When a user logs in, it loads a template dashboard.html that displays > > > > a map. The top part looks like this: > > > > > > > > {% extends "base.html" %} > > > > > > > > {% block page_content %} > > > > > > > > > > > > Lagos Map > > > > > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > > > > > > > > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > > > crossorigin=""/> > > > > > > > > > > > > > > > href=" > > > > > > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > > " > > > > > > > /> > > > > > > > href=" > > > > > > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > > " > > > > > > > /> > > > > > > > > > > > > ... > > > > ... > > > > > > > > And these are the relevant routes: > > > > > > > > @app.route('/',methods=['GET','POST']) > > > > def index(): > > > > form = LoginForm() > > > > if form.validate_on_submit(): > > > > user = User.query.filter_by(email=form.email.data).first() > > > > if user is not None and > > > user.check_password(form.password.data): > > > > user.authenticated = True > > > > current_user = user > > > > db.session.add(current_user) > > > > db.session.commit() > > > > login_user(current_user, form.remember_me.data) > > > > return redirect(request.args.get('next') or > > > > url_for('dashboard')) > > > > flash('Invalid username or password.') > > > > return render_template('auth/login.html', form=form) > > > > > > > > @app.route('/dashboard') > > > > def dashboard(): > > > > return render_template("dashboard.html") > > > > > > > > Thank you for your time. > > > > > > > > _______________________________________________ > > > > Flask mailing list > > > > Flask at python.org > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > -- > > > -- Kind regards, > > > Leni Kadali Mutungi > > > > > > _______________________________________________ > > > Flask mailing list > > > Flask at python.org > > > https://mail.python.org/mailman/listinfo/flask > > > > > -------------- next part -------------- > > An HTML attachment was scrubbed... > > URL: < > > > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > > > > > > > ------------------------------ > > > > Subject: Digest Footer > > > > _______________________________________________ > > Flask mailing list > > Flask at python.org > > https://mail.python.org/mailman/listinfo/flask > > > > > > ------------------------------ > > > > End of Flask Digest, Vol 49, Issue 5 > > ************************************ > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/flask/attachments/20190703/c47bb246/attachment-0001.html > > > > ------------------------------ > > Message: 2 > Date: Thu, 4 Jul 2019 06:25:40 +0200 > From: Gergely Polonkai > To: "sidwoodstock ." > Cc: flask > Subject: Re: [Flask] Unable to set current_user.authenticated to True > Message-ID: > < > CACczBUJaj67qxPCEi9Tmjku42QDxDsuVLmEGQGuFaC2nndT7eA at mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > No, modifying current_user directly is not possible (at least it won?t > propagate outside the function). current_user is a proxy object that points > to the logged in user in the current request. If you assign a different > value to it, its proxy nature goes away which is definitely not what you > want: in extreme cases it might introduce security issues where users can > access each the data of other. > > On Wed, 3 Jul 2019, 18:19 sidwoodstock ., wrote: > > > Also, if Gergely's suggestion doesn't work, you could try removing your > > variable assignment of current_user = user. I see no practical reason to > do > > this, and since current_user is a built-in (and very handy) variable, > maybe > > that is somehow related to your issue? > > > > > > current_user = user > > > > and then just call login_user directly with your user you already have at > > hand: > > > > > > login_user(user, form.remember_me.data) > > > > -Scott > > > > On Wed, Jul 3, 2019 at 9:03 AM wrote: > > > >> Send Flask mailing list submissions to > >> flask at python.org > >> > >> To subscribe or unsubscribe via the World Wide Web, visit > >> https://mail.python.org/mailman/listinfo/flask > >> or, via email, send a message with subject or body 'help' to > >> flask-request at python.org > >> > >> You can reach the person managing the list at > >> flask-owner at python.org > >> > >> When replying, please edit your Subject line so it is more specific > >> than "Re: Contents of Flask digest..." > >> > >> > >> Today's Topics: > >> > >> 1. Re: Unable to set current_user.authenticated to True > >> (Gergely Polonkai) > >> > >> > >> ---------------------------------------------------------------------- > >> > >> Message: 1 > >> Date: Tue, 2 Jul 2019 19:01:20 +0200 > >> From: Gergely Polonkai > >> To: Leni Kadali Mutungi > >> Cc: flask > >> Subject: Re: [Flask] Unable to set current_user.authenticated to True > >> Message-ID: > >> >> zxtk3bMO+n-+-y3Q at mail.gmail.com> > >> Content-Type: text/plain; charset="utf-8" > >> > >> Hello, > >> > >> I assume you are using Flask-Login (either directly or via another > >> extension like Flask-Security). If this is the case, you can import > >> login_user and call it like login_user(user). > >> > >> If that does not work, you may want to check if the user is active (ie. > >> not > >> disabled), as it is the most common culprit when a user can?t be logged > >> in. > >> > >> Best, > >> Gergely > >> > >> On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, > >> wrote: > >> > >> > I think you mean to set it as `current_user.is_authenticated = True`. > >> > > >> > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > >> > > Hello everyone, > >> > > I am trying to toggle between "Sign in" and "Sign > >> > > out" links using the current_user.is_authenticated variable such > that > >> > > when it returns False, the "Sign in" is displayed and when True the > >> > > "Sign out" link is displayed. At some point in the login code I set > >> > > current_user.authenticated = True. The thing is that by the I am > >> > > successfully logged in and presented with the next view, it is the > >> > > "Sign in" link that is still displayed. When I check > >> > > current_user.is_authenticated, it returns False, even though I had > >> > > explicitly set it to True. Please can anyone point out what I am > might > >> > > be doing wrong? Here is my code: > >> > > > >> > > I have a base.html file that contains the "Sign in" and "Sign out" > >> > > links that is extended by the other templates: > >> > > > >> > > > >> > > > >> > > > >> > > {% block page_content %}{% endblock %} > >> > > > >> > > > >> > > > >> > > When the app first loads in the browser it displays a login form, > >> > > login.html: > >> > > > >> > > {% extends "base.html" %} > >> > > > >> > > {% block content %} > >> > > {% import "bootstrap/wtf.html" as wtf %} > >> > > {% block title %}Flasky - Login{% endblock %} > >> > > {% block page_content %} > >> > > > >> > >
> >> > > {{ wtf.quick_form(form) }} > >> > >
> >> > > {% endblock %} > >> > > {% endblock %} > >> > > > >> > > When a user logs in, it loads a template dashboard.html that > displays > >> > > a map. The top part looks like this: > >> > > > >> > > {% extends "base.html" %} > >> > > > >> > > {% block page_content %} > >> > > > >> > > > >> > > Lagos Map > >> > > >> > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > >> > > > >> > > >> > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > >> > > crossorigin=""/> > >> > > > >> > > > >> > > >> > > href=" > >> > > >> > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > >> " > >> > > >> > > /> > >> > > >> > > href=" > >> > > >> > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > >> " > >> > > >> > > /> > >> > > > >> > > > >> > > ... > >> > > ... > >> > > > >> > > And these are the relevant routes: > >> > > > >> > > @app.route('/',methods=['GET','POST']) > >> > > def index(): > >> > > form = LoginForm() > >> > > if form.validate_on_submit(): > >> > > user = User.query.filter_by(email=form.email.data).first() > >> > > if user is not None and > >> > user.check_password(form.password.data): > >> > > user.authenticated = True > >> > > current_user = user > >> > > db.session.add(current_user) > >> > > db.session.commit() > >> > > login_user(current_user, form.remember_me.data) > >> > > return redirect(request.args.get('next') or > >> > > url_for('dashboard')) > >> > > flash('Invalid username or password.') > >> > > return render_template('auth/login.html', form=form) > >> > > > >> > > @app.route('/dashboard') > >> > > def dashboard(): > >> > > return render_template("dashboard.html") > >> > > > >> > > Thank you for your time. > >> > > > >> > > _______________________________________________ > >> > > Flask mailing list > >> > > Flask at python.org > >> > > https://mail.python.org/mailman/listinfo/flask > >> > > >> > -- > >> > -- Kind regards, > >> > Leni Kadali Mutungi > >> > > >> > _______________________________________________ > >> > Flask mailing list > >> > Flask at python.org > >> > https://mail.python.org/mailman/listinfo/flask > >> > > >> -------------- next part -------------- > >> An HTML attachment was scrubbed... > >> URL: < > >> > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > >> > > >> > >> ------------------------------ > >> > >> Subject: Digest Footer > >> > >> _______________________________________________ > >> Flask mailing list > >> Flask at python.org > >> https://mail.python.org/mailman/listinfo/flask > >> > >> > >> ------------------------------ > >> > >> End of Flask Digest, Vol 49, Issue 5 > >> ************************************ > >> > > _______________________________________________ > > Flask mailing list > > Flask at python.org > > https://mail.python.org/mailman/listinfo/flask > > > > On Wed, 3 Jul 2019, 18:19 sidwoodstock ., wrote: > > > Also, if Gergely's suggestion doesn't work, you could try removing your > > variable assignment of current_user = user. I see no practical reason to > do > > this, and since current_user is a built-in (and very handy) variable, > maybe > > that is somehow related to your issue? > > > > > > current_user = user > > > > and then just call login_user directly with your user you already have at > > hand: > > > > > > login_user(user, form.remember_me.data) > > > > -Scott > > > > On Wed, Jul 3, 2019 at 9:03 AM wrote: > > > >> Send Flask mailing list submissions to > >> flask at python.org > >> > >> To subscribe or unsubscribe via the World Wide Web, visit > >> https://mail.python.org/mailman/listinfo/flask > >> or, via email, send a message with subject or body 'help' to > >> flask-request at python.org > >> > >> You can reach the person managing the list at > >> flask-owner at python.org > >> > >> When replying, please edit your Subject line so it is more specific > >> than "Re: Contents of Flask digest..." > >> > >> > >> Today's Topics: > >> > >> 1. Re: Unable to set current_user.authenticated to True > >> (Gergely Polonkai) > >> > >> > >> ---------------------------------------------------------------------- > >> > >> Message: 1 > >> Date: Tue, 2 Jul 2019 19:01:20 +0200 > >> From: Gergely Polonkai > >> To: Leni Kadali Mutungi > >> Cc: flask > >> Subject: Re: [Flask] Unable to set current_user.authenticated to True > >> Message-ID: > >> >> zxtk3bMO+n-+-y3Q at mail.gmail.com> > >> Content-Type: text/plain; charset="utf-8" > >> > >> Hello, > >> > >> I assume you are using Flask-Login (either directly or via another > >> extension like Flask-Security). If this is the case, you can import > >> login_user and call it like login_user(user). > >> > >> If that does not work, you may want to check if the user is active (ie. > >> not > >> disabled), as it is the most common culprit when a user can?t be logged > >> in. > >> > >> Best, > >> Gergely > >> > >> On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, > >> wrote: > >> > >> > I think you mean to set it as `current_user.is_authenticated = True`. > >> > > >> > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > >> > > Hello everyone, > >> > > I am trying to toggle between "Sign in" and "Sign > >> > > out" links using the current_user.is_authenticated variable such > that > >> > > when it returns False, the "Sign in" is displayed and when True the > >> > > "Sign out" link is displayed. At some point in the login code I set > >> > > current_user.authenticated = True. The thing is that by the I am > >> > > successfully logged in and presented with the next view, it is the > >> > > "Sign in" link that is still displayed. When I check > >> > > current_user.is_authenticated, it returns False, even though I had > >> > > explicitly set it to True. Please can anyone point out what I am > might > >> > > be doing wrong? Here is my code: > >> > > > >> > > I have a base.html file that contains the "Sign in" and "Sign out" > >> > > links that is extended by the other templates: > >> > > > >> > > > >> > > > >> > > > >> > > {% block page_content %}{% endblock %} > >> > > > >> > > > >> > > > >> > > When the app first loads in the browser it displays a login form, > >> > > login.html: > >> > > > >> > > {% extends "base.html" %} > >> > > > >> > > {% block content %} > >> > > {% import "bootstrap/wtf.html" as wtf %} > >> > > {% block title %}Flasky - Login{% endblock %} > >> > > {% block page_content %} > >> > > > >> > >
> >> > > {{ wtf.quick_form(form) }} > >> > >
> >> > > {% endblock %} > >> > > {% endblock %} > >> > > > >> > > When a user logs in, it loads a template dashboard.html that > displays > >> > > a map. The top part looks like this: > >> > > > >> > > {% extends "base.html" %} > >> > > > >> > > {% block page_content %} > >> > > > >> > > > >> > > Lagos Map > >> > > >> > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > >> > > > >> > > >> > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > >> > > crossorigin=""/> > >> > > > >> > > > >> > > >> > > href=" > >> > > >> > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > >> " > >> > > >> > > /> > >> > > >> > > href=" > >> > > >> > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > >> " > >> > > >> > > /> > >> > > > >> > > > >> > > ... > >> > > ... > >> > > > >> > > And these are the relevant routes: > >> > > > >> > > @app.route('/',methods=['GET','POST']) > >> > > def index(): > >> > > form = LoginForm() > >> > > if form.validate_on_submit(): > >> > > user = User.query.filter_by(email=form.email.data).first() > >> > > if user is not None and > >> > user.check_password(form.password.data): > >> > > user.authenticated = True > >> > > current_user = user > >> > > db.session.add(current_user) > >> > > db.session.commit() > >> > > login_user(current_user, form.remember_me.data) > >> > > return redirect(request.args.get('next') or > >> > > url_for('dashboard')) > >> > > flash('Invalid username or password.') > >> > > return render_template('auth/login.html', form=form) > >> > > > >> > > @app.route('/dashboard') > >> > > def dashboard(): > >> > > return render_template("dashboard.html") > >> > > > >> > > Thank you for your time. > >> > > > >> > > _______________________________________________ > >> > > Flask mailing list > >> > > Flask at python.org > >> > > https://mail.python.org/mailman/listinfo/flask > >> > > >> > -- > >> > -- Kind regards, > >> > Leni Kadali Mutungi > >> > > >> > _______________________________________________ > >> > Flask mailing list > >> > Flask at python.org > >> > https://mail.python.org/mailman/listinfo/flask > >> > > >> -------------- next part -------------- > >> An HTML attachment was scrubbed... > >> URL: < > >> > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > >> > > >> > >> ------------------------------ > >> > >> Subject: Digest Footer > >> > >> _______________________________________________ > >> Flask mailing list > >> Flask at python.org > >> https://mail.python.org/mailman/listinfo/flask > >> > >> > >> ------------------------------ > >> > >> End of Flask Digest, Vol 49, Issue 5 > >> ************************************ > >> > > _______________________________________________ > > Flask mailing list > > Flask at python.org > > https://mail.python.org/mailman/listinfo/flask > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/flask/attachments/20190704/055df8bc/attachment.html > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > > ------------------------------ > > End of Flask Digest, Vol 49, Issue 6 > ************************************ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sidwoodstock at gmail.com Thu Jul 4 14:50:45 2019 From: sidwoodstock at gmail.com (sidwoodstock .) Date: Thu, 4 Jul 2019 11:50:45 -0700 Subject: [Flask] Unable to set current_user.authenticated to True In-Reply-To: References: Message-ID: Ahh okay I understand now. I haven't tested this myself, but perhaps try {% if current_user %} as your conditional since it ought to return None if no one is logged in. -Scott On Thu, Jul 4, 2019 at 8:56 AM wrote: > Send Flask mailing list submissions to > flask at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/flask > or, via email, send a message with subject or body 'help' to > flask-request at python.org > > You can reach the person managing the list at > flask-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Flask digest..." > > > Today's Topics: > > 1. Re: Flask Digest, Vol 49, Issue 5 (Abdul Mohammed) > 2. Re: Flask Digest, Vol 49, Issue 6 (Abdul Mohammed) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Thu, 4 Jul 2019 16:22:42 +0100 > From: Abdul Mohammed > To: flask at python.org > Subject: Re: [Flask] Flask Digest, Vol 49, Issue 5 > Message-ID: > < > CAEKkz85XoPnseQ9_jF_0WcfKDruXLAKKCBp4+2k_FogNA8zVcQ at mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > Thanks Gergely for the response. > Yes I am using Flask-Login and I think directly because this is how I > import it: > > from flask_login import login_user > > My problem is not that I can't log in. I can log in fine. The problem is > essentially that I can not log out. I am trying to use the value of > current_user.is_authenticated to determine whether to show the "Sign in" or > "Sign out" link. If True, it shows "Sign out" and "Sign in" when False. > For some reason, the value remains False after I have logged in so the > "Sign out" link never displays and so I am trapped in the app (Please save > me!!!) > because I can't log out. I hope I have made my problems clearer. > > Regards > > On Wed, Jul 3, 2019 at 5:04 PM wrote: > > > Send Flask mailing list submissions to > > flask at python.org > > > > To subscribe or unsubscribe via the World Wide Web, visit > > https://mail.python.org/mailman/listinfo/flask > > or, via email, send a message with subject or body 'help' to > > flask-request at python.org > > > > You can reach the person managing the list at > > flask-owner at python.org > > > > When replying, please edit your Subject line so it is more specific > > than "Re: Contents of Flask digest..." > > > > > > Today's Topics: > > > > 1. Re: Unable to set current_user.authenticated to True > > (Gergely Polonkai) > > > > > > ---------------------------------------------------------------------- > > > > Message: 1 > > Date: Tue, 2 Jul 2019 19:01:20 +0200 > > From: Gergely Polonkai > > To: Leni Kadali Mutungi > > Cc: flask > > Subject: Re: [Flask] Unable to set current_user.authenticated to True > > Message-ID: > > > zxtk3bMO+n-+-y3Q at mail.gmail.com> > > Content-Type: text/plain; charset="utf-8" > > > > Hello, > > > > I assume you are using Flask-Login (either directly or via another > > extension like Flask-Security). If this is the case, you can import > > login_user and call it like login_user(user). > > > > If that does not work, you may want to check if the user is active (ie. > not > > disabled), as it is the most common culprit when a user can?t be logged > in. > > > > Best, > > Gergely > > > > On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, > > wrote: > > > > > I think you mean to set it as `current_user.is_authenticated = True`. > > > > > > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > > > > Hello everyone, > > > > I am trying to toggle between "Sign in" and "Sign > > > > out" links using the current_user.is_authenticated variable such that > > > > when it returns False, the "Sign in" is displayed and when True the > > > > "Sign out" link is displayed. At some point in the login code I set > > > > current_user.authenticated = True. The thing is that by the I am > > > > successfully logged in and presented with the next view, it is the > > > > "Sign in" link that is still displayed. When I check > > > > current_user.is_authenticated, it returns False, even though I had > > > > explicitly set it to True. Please can anyone point out what I am > might > > > > be doing wrong? Here is my code: > > > > > > > > I have a base.html file that contains the "Sign in" and "Sign out" > > > > links that is extended by the other templates: > > > > > > > > > > > > > > > > > > > > {% block page_content %}{% endblock %} > > > > > > > > > > > > > > > > When the app first loads in the browser it displays a login form, > > > > login.html: > > > > > > > > {% extends "base.html" %} > > > > > > > > {% block content %} > > > > {% import "bootstrap/wtf.html" as wtf %} > > > > {% block title %}Flasky - Login{% endblock %} > > > > {% block page_content %} > > > > > > > >
> > > > {{ wtf.quick_form(form) }} > > > >
> > > > {% endblock %} > > > > {% endblock %} > > > > > > > > When a user logs in, it loads a template dashboard.html that displays > > > > a map. The top part looks like this: > > > > > > > > {% extends "base.html" %} > > > > > > > > {% block page_content %} > > > > > > > > > > > > Lagos Map > > > > > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > > > > > > > > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > > > crossorigin=""/> > > > > > > > > > > > > > > > href=" > > > > > > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > > " > > > > > > > /> > > > > > > > href=" > > > > > > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > > " > > > > > > > /> > > > > > > > > > > > > ... > > > > ... > > > > > > > > And these are the relevant routes: > > > > > > > > @app.route('/',methods=['GET','POST']) > > > > def index(): > > > > form = LoginForm() > > > > if form.validate_on_submit(): > > > > user = User.query.filter_by(email=form.email.data).first() > > > > if user is not None and > > > user.check_password(form.password.data): > > > > user.authenticated = True > > > > current_user = user > > > > db.session.add(current_user) > > > > db.session.commit() > > > > login_user(current_user, form.remember_me.data) > > > > return redirect(request.args.get('next') or > > > > url_for('dashboard')) > > > > flash('Invalid username or password.') > > > > return render_template('auth/login.html', form=form) > > > > > > > > @app.route('/dashboard') > > > > def dashboard(): > > > > return render_template("dashboard.html") > > > > > > > > Thank you for your time. > > > > > > > > _______________________________________________ > > > > Flask mailing list > > > > Flask at python.org > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > -- > > > -- Kind regards, > > > Leni Kadali Mutungi > > > > > > _______________________________________________ > > > Flask mailing list > > > Flask at python.org > > > https://mail.python.org/mailman/listinfo/flask > > > > > -------------- next part -------------- > > An HTML attachment was scrubbed... > > URL: < > > > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > > > > > > > ------------------------------ > > > > Subject: Digest Footer > > > > _______________________________________________ > > Flask mailing list > > Flask at python.org > > https://mail.python.org/mailman/listinfo/flask > > > > > > ------------------------------ > > > > End of Flask Digest, Vol 49, Issue 5 > > ************************************ > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/flask/attachments/20190704/29797e8e/attachment-0001.html > > > > ------------------------------ > > Message: 2 > Date: Thu, 4 Jul 2019 16:55:18 +0100 > From: Abdul Mohammed > To: flask at python.org > Subject: Re: [Flask] Flask Digest, Vol 49, Issue 6 > Message-ID: > g at mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > Thanks Scott. > I just explained to Gergely that my problem is not logging in but getting > the value of current_user.is_authenticated to change to True so that I > can log out. I wasn't originally doing the current_user = user assignment. > I could log in with either current_user or user. When the value of > current_user.is_authenticated wouldn't change to True, I added it because i > was just trying to see whether it would solve my problem. I will get rid of > it > but the problem is likely to remain. > > On Thu, Jul 4, 2019 at 5:26 AM wrote: > > > Send Flask mailing list submissions to > > flask at python.org > > > > To subscribe or unsubscribe via the World Wide Web, visit > > https://mail.python.org/mailman/listinfo/flask > > or, via email, send a message with subject or body 'help' to > > flask-request at python.org > > > > You can reach the person managing the list at > > flask-owner at python.org > > > > When replying, please edit your Subject line so it is more specific > > than "Re: Contents of Flask digest..." > > > > > > Today's Topics: > > > > 1. Re: Unable to set current_user.authenticated to True > > (sidwoodstock .) > > 2. Re: Unable to set current_user.authenticated to True > > (Gergely Polonkai) > > > > > > ---------------------------------------------------------------------- > > > > Message: 1 > > Date: Wed, 3 Jul 2019 09:19:20 -0700 > > From: "sidwoodstock ." > > To: flask at python.org > > Subject: Re: [Flask] Unable to set current_user.authenticated to True > > Message-ID: > > > KV78LHGK2k8hA at mail.gmail.com> > > Content-Type: text/plain; charset="utf-8" > > > > Also, if Gergely's suggestion doesn't work, you could try removing your > > variable assignment of current_user = user. I see no practical reason to > do > > this, and since current_user is a built-in (and very handy) variable, > maybe > > that is somehow related to your issue? > > > > > > current_user = user > > > > and then just call login_user directly with your user you already have at > > hand: > > > > > > login_user(user, form.remember_me.data) > > > > -Scott > > > > On Wed, Jul 3, 2019 at 9:03 AM wrote: > > > > > Send Flask mailing list submissions to > > > flask at python.org > > > > > > To subscribe or unsubscribe via the World Wide Web, visit > > > https://mail.python.org/mailman/listinfo/flask > > > or, via email, send a message with subject or body 'help' to > > > flask-request at python.org > > > > > > You can reach the person managing the list at > > > flask-owner at python.org > > > > > > When replying, please edit your Subject line so it is more specific > > > than "Re: Contents of Flask digest..." > > > > > > > > > Today's Topics: > > > > > > 1. Re: Unable to set current_user.authenticated to True > > > (Gergely Polonkai) > > > > > > > > > ---------------------------------------------------------------------- > > > > > > Message: 1 > > > Date: Tue, 2 Jul 2019 19:01:20 +0200 > > > From: Gergely Polonkai > > > To: Leni Kadali Mutungi > > > Cc: flask > > > Subject: Re: [Flask] Unable to set current_user.authenticated to True > > > Message-ID: > > > > > zxtk3bMO+n-+-y3Q at mail.gmail.com> > > > Content-Type: text/plain; charset="utf-8" > > > > > > Hello, > > > > > > I assume you are using Flask-Login (either directly or via another > > > extension like Flask-Security). If this is the case, you can import > > > login_user and call it like login_user(user). > > > > > > If that does not work, you may want to check if the user is active (ie. > > not > > > disabled), as it is the most common culprit when a user can?t be logged > > in. > > > > > > Best, > > > Gergely > > > > > > On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, > > > > wrote: > > > > > > > I think you mean to set it as `current_user.is_authenticated = True`. > > > > > > > > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > > > > > Hello everyone, > > > > > I am trying to toggle between "Sign in" and "Sign > > > > > out" links using the current_user.is_authenticated variable such > that > > > > > when it returns False, the "Sign in" is displayed and when True the > > > > > "Sign out" link is displayed. At some point in the login code I set > > > > > current_user.authenticated = True. The thing is that by the I am > > > > > successfully logged in and presented with the next view, it is the > > > > > "Sign in" link that is still displayed. When I check > > > > > current_user.is_authenticated, it returns False, even though I had > > > > > explicitly set it to True. Please can anyone point out what I am > > might > > > > > be doing wrong? Here is my code: > > > > > > > > > > I have a base.html file that contains the "Sign in" and "Sign out" > > > > > links that is extended by the other templates: > > > > > > > > > > > > > > > > > > > > > > > > > {% block page_content %}{% endblock %} > > > > > > > > > > > > > > > > > > > > When the app first loads in the browser it displays a login form, > > > > > login.html: > > > > > > > > > > {% extends "base.html" %} > > > > > > > > > > {% block content %} > > > > > {% import "bootstrap/wtf.html" as wtf %} > > > > > {% block title %}Flasky - Login{% endblock %} > > > > > {% block page_content %} > > > > > > > > > >
> > > > > {{ wtf.quick_form(form) }} > > > > >
> > > > > {% endblock %} > > > > > {% endblock %} > > > > > > > > > > When a user logs in, it loads a template dashboard.html that > displays > > > > > a map. The top part looks like this: > > > > > > > > > > {% extends "base.html" %} > > > > > > > > > > {% block page_content %} > > > > > > > > > > > > > > > Lagos Map > > > > > > > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > > > > > > > > > > > > > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > > > > crossorigin=""/> > > > > > > > > > > > > > > > > > > > href=" > > > > > > > > > > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > > > " > > > > > > > > > /> > > > > > > > > > href=" > > > > > > > > > > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > > > " > > > > > > > > > /> > > > > > > > > > > > > > > > ... > > > > > ... > > > > > > > > > > And these are the relevant routes: > > > > > > > > > > @app.route('/',methods=['GET','POST']) > > > > > def index(): > > > > > form = LoginForm() > > > > > if form.validate_on_submit(): > > > > > user = > User.query.filter_by(email=form.email.data).first() > > > > > if user is not None and > > > > user.check_password(form.password.data): > > > > > user.authenticated = True > > > > > current_user = user > > > > > db.session.add(current_user) > > > > > db.session.commit() > > > > > login_user(current_user, form.remember_me.data) > > > > > return redirect(request.args.get('next') or > > > > > url_for('dashboard')) > > > > > flash('Invalid username or password.') > > > > > return render_template('auth/login.html', form=form) > > > > > > > > > > @app.route('/dashboard') > > > > > def dashboard(): > > > > > return render_template("dashboard.html") > > > > > > > > > > Thank you for your time. > > > > > > > > > > _______________________________________________ > > > > > Flask mailing list > > > > > Flask at python.org > > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > > -- > > > > -- Kind regards, > > > > Leni Kadali Mutungi > > > > > > > > _______________________________________________ > > > > Flask mailing list > > > > Flask at python.org > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > -------------- next part -------------- > > > An HTML attachment was scrubbed... > > > URL: < > > > > > > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > > > > > > > > > > ------------------------------ > > > > > > Subject: Digest Footer > > > > > > _______________________________________________ > > > Flask mailing list > > > Flask at python.org > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > > > ------------------------------ > > > > > > End of Flask Digest, Vol 49, Issue 5 > > > ************************************ > > > > > -------------- next part -------------- > > An HTML attachment was scrubbed... > > URL: < > > > http://mail.python.org/pipermail/flask/attachments/20190703/c47bb246/attachment-0001.html > > > > > > > ------------------------------ > > > > Message: 2 > > Date: Thu, 4 Jul 2019 06:25:40 +0200 > > From: Gergely Polonkai > > To: "sidwoodstock ." > > Cc: flask > > Subject: Re: [Flask] Unable to set current_user.authenticated to True > > Message-ID: > > < > > CACczBUJaj67qxPCEi9Tmjku42QDxDsuVLmEGQGuFaC2nndT7eA at mail.gmail.com> > > Content-Type: text/plain; charset="utf-8" > > > > No, modifying current_user directly is not possible (at least it won?t > > propagate outside the function). current_user is a proxy object that > points > > to the logged in user in the current request. If you assign a different > > value to it, its proxy nature goes away which is definitely not what you > > want: in extreme cases it might introduce security issues where users can > > access each the data of other. > > > > On Wed, 3 Jul 2019, 18:19 sidwoodstock ., > wrote: > > > > > Also, if Gergely's suggestion doesn't work, you could try removing your > > > variable assignment of current_user = user. I see no practical reason > to > > do > > > this, and since current_user is a built-in (and very handy) variable, > > maybe > > > that is somehow related to your issue? > > > > > > > > current_user = user > > > > > > and then just call login_user directly with your user you already have > at > > > hand: > > > > > > > > login_user(user, form.remember_me.data) > > > > > > -Scott > > > > > > On Wed, Jul 3, 2019 at 9:03 AM wrote: > > > > > >> Send Flask mailing list submissions to > > >> flask at python.org > > >> > > >> To subscribe or unsubscribe via the World Wide Web, visit > > >> https://mail.python.org/mailman/listinfo/flask > > >> or, via email, send a message with subject or body 'help' to > > >> flask-request at python.org > > >> > > >> You can reach the person managing the list at > > >> flask-owner at python.org > > >> > > >> When replying, please edit your Subject line so it is more specific > > >> than "Re: Contents of Flask digest..." > > >> > > >> > > >> Today's Topics: > > >> > > >> 1. Re: Unable to set current_user.authenticated to True > > >> (Gergely Polonkai) > > >> > > >> > > >> ---------------------------------------------------------------------- > > >> > > >> Message: 1 > > >> Date: Tue, 2 Jul 2019 19:01:20 +0200 > > >> From: Gergely Polonkai > > >> To: Leni Kadali Mutungi > > >> Cc: flask > > >> Subject: Re: [Flask] Unable to set current_user.authenticated to True > > >> Message-ID: > > >> > >> zxtk3bMO+n-+-y3Q at mail.gmail.com> > > >> Content-Type: text/plain; charset="utf-8" > > >> > > >> Hello, > > >> > > >> I assume you are using Flask-Login (either directly or via another > > >> extension like Flask-Security). If this is the case, you can import > > >> login_user and call it like login_user(user). > > >> > > >> If that does not work, you may want to check if the user is active > (ie. > > >> not > > >> disabled), as it is the most common culprit when a user can?t be > logged > > >> in. > > >> > > >> Best, > > >> Gergely > > >> > > >> On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < > lenikmutungi at gmail.com> > > >> wrote: > > >> > > >> > I think you mean to set it as `current_user.is_authenticated = > True`. > > >> > > > >> > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > > >> > > Hello everyone, > > >> > > I am trying to toggle between "Sign in" and > "Sign > > >> > > out" links using the current_user.is_authenticated variable such > > that > > >> > > when it returns False, the "Sign in" is displayed and when True > the > > >> > > "Sign out" link is displayed. At some point in the login code I > set > > >> > > current_user.authenticated = True. The thing is that by the I am > > >> > > successfully logged in and presented with the next view, it is the > > >> > > "Sign in" link that is still displayed. When I check > > >> > > current_user.is_authenticated, it returns False, even though I had > > >> > > explicitly set it to True. Please can anyone point out what I am > > might > > >> > > be doing wrong? Here is my code: > > >> > > > > >> > > I have a base.html file that contains the "Sign in" and "Sign out" > > >> > > links that is extended by the other templates: > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > {% block page_content %}{% endblock %} > > >> > > > > >> > > > > >> > > > > >> > > When the app first loads in the browser it displays a login form, > > >> > > login.html: > > >> > > > > >> > > {% extends "base.html" %} > > >> > > > > >> > > {% block content %} > > >> > > {% import "bootstrap/wtf.html" as wtf %} > > >> > > {% block title %}Flasky - Login{% endblock %} > > >> > > {% block page_content %} > > >> > > > > >> > >
> > >> > > {{ wtf.quick_form(form) }} > > >> > >
> > >> > > {% endblock %} > > >> > > {% endblock %} > > >> > > > > >> > > When a user logs in, it loads a template dashboard.html that > > displays > > >> > > a map. The top part looks like this: > > >> > > > > >> > > {% extends "base.html" %} > > >> > > > > >> > > {% block page_content %} > > >> > > > > >> > > > > >> > > Lagos Map > > >> > > > >> > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > > >> > > > > >> > > > >> > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > >> > > crossorigin=""/> > > >> > > > > >> > > > > >> > > > >> > > href=" > > >> > > > >> > > > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > > >> " > > >> > > > >> > > /> > > >> > > > >> > > href=" > > >> > > > >> > > > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > > >> " > > >> > > > >> > > /> > > >> > > > > >> > > > > >> > > ... > > >> > > ... > > >> > > > > >> > > And these are the relevant routes: > > >> > > > > >> > > @app.route('/',methods=['GET','POST']) > > >> > > def index(): > > >> > > form = LoginForm() > > >> > > if form.validate_on_submit(): > > >> > > user = > User.query.filter_by(email=form.email.data).first() > > >> > > if user is not None and > > >> > user.check_password(form.password.data): > > >> > > user.authenticated = True > > >> > > current_user = user > > >> > > db.session.add(current_user) > > >> > > db.session.commit() > > >> > > login_user(current_user, form.remember_me.data) > > >> > > return redirect(request.args.get('next') or > > >> > > url_for('dashboard')) > > >> > > flash('Invalid username or password.') > > >> > > return render_template('auth/login.html', form=form) > > >> > > > > >> > > @app.route('/dashboard') > > >> > > def dashboard(): > > >> > > return render_template("dashboard.html") > > >> > > > > >> > > Thank you for your time. > > >> > > > > >> > > _______________________________________________ > > >> > > Flask mailing list > > >> > > Flask at python.org > > >> > > https://mail.python.org/mailman/listinfo/flask > > >> > > > >> > -- > > >> > -- Kind regards, > > >> > Leni Kadali Mutungi > > >> > > > >> > _______________________________________________ > > >> > Flask mailing list > > >> > Flask at python.org > > >> > https://mail.python.org/mailman/listinfo/flask > > >> > > > >> -------------- next part -------------- > > >> An HTML attachment was scrubbed... > > >> URL: < > > >> > > > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > > >> > > > >> > > >> ------------------------------ > > >> > > >> Subject: Digest Footer > > >> > > >> _______________________________________________ > > >> Flask mailing list > > >> Flask at python.org > > >> https://mail.python.org/mailman/listinfo/flask > > >> > > >> > > >> ------------------------------ > > >> > > >> End of Flask Digest, Vol 49, Issue 5 > > >> ************************************ > > >> > > > _______________________________________________ > > > Flask mailing list > > > Flask at python.org > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > On Wed, 3 Jul 2019, 18:19 sidwoodstock ., > wrote: > > > > > Also, if Gergely's suggestion doesn't work, you could try removing your > > > variable assignment of current_user = user. I see no practical reason > to > > do > > > this, and since current_user is a built-in (and very handy) variable, > > maybe > > > that is somehow related to your issue? > > > > > > > > current_user = user > > > > > > and then just call login_user directly with your user you already have > at > > > hand: > > > > > > > > login_user(user, form.remember_me.data) > > > > > > -Scott > > > > > > On Wed, Jul 3, 2019 at 9:03 AM wrote: > > > > > >> Send Flask mailing list submissions to > > >> flask at python.org > > >> > > >> To subscribe or unsubscribe via the World Wide Web, visit > > >> https://mail.python.org/mailman/listinfo/flask > > >> or, via email, send a message with subject or body 'help' to > > >> flask-request at python.org > > >> > > >> You can reach the person managing the list at > > >> flask-owner at python.org > > >> > > >> When replying, please edit your Subject line so it is more specific > > >> than "Re: Contents of Flask digest..." > > >> > > >> > > >> Today's Topics: > > >> > > >> 1. Re: Unable to set current_user.authenticated to True > > >> (Gergely Polonkai) > > >> > > >> > > >> ---------------------------------------------------------------------- > > >> > > >> Message: 1 > > >> Date: Tue, 2 Jul 2019 19:01:20 +0200 > > >> From: Gergely Polonkai > > >> To: Leni Kadali Mutungi > > >> Cc: flask > > >> Subject: Re: [Flask] Unable to set current_user.authenticated to True > > >> Message-ID: > > >> > >> zxtk3bMO+n-+-y3Q at mail.gmail.com> > > >> Content-Type: text/plain; charset="utf-8" > > >> > > >> Hello, > > >> > > >> I assume you are using Flask-Login (either directly or via another > > >> extension like Flask-Security). If this is the case, you can import > > >> login_user and call it like login_user(user). > > >> > > >> If that does not work, you may want to check if the user is active > (ie. > > >> not > > >> disabled), as it is the most common culprit when a user can?t be > logged > > >> in. > > >> > > >> Best, > > >> Gergely > > >> > > >> On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < > lenikmutungi at gmail.com> > > >> wrote: > > >> > > >> > I think you mean to set it as `current_user.is_authenticated = > True`. > > >> > > > >> > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > > >> > > Hello everyone, > > >> > > I am trying to toggle between "Sign in" and > "Sign > > >> > > out" links using the current_user.is_authenticated variable such > > that > > >> > > when it returns False, the "Sign in" is displayed and when True > the > > >> > > "Sign out" link is displayed. At some point in the login code I > set > > >> > > current_user.authenticated = True. The thing is that by the I am > > >> > > successfully logged in and presented with the next view, it is the > > >> > > "Sign in" link that is still displayed. When I check > > >> > > current_user.is_authenticated, it returns False, even though I had > > >> > > explicitly set it to True. Please can anyone point out what I am > > might > > >> > > be doing wrong? Here is my code: > > >> > > > > >> > > I have a base.html file that contains the "Sign in" and "Sign out" > > >> > > links that is extended by the other templates: > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > {% block page_content %}{% endblock %} > > >> > > > > >> > > > > >> > > > > >> > > When the app first loads in the browser it displays a login form, > > >> > > login.html: > > >> > > > > >> > > {% extends "base.html" %} > > >> > > > > >> > > {% block content %} > > >> > > {% import "bootstrap/wtf.html" as wtf %} > > >> > > {% block title %}Flasky - Login{% endblock %} > > >> > > {% block page_content %} > > >> > > > > >> > >
> > >> > > {{ wtf.quick_form(form) }} > > >> > >
> > >> > > {% endblock %} > > >> > > {% endblock %} > > >> > > > > >> > > When a user logs in, it loads a template dashboard.html that > > displays > > >> > > a map. The top part looks like this: > > >> > > > > >> > > {% extends "base.html" %} > > >> > > > > >> > > {% block page_content %} > > >> > > > > >> > > > > >> > > Lagos Map > > >> > > > >> > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > > >> > > > > >> > > > >> > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > >> > > crossorigin=""/> > > >> > > > > >> > > > > >> > > > >> > > href=" > > >> > > > >> > > > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > > >> " > > >> > > > >> > > /> > > >> > > > >> > > href=" > > >> > > > >> > > > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > > >> " > > >> > > > >> > > /> > > >> > > > > >> > > > > >> > > ... > > >> > > ... > > >> > > > > >> > > And these are the relevant routes: > > >> > > > > >> > > @app.route('/',methods=['GET','POST']) > > >> > > def index(): > > >> > > form = LoginForm() > > >> > > if form.validate_on_submit(): > > >> > > user = > User.query.filter_by(email=form.email.data).first() > > >> > > if user is not None and > > >> > user.check_password(form.password.data): > > >> > > user.authenticated = True > > >> > > current_user = user > > >> > > db.session.add(current_user) > > >> > > db.session.commit() > > >> > > login_user(current_user, form.remember_me.data) > > >> > > return redirect(request.args.get('next') or > > >> > > url_for('dashboard')) > > >> > > flash('Invalid username or password.') > > >> > > return render_template('auth/login.html', form=form) > > >> > > > > >> > > @app.route('/dashboard') > > >> > > def dashboard(): > > >> > > return render_template("dashboard.html") > > >> > > > > >> > > Thank you for your time. > > >> > > > > >> > > _______________________________________________ > > >> > > Flask mailing list > > >> > > Flask at python.org > > >> > > https://mail.python.org/mailman/listinfo/flask > > >> > > > >> > -- > > >> > -- Kind regards, > > >> > Leni Kadali Mutungi > > >> > > > >> > _______________________________________________ > > >> > Flask mailing list > > >> > Flask at python.org > > >> > https://mail.python.org/mailman/listinfo/flask > > >> > > > >> -------------- next part -------------- > > >> An HTML attachment was scrubbed... > > >> URL: < > > >> > > > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > > >> > > > >> > > >> ------------------------------ > > >> > > >> Subject: Digest Footer > > >> > > >> _______________________________________________ > > >> Flask mailing list > > >> Flask at python.org > > >> https://mail.python.org/mailman/listinfo/flask > > >> > > >> > > >> ------------------------------ > > >> > > >> End of Flask Digest, Vol 49, Issue 5 > > >> ************************************ > > >> > > > _______________________________________________ > > > Flask mailing list > > > Flask at python.org > > > https://mail.python.org/mailman/listinfo/flask > > > > > -------------- next part -------------- > > An HTML attachment was scrubbed... > > URL: < > > > http://mail.python.org/pipermail/flask/attachments/20190704/055df8bc/attachment.html > > > > > > > ------------------------------ > > > > Subject: Digest Footer > > > > _______________________________________________ > > Flask mailing list > > Flask at python.org > > https://mail.python.org/mailman/listinfo/flask > > > > > > ------------------------------ > > > > End of Flask Digest, Vol 49, Issue 6 > > ************************************ > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/flask/attachments/20190704/89bc8e49/attachment.html > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > > ------------------------------ > > End of Flask Digest, Vol 49, Issue 7 > ************************************ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gergely at polonkai.eu Fri Jul 5 03:33:57 2019 From: gergely at polonkai.eu (Gergely Polonkai) Date: Fri, 5 Jul 2019 07:33:57 +0000 Subject: [Flask] Unable to set current_user.authenticated to True In-Reply-To: References: Message-ID: The whole problem is that UserMixin.is_authenticated is a bit counterintuitive as, by default, it always returns True. Contrast that with AnonymousUserMixin.is_authenticated, which always returns False. So to check if someone is logged in with login_user, check if current_user.is_authenticated is True. When no one is logged in, current_user returns AnonymousUser; if someone is logged in, current_user returns a User object. Thus, if current_user is still a User object after calling logout_user, that?s a bug somewhere. In this case it would be helpful if you could share a minimum working (well, in this case *not* working) example with us to see where the problem is. Best, Gergely Gergely Polonkai [image: https://]about.me/gergely.polonkai fim., 4. j?l. 2019 kl. 18:51 skrifa?i sidwoodstock . : > Ahh okay I understand now. > > I haven't tested this myself, but perhaps try {% if current_user %} as > your conditional since it ought to return None if no one is logged in. > > -Scott > > On Thu, Jul 4, 2019 at 8:56 AM wrote: > >> Send Flask mailing list submissions to >> flask at python.org >> >> To subscribe or unsubscribe via the World Wide Web, visit >> https://mail.python.org/mailman/listinfo/flask >> or, via email, send a message with subject or body 'help' to >> flask-request at python.org >> >> You can reach the person managing the list at >> flask-owner at python.org >> >> When replying, please edit your Subject line so it is more specific >> than "Re: Contents of Flask digest..." >> >> >> Today's Topics: >> >> 1. Re: Flask Digest, Vol 49, Issue 5 (Abdul Mohammed) >> 2. Re: Flask Digest, Vol 49, Issue 6 (Abdul Mohammed) >> >> >> ---------------------------------------------------------------------- >> >> Message: 1 >> Date: Thu, 4 Jul 2019 16:22:42 +0100 >> From: Abdul Mohammed >> To: flask at python.org >> Subject: Re: [Flask] Flask Digest, Vol 49, Issue 5 >> Message-ID: >> < >> CAEKkz85XoPnseQ9_jF_0WcfKDruXLAKKCBp4+2k_FogNA8zVcQ at mail.gmail.com> >> Content-Type: text/plain; charset="utf-8" >> >> Thanks Gergely for the response. >> Yes I am using Flask-Login and I think directly because this is how I >> import it: >> >> from flask_login import login_user >> >> My problem is not that I can't log in. I can log in fine. The problem is >> essentially that I can not log out. I am trying to use the value of >> current_user.is_authenticated to determine whether to show the "Sign in" >> or >> "Sign out" link. If True, it shows "Sign out" and "Sign in" when False. >> For some reason, the value remains False after I have logged in so the >> "Sign out" link never displays and so I am trapped in the app (Please save >> me!!!) >> because I can't log out. I hope I have made my problems clearer. >> >> Regards >> >> On Wed, Jul 3, 2019 at 5:04 PM wrote: >> >> > Send Flask mailing list submissions to >> > flask at python.org >> > >> > To subscribe or unsubscribe via the World Wide Web, visit >> > https://mail.python.org/mailman/listinfo/flask >> > or, via email, send a message with subject or body 'help' to >> > flask-request at python.org >> > >> > You can reach the person managing the list at >> > flask-owner at python.org >> > >> > When replying, please edit your Subject line so it is more specific >> > than "Re: Contents of Flask digest..." >> > >> > >> > Today's Topics: >> > >> > 1. Re: Unable to set current_user.authenticated to True >> > (Gergely Polonkai) >> > >> > >> > ---------------------------------------------------------------------- >> > >> > Message: 1 >> > Date: Tue, 2 Jul 2019 19:01:20 +0200 >> > From: Gergely Polonkai >> > To: Leni Kadali Mutungi >> > Cc: flask >> > Subject: Re: [Flask] Unable to set current_user.authenticated to True >> > Message-ID: >> > > > zxtk3bMO+n-+-y3Q at mail.gmail.com> >> > Content-Type: text/plain; charset="utf-8" >> > >> > Hello, >> > >> > I assume you are using Flask-Login (either directly or via another >> > extension like Flask-Security). If this is the case, you can import >> > login_user and call it like login_user(user). >> > >> > If that does not work, you may want to check if the user is active (ie. >> not >> > disabled), as it is the most common culprit when a user can?t be logged >> in. >> > >> > Best, >> > Gergely >> > >> > On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, >> > wrote: >> > >> > > I think you mean to set it as `current_user.is_authenticated = True`. >> > > >> > > On 7/1/19 6:14 PM, Abdul Mohammed wrote: >> > > > Hello everyone, >> > > > I am trying to toggle between "Sign in" and "Sign >> > > > out" links using the current_user.is_authenticated variable such >> that >> > > > when it returns False, the "Sign in" is displayed and when True the >> > > > "Sign out" link is displayed. At some point in the login code I set >> > > > current_user.authenticated = True. The thing is that by the I am >> > > > successfully logged in and presented with the next view, it is the >> > > > "Sign in" link that is still displayed. When I check >> > > > current_user.is_authenticated, it returns False, even though I had >> > > > explicitly set it to True. Please can anyone point out what I am >> might >> > > > be doing wrong? Here is my code: >> > > > >> > > > I have a base.html file that contains the "Sign in" and "Sign out" >> > > > links that is extended by the other templates: >> > > > >> > > > >> > > > >> > > > >> > > > {% block page_content %}{% endblock %} >> > > > >> > > > >> > > > >> > > > When the app first loads in the browser it displays a login form, >> > > > login.html: >> > > > >> > > > {% extends "base.html" %} >> > > > >> > > > {% block content %} >> > > > {% import "bootstrap/wtf.html" as wtf %} >> > > > {% block title %}Flasky - Login{% endblock %} >> > > > {% block page_content %} >> > > > >> > > >
>> > > > {{ wtf.quick_form(form) }} >> > > >
>> > > > {% endblock %} >> > > > {% endblock %} >> > > > >> > > > When a user logs in, it loads a template dashboard.html that >> displays >> > > > a map. The top part looks like this: >> > > > >> > > > {% extends "base.html" %} >> > > > >> > > > {% block page_content %} >> > > > >> > > > >> > > > Lagos Map >> > > > > > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" >> > > > >> > > >> > >> integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" >> > > > crossorigin=""/> >> > > > >> > > > >> > > > > > > > href=" >> > > >> > >> https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css >> > " >> > > >> > > > /> >> > > > > > > > href=" >> > > >> > >> https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css >> > " >> > > >> > > > /> >> > > > >> > > > >> > > > ... >> > > > ... >> > > > >> > > > And these are the relevant routes: >> > > > >> > > > @app.route('/',methods=['GET','POST']) >> > > > def index(): >> > > > form = LoginForm() >> > > > if form.validate_on_submit(): >> > > > user = User.query.filter_by(email=form.email.data).first() >> > > > if user is not None and >> > > user.check_password(form.password.data): >> > > > user.authenticated = True >> > > > current_user = user >> > > > db.session.add(current_user) >> > > > db.session.commit() >> > > > login_user(current_user, form.remember_me.data) >> > > > return redirect(request.args.get('next') or >> > > > url_for('dashboard')) >> > > > flash('Invalid username or password.') >> > > > return render_template('auth/login.html', form=form) >> > > > >> > > > @app.route('/dashboard') >> > > > def dashboard(): >> > > > return render_template("dashboard.html") >> > > > >> > > > Thank you for your time. >> > > > >> > > > _______________________________________________ >> > > > Flask mailing list >> > > > Flask at python.org >> > > > https://mail.python.org/mailman/listinfo/flask >> > > >> > > -- >> > > -- Kind regards, >> > > Leni Kadali Mutungi >> > > >> > > _______________________________________________ >> > > Flask mailing list >> > > Flask at python.org >> > > https://mail.python.org/mailman/listinfo/flask >> > > >> > -------------- next part -------------- >> > An HTML attachment was scrubbed... >> > URL: < >> > >> http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html >> > > >> > >> > ------------------------------ >> > >> > Subject: Digest Footer >> > >> > _______________________________________________ >> > Flask mailing list >> > Flask at python.org >> > https://mail.python.org/mailman/listinfo/flask >> > >> > >> > ------------------------------ >> > >> > End of Flask Digest, Vol 49, Issue 5 >> > ************************************ >> > >> -------------- next part -------------- >> An HTML attachment was scrubbed... >> URL: < >> http://mail.python.org/pipermail/flask/attachments/20190704/29797e8e/attachment-0001.html >> > >> >> ------------------------------ >> >> Message: 2 >> Date: Thu, 4 Jul 2019 16:55:18 +0100 >> From: Abdul Mohammed >> To: flask at python.org >> Subject: Re: [Flask] Flask Digest, Vol 49, Issue 6 >> Message-ID: >> > g at mail.gmail.com> >> Content-Type: text/plain; charset="utf-8" >> >> Thanks Scott. >> I just explained to Gergely that my problem is not logging in but getting >> the value of current_user.is_authenticated to change to True so that I >> can log out. I wasn't originally doing the current_user = user assignment. >> I could log in with either current_user or user. When the value of >> current_user.is_authenticated wouldn't change to True, I added it because >> i >> was just trying to see whether it would solve my problem. I will get rid >> of >> it >> but the problem is likely to remain. >> >> On Thu, Jul 4, 2019 at 5:26 AM wrote: >> >> > Send Flask mailing list submissions to >> > flask at python.org >> > >> > To subscribe or unsubscribe via the World Wide Web, visit >> > https://mail.python.org/mailman/listinfo/flask >> > or, via email, send a message with subject or body 'help' to >> > flask-request at python.org >> > >> > You can reach the person managing the list at >> > flask-owner at python.org >> > >> > When replying, please edit your Subject line so it is more specific >> > than "Re: Contents of Flask digest..." >> > >> > >> > Today's Topics: >> > >> > 1. Re: Unable to set current_user.authenticated to True >> > (sidwoodstock .) >> > 2. Re: Unable to set current_user.authenticated to True >> > (Gergely Polonkai) >> > >> > >> > ---------------------------------------------------------------------- >> > >> > Message: 1 >> > Date: Wed, 3 Jul 2019 09:19:20 -0700 >> > From: "sidwoodstock ." >> > To: flask at python.org >> > Subject: Re: [Flask] Unable to set current_user.authenticated to True >> > Message-ID: >> > > > KV78LHGK2k8hA at mail.gmail.com> >> > Content-Type: text/plain; charset="utf-8" >> > >> > Also, if Gergely's suggestion doesn't work, you could try removing your >> > variable assignment of current_user = user. I see no practical reason >> to do >> > this, and since current_user is a built-in (and very handy) variable, >> maybe >> > that is somehow related to your issue? >> > >> > > > current_user = user >> > >> > and then just call login_user directly with your user you already have >> at >> > hand: >> > >> > > > login_user(user, form.remember_me.data) >> > >> > -Scott >> > >> > On Wed, Jul 3, 2019 at 9:03 AM wrote: >> > >> > > Send Flask mailing list submissions to >> > > flask at python.org >> > > >> > > To subscribe or unsubscribe via the World Wide Web, visit >> > > https://mail.python.org/mailman/listinfo/flask >> > > or, via email, send a message with subject or body 'help' to >> > > flask-request at python.org >> > > >> > > You can reach the person managing the list at >> > > flask-owner at python.org >> > > >> > > When replying, please edit your Subject line so it is more specific >> > > than "Re: Contents of Flask digest..." >> > > >> > > >> > > Today's Topics: >> > > >> > > 1. Re: Unable to set current_user.authenticated to True >> > > (Gergely Polonkai) >> > > >> > > >> > > ---------------------------------------------------------------------- >> > > >> > > Message: 1 >> > > Date: Tue, 2 Jul 2019 19:01:20 +0200 >> > > From: Gergely Polonkai >> > > To: Leni Kadali Mutungi >> > > Cc: flask >> > > Subject: Re: [Flask] Unable to set current_user.authenticated to True >> > > Message-ID: >> > > > > > zxtk3bMO+n-+-y3Q at mail.gmail.com> >> > > Content-Type: text/plain; charset="utf-8" >> > > >> > > Hello, >> > > >> > > I assume you are using Flask-Login (either directly or via another >> > > extension like Flask-Security). If this is the case, you can import >> > > login_user and call it like login_user(user). >> > > >> > > If that does not work, you may want to check if the user is active >> (ie. >> > not >> > > disabled), as it is the most common culprit when a user can?t be >> logged >> > in. >> > > >> > > Best, >> > > Gergely >> > > >> > > On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < >> lenikmutungi at gmail.com> >> > > wrote: >> > > >> > > > I think you mean to set it as `current_user.is_authenticated = >> True`. >> > > > >> > > > On 7/1/19 6:14 PM, Abdul Mohammed wrote: >> > > > > Hello everyone, >> > > > > I am trying to toggle between "Sign in" and >> "Sign >> > > > > out" links using the current_user.is_authenticated variable such >> that >> > > > > when it returns False, the "Sign in" is displayed and when True >> the >> > > > > "Sign out" link is displayed. At some point in the login code I >> set >> > > > > current_user.authenticated = True. The thing is that by the I am >> > > > > successfully logged in and presented with the next view, it is the >> > > > > "Sign in" link that is still displayed. When I check >> > > > > current_user.is_authenticated, it returns False, even though I had >> > > > > explicitly set it to True. Please can anyone point out what I am >> > might >> > > > > be doing wrong? Here is my code: >> > > > > >> > > > > I have a base.html file that contains the "Sign in" and "Sign out" >> > > > > links that is extended by the other templates: >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > {% block page_content %}{% endblock %} >> > > > > >> > > > > >> > > > > >> > > > > When the app first loads in the browser it displays a login form, >> > > > > login.html: >> > > > > >> > > > > {% extends "base.html" %} >> > > > > >> > > > > {% block content %} >> > > > > {% import "bootstrap/wtf.html" as wtf %} >> > > > > {% block title %}Flasky - Login{% endblock %} >> > > > > {% block page_content %} >> > > > > >> > > > >
>> > > > > {{ wtf.quick_form(form) }} >> > > > >
>> > > > > {% endblock %} >> > > > > {% endblock %} >> > > > > >> > > > > When a user logs in, it loads a template dashboard.html that >> displays >> > > > > a map. The top part looks like this: >> > > > > >> > > > > {% extends "base.html" %} >> > > > > >> > > > > {% block page_content %} >> > > > > >> > > > > >> > > > > Lagos Map >> > > > > > > > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" >> > > > > >> > > > >> > > >> > >> integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" >> > > > > crossorigin=""/> >> > > > > >> > > > > >> > > > > > > > > > href=" >> > > > >> > > >> > >> https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css >> > > " >> > > > >> > > > > /> >> > > > > > > > > > href=" >> > > > >> > > >> > >> https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css >> > > " >> > > > >> > > > > /> >> > > > > >> > > > > >> > > > > ... >> > > > > ... >> > > > > >> > > > > And these are the relevant routes: >> > > > > >> > > > > @app.route('/',methods=['GET','POST']) >> > > > > def index(): >> > > > > form = LoginForm() >> > > > > if form.validate_on_submit(): >> > > > > user = >> User.query.filter_by(email=form.email.data).first() >> > > > > if user is not None and >> > > > user.check_password(form.password.data): >> > > > > user.authenticated = True >> > > > > current_user = user >> > > > > db.session.add(current_user) >> > > > > db.session.commit() >> > > > > login_user(current_user, form.remember_me.data) >> > > > > return redirect(request.args.get('next') or >> > > > > url_for('dashboard')) >> > > > > flash('Invalid username or password.') >> > > > > return render_template('auth/login.html', form=form) >> > > > > >> > > > > @app.route('/dashboard') >> > > > > def dashboard(): >> > > > > return render_template("dashboard.html") >> > > > > >> > > > > Thank you for your time. >> > > > > >> > > > > _______________________________________________ >> > > > > Flask mailing list >> > > > > Flask at python.org >> > > > > https://mail.python.org/mailman/listinfo/flask >> > > > >> > > > -- >> > > > -- Kind regards, >> > > > Leni Kadali Mutungi >> > > > >> > > > _______________________________________________ >> > > > Flask mailing list >> > > > Flask at python.org >> > > > https://mail.python.org/mailman/listinfo/flask >> > > > >> > > -------------- next part -------------- >> > > An HTML attachment was scrubbed... >> > > URL: < >> > > >> > >> http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html >> > > > >> > > >> > > ------------------------------ >> > > >> > > Subject: Digest Footer >> > > >> > > _______________________________________________ >> > > Flask mailing list >> > > Flask at python.org >> > > https://mail.python.org/mailman/listinfo/flask >> > > >> > > >> > > ------------------------------ >> > > >> > > End of Flask Digest, Vol 49, Issue 5 >> > > ************************************ >> > > >> > -------------- next part -------------- >> > An HTML attachment was scrubbed... >> > URL: < >> > >> http://mail.python.org/pipermail/flask/attachments/20190703/c47bb246/attachment-0001.html >> > > >> > >> > ------------------------------ >> > >> > Message: 2 >> > Date: Thu, 4 Jul 2019 06:25:40 +0200 >> > From: Gergely Polonkai >> > To: "sidwoodstock ." >> > Cc: flask >> > Subject: Re: [Flask] Unable to set current_user.authenticated to True >> > Message-ID: >> > < >> > CACczBUJaj67qxPCEi9Tmjku42QDxDsuVLmEGQGuFaC2nndT7eA at mail.gmail.com> >> > Content-Type: text/plain; charset="utf-8" >> > >> > No, modifying current_user directly is not possible (at least it won?t >> > propagate outside the function). current_user is a proxy object that >> points >> > to the logged in user in the current request. If you assign a different >> > value to it, its proxy nature goes away which is definitely not what you >> > want: in extreme cases it might introduce security issues where users >> can >> > access each the data of other. >> > >> > On Wed, 3 Jul 2019, 18:19 sidwoodstock ., >> wrote: >> > >> > > Also, if Gergely's suggestion doesn't work, you could try removing >> your >> > > variable assignment of current_user = user. I see no practical reason >> to >> > do >> > > this, and since current_user is a built-in (and very handy) variable, >> > maybe >> > > that is somehow related to your issue? >> > > >> > > > > current_user = user >> > > >> > > and then just call login_user directly with your user you already >> have at >> > > hand: >> > > >> > > > > login_user(user, form.remember_me.data) >> > > >> > > -Scott >> > > >> > > On Wed, Jul 3, 2019 at 9:03 AM wrote: >> > > >> > >> Send Flask mailing list submissions to >> > >> flask at python.org >> > >> >> > >> To subscribe or unsubscribe via the World Wide Web, visit >> > >> https://mail.python.org/mailman/listinfo/flask >> > >> or, via email, send a message with subject or body 'help' to >> > >> flask-request at python.org >> > >> >> > >> You can reach the person managing the list at >> > >> flask-owner at python.org >> > >> >> > >> When replying, please edit your Subject line so it is more specific >> > >> than "Re: Contents of Flask digest..." >> > >> >> > >> >> > >> Today's Topics: >> > >> >> > >> 1. Re: Unable to set current_user.authenticated to True >> > >> (Gergely Polonkai) >> > >> >> > >> >> > >> >> ---------------------------------------------------------------------- >> > >> >> > >> Message: 1 >> > >> Date: Tue, 2 Jul 2019 19:01:20 +0200 >> > >> From: Gergely Polonkai >> > >> To: Leni Kadali Mutungi >> > >> Cc: flask >> > >> Subject: Re: [Flask] Unable to set current_user.authenticated to True >> > >> Message-ID: >> > >> > > >> zxtk3bMO+n-+-y3Q at mail.gmail.com> >> > >> Content-Type: text/plain; charset="utf-8" >> > >> >> > >> Hello, >> > >> >> > >> I assume you are using Flask-Login (either directly or via another >> > >> extension like Flask-Security). If this is the case, you can import >> > >> login_user and call it like login_user(user). >> > >> >> > >> If that does not work, you may want to check if the user is active >> (ie. >> > >> not >> > >> disabled), as it is the most common culprit when a user can?t be >> logged >> > >> in. >> > >> >> > >> Best, >> > >> Gergely >> > >> >> > >> On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < >> lenikmutungi at gmail.com> >> > >> wrote: >> > >> >> > >> > I think you mean to set it as `current_user.is_authenticated = >> True`. >> > >> > >> > >> > On 7/1/19 6:14 PM, Abdul Mohammed wrote: >> > >> > > Hello everyone, >> > >> > > I am trying to toggle between "Sign in" and >> "Sign >> > >> > > out" links using the current_user.is_authenticated variable such >> > that >> > >> > > when it returns False, the "Sign in" is displayed and when True >> the >> > >> > > "Sign out" link is displayed. At some point in the login code I >> set >> > >> > > current_user.authenticated = True. The thing is that by the I am >> > >> > > successfully logged in and presented with the next view, it is >> the >> > >> > > "Sign in" link that is still displayed. When I check >> > >> > > current_user.is_authenticated, it returns False, even though I >> had >> > >> > > explicitly set it to True. Please can anyone point out what I am >> > might >> > >> > > be doing wrong? Here is my code: >> > >> > > >> > >> > > I have a base.html file that contains the "Sign in" and "Sign >> out" >> > >> > > links that is extended by the other templates: >> > >> > > >> > >> > > >> > >> > > >> > >> > > >> > >> > > {% block page_content %}{% endblock %} >> > >> > > >> > >> > > >> > >> > > >> > >> > > When the app first loads in the browser it displays a login >> form, >> > >> > > login.html: >> > >> > > >> > >> > > {% extends "base.html" %} >> > >> > > >> > >> > > {% block content %} >> > >> > > {% import "bootstrap/wtf.html" as wtf %} >> > >> > > {% block title %}Flasky - Login{% endblock %} >> > >> > > {% block page_content %} >> > >> > > >> > >> > >
>> > >> > > {{ wtf.quick_form(form) }} >> > >> > >
>> > >> > > {% endblock %} >> > >> > > {% endblock %} >> > >> > > >> > >> > > When a user logs in, it loads a template dashboard.html that >> > displays >> > >> > > a map. The top part looks like this: >> > >> > > >> > >> > > {% extends "base.html" %} >> > >> > > >> > >> > > {% block page_content %} >> > >> > > >> > >> > > >> > >> > > Lagos Map >> > >> > > > > >> > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" >> > >> > > >> > >> > >> > >> >> > >> integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" >> > >> > > crossorigin=""/> >> > >> > > >> > >> > > >> > >> > > > > >> > > href=" >> > >> > >> > >> >> > >> https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css >> > >> " >> > >> > >> > >> > > /> >> > >> > > > > >> > > href=" >> > >> > >> > >> >> > >> https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css >> > >> " >> > >> > >> > >> > > /> >> > >> > > >> > >> > > >> > >> > > ... >> > >> > > ... >> > >> > > >> > >> > > And these are the relevant routes: >> > >> > > >> > >> > > @app.route('/',methods=['GET','POST']) >> > >> > > def index(): >> > >> > > form = LoginForm() >> > >> > > if form.validate_on_submit(): >> > >> > > user = >> User.query.filter_by(email=form.email.data).first() >> > >> > > if user is not None and >> > >> > user.check_password(form.password.data): >> > >> > > user.authenticated = True >> > >> > > current_user = user >> > >> > > db.session.add(current_user) >> > >> > > db.session.commit() >> > >> > > login_user(current_user, form.remember_me.data) >> > >> > > return redirect(request.args.get('next') or >> > >> > > url_for('dashboard')) >> > >> > > flash('Invalid username or password.') >> > >> > > return render_template('auth/login.html', form=form) >> > >> > > >> > >> > > @app.route('/dashboard') >> > >> > > def dashboard(): >> > >> > > return render_template("dashboard.html") >> > >> > > >> > >> > > Thank you for your time. >> > >> > > >> > >> > > _______________________________________________ >> > >> > > Flask mailing list >> > >> > > Flask at python.org >> > >> > > https://mail.python.org/mailman/listinfo/flask >> > >> > >> > >> > -- >> > >> > -- Kind regards, >> > >> > Leni Kadali Mutungi >> > >> > >> > >> > _______________________________________________ >> > >> > Flask mailing list >> > >> > Flask at python.org >> > >> > https://mail.python.org/mailman/listinfo/flask >> > >> > >> > >> -------------- next part -------------- >> > >> An HTML attachment was scrubbed... >> > >> URL: < >> > >> >> > >> http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html >> > >> > >> > >> >> > >> ------------------------------ >> > >> >> > >> Subject: Digest Footer >> > >> >> > >> _______________________________________________ >> > >> Flask mailing list >> > >> Flask at python.org >> > >> https://mail.python.org/mailman/listinfo/flask >> > >> >> > >> >> > >> ------------------------------ >> > >> >> > >> End of Flask Digest, Vol 49, Issue 5 >> > >> ************************************ >> > >> >> > > _______________________________________________ >> > > Flask mailing list >> > > Flask at python.org >> > > https://mail.python.org/mailman/listinfo/flask >> > > >> > >> > On Wed, 3 Jul 2019, 18:19 sidwoodstock ., >> wrote: >> > >> > > Also, if Gergely's suggestion doesn't work, you could try removing >> your >> > > variable assignment of current_user = user. I see no practical reason >> to >> > do >> > > this, and since current_user is a built-in (and very handy) variable, >> > maybe >> > > that is somehow related to your issue? >> > > >> > > > > current_user = user >> > > >> > > and then just call login_user directly with your user you already >> have at >> > > hand: >> > > >> > > > > login_user(user, form.remember_me.data) >> > > >> > > -Scott >> > > >> > > On Wed, Jul 3, 2019 at 9:03 AM wrote: >> > > >> > >> Send Flask mailing list submissions to >> > >> flask at python.org >> > >> >> > >> To subscribe or unsubscribe via the World Wide Web, visit >> > >> https://mail.python.org/mailman/listinfo/flask >> > >> or, via email, send a message with subject or body 'help' to >> > >> flask-request at python.org >> > >> >> > >> You can reach the person managing the list at >> > >> flask-owner at python.org >> > >> >> > >> When replying, please edit your Subject line so it is more specific >> > >> than "Re: Contents of Flask digest..." >> > >> >> > >> >> > >> Today's Topics: >> > >> >> > >> 1. Re: Unable to set current_user.authenticated to True >> > >> (Gergely Polonkai) >> > >> >> > >> >> > >> >> ---------------------------------------------------------------------- >> > >> >> > >> Message: 1 >> > >> Date: Tue, 2 Jul 2019 19:01:20 +0200 >> > >> From: Gergely Polonkai >> > >> To: Leni Kadali Mutungi >> > >> Cc: flask >> > >> Subject: Re: [Flask] Unable to set current_user.authenticated to True >> > >> Message-ID: >> > >> > > >> zxtk3bMO+n-+-y3Q at mail.gmail.com> >> > >> Content-Type: text/plain; charset="utf-8" >> > >> >> > >> Hello, >> > >> >> > >> I assume you are using Flask-Login (either directly or via another >> > >> extension like Flask-Security). If this is the case, you can import >> > >> login_user and call it like login_user(user). >> > >> >> > >> If that does not work, you may want to check if the user is active >> (ie. >> > >> not >> > >> disabled), as it is the most common culprit when a user can?t be >> logged >> > >> in. >> > >> >> > >> Best, >> > >> Gergely >> > >> >> > >> On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < >> lenikmutungi at gmail.com> >> > >> wrote: >> > >> >> > >> > I think you mean to set it as `current_user.is_authenticated = >> True`. >> > >> > >> > >> > On 7/1/19 6:14 PM, Abdul Mohammed wrote: >> > >> > > Hello everyone, >> > >> > > I am trying to toggle between "Sign in" and >> "Sign >> > >> > > out" links using the current_user.is_authenticated variable such >> > that >> > >> > > when it returns False, the "Sign in" is displayed and when True >> the >> > >> > > "Sign out" link is displayed. At some point in the login code I >> set >> > >> > > current_user.authenticated = True. The thing is that by the I am >> > >> > > successfully logged in and presented with the next view, it is >> the >> > >> > > "Sign in" link that is still displayed. When I check >> > >> > > current_user.is_authenticated, it returns False, even though I >> had >> > >> > > explicitly set it to True. Please can anyone point out what I am >> > might >> > >> > > be doing wrong? Here is my code: >> > >> > > >> > >> > > I have a base.html file that contains the "Sign in" and "Sign >> out" >> > >> > > links that is extended by the other templates: >> > >> > > >> > >> > > >> > >> > > >> > >> > > >> > >> > > {% block page_content %}{% endblock %} >> > >> > > >> > >> > > >> > >> > > >> > >> > > When the app first loads in the browser it displays a login >> form, >> > >> > > login.html: >> > >> > > >> > >> > > {% extends "base.html" %} >> > >> > > >> > >> > > {% block content %} >> > >> > > {% import "bootstrap/wtf.html" as wtf %} >> > >> > > {% block title %}Flasky - Login{% endblock %} >> > >> > > {% block page_content %} >> > >> > > >> > >> > >
>> > >> > > {{ wtf.quick_form(form) }} >> > >> > >
>> > >> > > {% endblock %} >> > >> > > {% endblock %} >> > >> > > >> > >> > > When a user logs in, it loads a template dashboard.html that >> > displays >> > >> > > a map. The top part looks like this: >> > >> > > >> > >> > > {% extends "base.html" %} >> > >> > > >> > >> > > {% block page_content %} >> > >> > > >> > >> > > >> > >> > > Lagos Map >> > >> > > > > >> > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" >> > >> > > >> > >> > >> > >> >> > >> integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" >> > >> > > crossorigin=""/> >> > >> > > >> > >> > > >> > >> > > > > >> > > href=" >> > >> > >> > >> >> > >> https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css >> > >> " >> > >> > >> > >> > > /> >> > >> > > > > >> > > href=" >> > >> > >> > >> >> > >> https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css >> > >> " >> > >> > >> > >> > > /> >> > >> > > >> > >> > > >> > >> > > ... >> > >> > > ... >> > >> > > >> > >> > > And these are the relevant routes: >> > >> > > >> > >> > > @app.route('/',methods=['GET','POST']) >> > >> > > def index(): >> > >> > > form = LoginForm() >> > >> > > if form.validate_on_submit(): >> > >> > > user = >> User.query.filter_by(email=form.email.data).first() >> > >> > > if user is not None and >> > >> > user.check_password(form.password.data): >> > >> > > user.authenticated = True >> > >> > > current_user = user >> > >> > > db.session.add(current_user) >> > >> > > db.session.commit() >> > >> > > login_user(current_user, form.remember_me.data) >> > >> > > return redirect(request.args.get('next') or >> > >> > > url_for('dashboard')) >> > >> > > flash('Invalid username or password.') >> > >> > > return render_template('auth/login.html', form=form) >> > >> > > >> > >> > > @app.route('/dashboard') >> > >> > > def dashboard(): >> > >> > > return render_template("dashboard.html") >> > >> > > >> > >> > > Thank you for your time. >> > >> > > >> > >> > > _______________________________________________ >> > >> > > Flask mailing list >> > >> > > Flask at python.org >> > >> > > https://mail.python.org/mailman/listinfo/flask >> > >> > >> > >> > -- >> > >> > -- Kind regards, >> > >> > Leni Kadali Mutungi >> > >> > >> > >> > _______________________________________________ >> > >> > Flask mailing list >> > >> > Flask at python.org >> > >> > https://mail.python.org/mailman/listinfo/flask >> > >> > >> > >> -------------- next part -------------- >> > >> An HTML attachment was scrubbed... >> > >> URL: < >> > >> >> > >> http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html >> > >> > >> > >> >> > >> ------------------------------ >> > >> >> > >> Subject: Digest Footer >> > >> >> > >> _______________________________________________ >> > >> Flask mailing list >> > >> Flask at python.org >> > >> https://mail.python.org/mailman/listinfo/flask >> > >> >> > >> >> > >> ------------------------------ >> > >> >> > >> End of Flask Digest, Vol 49, Issue 5 >> > >> ************************************ >> > >> >> > > _______________________________________________ >> > > Flask mailing list >> > > Flask at python.org >> > > https://mail.python.org/mailman/listinfo/flask >> > > >> > -------------- next part -------------- >> > An HTML attachment was scrubbed... >> > URL: < >> > >> http://mail.python.org/pipermail/flask/attachments/20190704/055df8bc/attachment.html >> > > >> > >> > ------------------------------ >> > >> > Subject: Digest Footer >> > >> > _______________________________________________ >> > Flask mailing list >> > Flask at python.org >> > https://mail.python.org/mailman/listinfo/flask >> > >> > >> > ------------------------------ >> > >> > End of Flask Digest, Vol 49, Issue 6 >> > ************************************ >> > >> -------------- next part -------------- >> An HTML attachment was scrubbed... >> URL: < >> http://mail.python.org/pipermail/flask/attachments/20190704/89bc8e49/attachment.html >> > >> >> ------------------------------ >> >> Subject: Digest Footer >> >> _______________________________________________ >> Flask mailing list >> Flask at python.org >> https://mail.python.org/mailman/listinfo/flask >> >> >> ------------------------------ >> >> End of Flask Digest, Vol 49, Issue 7 >> ************************************ >> > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From imonikemohammed at gmail.com Mon Jul 8 09:53:38 2019 From: imonikemohammed at gmail.com (Abdul Mohammed) Date: Mon, 8 Jul 2019 14:53:38 +0100 Subject: [Flask] Flask Digest, Vol 49, Issue 7 In-Reply-To: References: Message-ID: Thanks Gergely for explaining the current_user object. I noticed that the value of is_authenticated wouldn't propagate outside the function but since I didn't understand the object, it was driving me nuts. On Thu, Jul 4, 2019 at 4:56 PM wrote: > Send Flask mailing list submissions to > flask at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/flask > or, via email, send a message with subject or body 'help' to > flask-request at python.org > > You can reach the person managing the list at > flask-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Flask digest..." > > > Today's Topics: > > 1. Re: Flask Digest, Vol 49, Issue 5 (Abdul Mohammed) > 2. Re: Flask Digest, Vol 49, Issue 6 (Abdul Mohammed) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Thu, 4 Jul 2019 16:22:42 +0100 > From: Abdul Mohammed > To: flask at python.org > Subject: Re: [Flask] Flask Digest, Vol 49, Issue 5 > Message-ID: > < > CAEKkz85XoPnseQ9_jF_0WcfKDruXLAKKCBp4+2k_FogNA8zVcQ at mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > Thanks Gergely for the response. > Yes I am using Flask-Login and I think directly because this is how I > import it: > > from flask_login import login_user > > My problem is not that I can't log in. I can log in fine. The problem is > essentially that I can not log out. I am trying to use the value of > current_user.is_authenticated to determine whether to show the "Sign in" or > "Sign out" link. If True, it shows "Sign out" and "Sign in" when False. > For some reason, the value remains False after I have logged in so the > "Sign out" link never displays and so I am trapped in the app (Please save > me!!!) > because I can't log out. I hope I have made my problems clearer. > > Regards > > On Wed, Jul 3, 2019 at 5:04 PM wrote: > > > Send Flask mailing list submissions to > > flask at python.org > > > > To subscribe or unsubscribe via the World Wide Web, visit > > https://mail.python.org/mailman/listinfo/flask > > or, via email, send a message with subject or body 'help' to > > flask-request at python.org > > > > You can reach the person managing the list at > > flask-owner at python.org > > > > When replying, please edit your Subject line so it is more specific > > than "Re: Contents of Flask digest..." > > > > > > Today's Topics: > > > > 1. Re: Unable to set current_user.authenticated to True > > (Gergely Polonkai) > > > > > > ---------------------------------------------------------------------- > > > > Message: 1 > > Date: Tue, 2 Jul 2019 19:01:20 +0200 > > From: Gergely Polonkai > > To: Leni Kadali Mutungi > > Cc: flask > > Subject: Re: [Flask] Unable to set current_user.authenticated to True > > Message-ID: > > > zxtk3bMO+n-+-y3Q at mail.gmail.com> > > Content-Type: text/plain; charset="utf-8" > > > > Hello, > > > > I assume you are using Flask-Login (either directly or via another > > extension like Flask-Security). If this is the case, you can import > > login_user and call it like login_user(user). > > > > If that does not work, you may want to check if the user is active (ie. > not > > disabled), as it is the most common culprit when a user can?t be logged > in. > > > > Best, > > Gergely > > > > On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, > > wrote: > > > > > I think you mean to set it as `current_user.is_authenticated = True`. > > > > > > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > > > > Hello everyone, > > > > I am trying to toggle between "Sign in" and "Sign > > > > out" links using the current_user.is_authenticated variable such that > > > > when it returns False, the "Sign in" is displayed and when True the > > > > "Sign out" link is displayed. At some point in the login code I set > > > > current_user.authenticated = True. The thing is that by the I am > > > > successfully logged in and presented with the next view, it is the > > > > "Sign in" link that is still displayed. When I check > > > > current_user.is_authenticated, it returns False, even though I had > > > > explicitly set it to True. Please can anyone point out what I am > might > > > > be doing wrong? Here is my code: > > > > > > > > I have a base.html file that contains the "Sign in" and "Sign out" > > > > links that is extended by the other templates: > > > > > > > > > > > > > > > > > > > > {% block page_content %}{% endblock %} > > > > > > > > > > > > > > > > When the app first loads in the browser it displays a login form, > > > > login.html: > > > > > > > > {% extends "base.html" %} > > > > > > > > {% block content %} > > > > {% import "bootstrap/wtf.html" as wtf %} > > > > {% block title %}Flasky - Login{% endblock %} > > > > {% block page_content %} > > > > > > > >
> > > > {{ wtf.quick_form(form) }} > > > >
> > > > {% endblock %} > > > > {% endblock %} > > > > > > > > When a user logs in, it loads a template dashboard.html that displays > > > > a map. The top part looks like this: > > > > > > > > {% extends "base.html" %} > > > > > > > > {% block page_content %} > > > > > > > > > > > > Lagos Map > > > > > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > > > > > > > > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > > > crossorigin=""/> > > > > > > > > > > > > > > > href=" > > > > > > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > > " > > > > > > > /> > > > > > > > href=" > > > > > > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > > " > > > > > > > /> > > > > > > > > > > > > ... > > > > ... > > > > > > > > And these are the relevant routes: > > > > > > > > @app.route('/',methods=['GET','POST']) > > > > def index(): > > > > form = LoginForm() > > > > if form.validate_on_submit(): > > > > user = User.query.filter_by(email=form.email.data).first() > > > > if user is not None and > > > user.check_password(form.password.data): > > > > user.authenticated = True > > > > current_user = user > > > > db.session.add(current_user) > > > > db.session.commit() > > > > login_user(current_user, form.remember_me.data) > > > > return redirect(request.args.get('next') or > > > > url_for('dashboard')) > > > > flash('Invalid username or password.') > > > > return render_template('auth/login.html', form=form) > > > > > > > > @app.route('/dashboard') > > > > def dashboard(): > > > > return render_template("dashboard.html") > > > > > > > > Thank you for your time. > > > > > > > > _______________________________________________ > > > > Flask mailing list > > > > Flask at python.org > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > -- > > > -- Kind regards, > > > Leni Kadali Mutungi > > > > > > _______________________________________________ > > > Flask mailing list > > > Flask at python.org > > > https://mail.python.org/mailman/listinfo/flask > > > > > -------------- next part -------------- > > An HTML attachment was scrubbed... > > URL: < > > > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > > > > > > > ------------------------------ > > > > Subject: Digest Footer > > > > _______________________________________________ > > Flask mailing list > > Flask at python.org > > https://mail.python.org/mailman/listinfo/flask > > > > > > ------------------------------ > > > > End of Flask Digest, Vol 49, Issue 5 > > ************************************ > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/flask/attachments/20190704/29797e8e/attachment-0001.html > > > > ------------------------------ > > Message: 2 > Date: Thu, 4 Jul 2019 16:55:18 +0100 > From: Abdul Mohammed > To: flask at python.org > Subject: Re: [Flask] Flask Digest, Vol 49, Issue 6 > Message-ID: > g at mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > Thanks Scott. > I just explained to Gergely that my problem is not logging in but getting > the value of current_user.is_authenticated to change to True so that I > can log out. I wasn't originally doing the current_user = user assignment. > I could log in with either current_user or user. When the value of > current_user.is_authenticated wouldn't change to True, I added it because i > was just trying to see whether it would solve my problem. I will get rid of > it > but the problem is likely to remain. > > On Thu, Jul 4, 2019 at 5:26 AM wrote: > > > Send Flask mailing list submissions to > > flask at python.org > > > > To subscribe or unsubscribe via the World Wide Web, visit > > https://mail.python.org/mailman/listinfo/flask > > or, via email, send a message with subject or body 'help' to > > flask-request at python.org > > > > You can reach the person managing the list at > > flask-owner at python.org > > > > When replying, please edit your Subject line so it is more specific > > than "Re: Contents of Flask digest..." > > > > > > Today's Topics: > > > > 1. Re: Unable to set current_user.authenticated to True > > (sidwoodstock .) > > 2. Re: Unable to set current_user.authenticated to True > > (Gergely Polonkai) > > > > > > ---------------------------------------------------------------------- > > > > Message: 1 > > Date: Wed, 3 Jul 2019 09:19:20 -0700 > > From: "sidwoodstock ." > > To: flask at python.org > > Subject: Re: [Flask] Unable to set current_user.authenticated to True > > Message-ID: > > > KV78LHGK2k8hA at mail.gmail.com> > > Content-Type: text/plain; charset="utf-8" > > > > Also, if Gergely's suggestion doesn't work, you could try removing your > > variable assignment of current_user = user. I see no practical reason to > do > > this, and since current_user is a built-in (and very handy) variable, > maybe > > that is somehow related to your issue? > > > > > > current_user = user > > > > and then just call login_user directly with your user you already have at > > hand: > > > > > > login_user(user, form.remember_me.data) > > > > -Scott > > > > On Wed, Jul 3, 2019 at 9:03 AM wrote: > > > > > Send Flask mailing list submissions to > > > flask at python.org > > > > > > To subscribe or unsubscribe via the World Wide Web, visit > > > https://mail.python.org/mailman/listinfo/flask > > > or, via email, send a message with subject or body 'help' to > > > flask-request at python.org > > > > > > You can reach the person managing the list at > > > flask-owner at python.org > > > > > > When replying, please edit your Subject line so it is more specific > > > than "Re: Contents of Flask digest..." > > > > > > > > > Today's Topics: > > > > > > 1. Re: Unable to set current_user.authenticated to True > > > (Gergely Polonkai) > > > > > > > > > ---------------------------------------------------------------------- > > > > > > Message: 1 > > > Date: Tue, 2 Jul 2019 19:01:20 +0200 > > > From: Gergely Polonkai > > > To: Leni Kadali Mutungi > > > Cc: flask > > > Subject: Re: [Flask] Unable to set current_user.authenticated to True > > > Message-ID: > > > > > zxtk3bMO+n-+-y3Q at mail.gmail.com> > > > Content-Type: text/plain; charset="utf-8" > > > > > > Hello, > > > > > > I assume you are using Flask-Login (either directly or via another > > > extension like Flask-Security). If this is the case, you can import > > > login_user and call it like login_user(user). > > > > > > If that does not work, you may want to check if the user is active (ie. > > not > > > disabled), as it is the most common culprit when a user can?t be logged > > in. > > > > > > Best, > > > Gergely > > > > > > On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, > > > > wrote: > > > > > > > I think you mean to set it as `current_user.is_authenticated = True`. > > > > > > > > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > > > > > Hello everyone, > > > > > I am trying to toggle between "Sign in" and "Sign > > > > > out" links using the current_user.is_authenticated variable such > that > > > > > when it returns False, the "Sign in" is displayed and when True the > > > > > "Sign out" link is displayed. At some point in the login code I set > > > > > current_user.authenticated = True. The thing is that by the I am > > > > > successfully logged in and presented with the next view, it is the > > > > > "Sign in" link that is still displayed. When I check > > > > > current_user.is_authenticated, it returns False, even though I had > > > > > explicitly set it to True. Please can anyone point out what I am > > might > > > > > be doing wrong? Here is my code: > > > > > > > > > > I have a base.html file that contains the "Sign in" and "Sign out" > > > > > links that is extended by the other templates: > > > > > > > > > > > > > > > > > > > > > > > > > {% block page_content %}{% endblock %} > > > > > > > > > > > > > > > > > > > > When the app first loads in the browser it displays a login form, > > > > > login.html: > > > > > > > > > > {% extends "base.html" %} > > > > > > > > > > {% block content %} > > > > > {% import "bootstrap/wtf.html" as wtf %} > > > > > {% block title %}Flasky - Login{% endblock %} > > > > > {% block page_content %} > > > > > > > > > >
> > > > > {{ wtf.quick_form(form) }} > > > > >
> > > > > {% endblock %} > > > > > {% endblock %} > > > > > > > > > > When a user logs in, it loads a template dashboard.html that > displays > > > > > a map. The top part looks like this: > > > > > > > > > > {% extends "base.html" %} > > > > > > > > > > {% block page_content %} > > > > > > > > > > > > > > > Lagos Map > > > > > > > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > > > > > > > > > > > > > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > > > > crossorigin=""/> > > > > > > > > > > > > > > > > > > > href=" > > > > > > > > > > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > > > " > > > > > > > > > /> > > > > > > > > > href=" > > > > > > > > > > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > > > " > > > > > > > > > /> > > > > > > > > > > > > > > > ... > > > > > ... > > > > > > > > > > And these are the relevant routes: > > > > > > > > > > @app.route('/',methods=['GET','POST']) > > > > > def index(): > > > > > form = LoginForm() > > > > > if form.validate_on_submit(): > > > > > user = > User.query.filter_by(email=form.email.data).first() > > > > > if user is not None and > > > > user.check_password(form.password.data): > > > > > user.authenticated = True > > > > > current_user = user > > > > > db.session.add(current_user) > > > > > db.session.commit() > > > > > login_user(current_user, form.remember_me.data) > > > > > return redirect(request.args.get('next') or > > > > > url_for('dashboard')) > > > > > flash('Invalid username or password.') > > > > > return render_template('auth/login.html', form=form) > > > > > > > > > > @app.route('/dashboard') > > > > > def dashboard(): > > > > > return render_template("dashboard.html") > > > > > > > > > > Thank you for your time. > > > > > > > > > > _______________________________________________ > > > > > Flask mailing list > > > > > Flask at python.org > > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > > -- > > > > -- Kind regards, > > > > Leni Kadali Mutungi > > > > > > > > _______________________________________________ > > > > Flask mailing list > > > > Flask at python.org > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > -------------- next part -------------- > > > An HTML attachment was scrubbed... > > > URL: < > > > > > > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > > > > > > > > > > ------------------------------ > > > > > > Subject: Digest Footer > > > > > > _______________________________________________ > > > Flask mailing list > > > Flask at python.org > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > > > ------------------------------ > > > > > > End of Flask Digest, Vol 49, Issue 5 > > > ************************************ > > > > > -------------- next part -------------- > > An HTML attachment was scrubbed... > > URL: < > > > http://mail.python.org/pipermail/flask/attachments/20190703/c47bb246/attachment-0001.html > > > > > > > ------------------------------ > > > > Message: 2 > > Date: Thu, 4 Jul 2019 06:25:40 +0200 > > From: Gergely Polonkai > > To: "sidwoodstock ." > > Cc: flask > > Subject: Re: [Flask] Unable to set current_user.authenticated to True > > Message-ID: > > < > > CACczBUJaj67qxPCEi9Tmjku42QDxDsuVLmEGQGuFaC2nndT7eA at mail.gmail.com> > > Content-Type: text/plain; charset="utf-8" > > > > No, modifying current_user directly is not possible (at least it won?t > > propagate outside the function). current_user is a proxy object that > points > > to the logged in user in the current request. If you assign a different > > value to it, its proxy nature goes away which is definitely not what you > > want: in extreme cases it might introduce security issues where users can > > access each the data of other. > > > > On Wed, 3 Jul 2019, 18:19 sidwoodstock ., > wrote: > > > > > Also, if Gergely's suggestion doesn't work, you could try removing your > > > variable assignment of current_user = user. I see no practical reason > to > > do > > > this, and since current_user is a built-in (and very handy) variable, > > maybe > > > that is somehow related to your issue? > > > > > > > > current_user = user > > > > > > and then just call login_user directly with your user you already have > at > > > hand: > > > > > > > > login_user(user, form.remember_me.data) > > > > > > -Scott > > > > > > On Wed, Jul 3, 2019 at 9:03 AM wrote: > > > > > >> Send Flask mailing list submissions to > > >> flask at python.org > > >> > > >> To subscribe or unsubscribe via the World Wide Web, visit > > >> https://mail.python.org/mailman/listinfo/flask > > >> or, via email, send a message with subject or body 'help' to > > >> flask-request at python.org > > >> > > >> You can reach the person managing the list at > > >> flask-owner at python.org > > >> > > >> When replying, please edit your Subject line so it is more specific > > >> than "Re: Contents of Flask digest..." > > >> > > >> > > >> Today's Topics: > > >> > > >> 1. Re: Unable to set current_user.authenticated to True > > >> (Gergely Polonkai) > > >> > > >> > > >> ---------------------------------------------------------------------- > > >> > > >> Message: 1 > > >> Date: Tue, 2 Jul 2019 19:01:20 +0200 > > >> From: Gergely Polonkai > > >> To: Leni Kadali Mutungi > > >> Cc: flask > > >> Subject: Re: [Flask] Unable to set current_user.authenticated to True > > >> Message-ID: > > >> > >> zxtk3bMO+n-+-y3Q at mail.gmail.com> > > >> Content-Type: text/plain; charset="utf-8" > > >> > > >> Hello, > > >> > > >> I assume you are using Flask-Login (either directly or via another > > >> extension like Flask-Security). If this is the case, you can import > > >> login_user and call it like login_user(user). > > >> > > >> If that does not work, you may want to check if the user is active > (ie. > > >> not > > >> disabled), as it is the most common culprit when a user can?t be > logged > > >> in. > > >> > > >> Best, > > >> Gergely > > >> > > >> On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < > lenikmutungi at gmail.com> > > >> wrote: > > >> > > >> > I think you mean to set it as `current_user.is_authenticated = > True`. > > >> > > > >> > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > > >> > > Hello everyone, > > >> > > I am trying to toggle between "Sign in" and > "Sign > > >> > > out" links using the current_user.is_authenticated variable such > > that > > >> > > when it returns False, the "Sign in" is displayed and when True > the > > >> > > "Sign out" link is displayed. At some point in the login code I > set > > >> > > current_user.authenticated = True. The thing is that by the I am > > >> > > successfully logged in and presented with the next view, it is the > > >> > > "Sign in" link that is still displayed. When I check > > >> > > current_user.is_authenticated, it returns False, even though I had > > >> > > explicitly set it to True. Please can anyone point out what I am > > might > > >> > > be doing wrong? Here is my code: > > >> > > > > >> > > I have a base.html file that contains the "Sign in" and "Sign out" > > >> > > links that is extended by the other templates: > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > {% block page_content %}{% endblock %} > > >> > > > > >> > > > > >> > > > > >> > > When the app first loads in the browser it displays a login form, > > >> > > login.html: > > >> > > > > >> > > {% extends "base.html" %} > > >> > > > > >> > > {% block content %} > > >> > > {% import "bootstrap/wtf.html" as wtf %} > > >> > > {% block title %}Flasky - Login{% endblock %} > > >> > > {% block page_content %} > > >> > > > > >> > >
> > >> > > {{ wtf.quick_form(form) }} > > >> > >
> > >> > > {% endblock %} > > >> > > {% endblock %} > > >> > > > > >> > > When a user logs in, it loads a template dashboard.html that > > displays > > >> > > a map. The top part looks like this: > > >> > > > > >> > > {% extends "base.html" %} > > >> > > > > >> > > {% block page_content %} > > >> > > > > >> > > > > >> > > Lagos Map > > >> > > > >> > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > > >> > > > > >> > > > >> > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > >> > > crossorigin=""/> > > >> > > > > >> > > > > >> > > > >> > > href=" > > >> > > > >> > > > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > > >> " > > >> > > > >> > > /> > > >> > > > >> > > href=" > > >> > > > >> > > > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > > >> " > > >> > > > >> > > /> > > >> > > > > >> > > > > >> > > ... > > >> > > ... > > >> > > > > >> > > And these are the relevant routes: > > >> > > > > >> > > @app.route('/',methods=['GET','POST']) > > >> > > def index(): > > >> > > form = LoginForm() > > >> > > if form.validate_on_submit(): > > >> > > user = > User.query.filter_by(email=form.email.data).first() > > >> > > if user is not None and > > >> > user.check_password(form.password.data): > > >> > > user.authenticated = True > > >> > > current_user = user > > >> > > db.session.add(current_user) > > >> > > db.session.commit() > > >> > > login_user(current_user, form.remember_me.data) > > >> > > return redirect(request.args.get('next') or > > >> > > url_for('dashboard')) > > >> > > flash('Invalid username or password.') > > >> > > return render_template('auth/login.html', form=form) > > >> > > > > >> > > @app.route('/dashboard') > > >> > > def dashboard(): > > >> > > return render_template("dashboard.html") > > >> > > > > >> > > Thank you for your time. > > >> > > > > >> > > _______________________________________________ > > >> > > Flask mailing list > > >> > > Flask at python.org > > >> > > https://mail.python.org/mailman/listinfo/flask > > >> > > > >> > -- > > >> > -- Kind regards, > > >> > Leni Kadali Mutungi > > >> > > > >> > _______________________________________________ > > >> > Flask mailing list > > >> > Flask at python.org > > >> > https://mail.python.org/mailman/listinfo/flask > > >> > > > >> -------------- next part -------------- > > >> An HTML attachment was scrubbed... > > >> URL: < > > >> > > > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > > >> > > > >> > > >> ------------------------------ > > >> > > >> Subject: Digest Footer > > >> > > >> _______________________________________________ > > >> Flask mailing list > > >> Flask at python.org > > >> https://mail.python.org/mailman/listinfo/flask > > >> > > >> > > >> ------------------------------ > > >> > > >> End of Flask Digest, Vol 49, Issue 5 > > >> ************************************ > > >> > > > _______________________________________________ > > > Flask mailing list > > > Flask at python.org > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > On Wed, 3 Jul 2019, 18:19 sidwoodstock ., > wrote: > > > > > Also, if Gergely's suggestion doesn't work, you could try removing your > > > variable assignment of current_user = user. I see no practical reason > to > > do > > > this, and since current_user is a built-in (and very handy) variable, > > maybe > > > that is somehow related to your issue? > > > > > > > > current_user = user > > > > > > and then just call login_user directly with your user you already have > at > > > hand: > > > > > > > > login_user(user, form.remember_me.data) > > > > > > -Scott > > > > > > On Wed, Jul 3, 2019 at 9:03 AM wrote: > > > > > >> Send Flask mailing list submissions to > > >> flask at python.org > > >> > > >> To subscribe or unsubscribe via the World Wide Web, visit > > >> https://mail.python.org/mailman/listinfo/flask > > >> or, via email, send a message with subject or body 'help' to > > >> flask-request at python.org > > >> > > >> You can reach the person managing the list at > > >> flask-owner at python.org > > >> > > >> When replying, please edit your Subject line so it is more specific > > >> than "Re: Contents of Flask digest..." > > >> > > >> > > >> Today's Topics: > > >> > > >> 1. Re: Unable to set current_user.authenticated to True > > >> (Gergely Polonkai) > > >> > > >> > > >> ---------------------------------------------------------------------- > > >> > > >> Message: 1 > > >> Date: Tue, 2 Jul 2019 19:01:20 +0200 > > >> From: Gergely Polonkai > > >> To: Leni Kadali Mutungi > > >> Cc: flask > > >> Subject: Re: [Flask] Unable to set current_user.authenticated to True > > >> Message-ID: > > >> > >> zxtk3bMO+n-+-y3Q at mail.gmail.com> > > >> Content-Type: text/plain; charset="utf-8" > > >> > > >> Hello, > > >> > > >> I assume you are using Flask-Login (either directly or via another > > >> extension like Flask-Security). If this is the case, you can import > > >> login_user and call it like login_user(user). > > >> > > >> If that does not work, you may want to check if the user is active > (ie. > > >> not > > >> disabled), as it is the most common culprit when a user can?t be > logged > > >> in. > > >> > > >> Best, > > >> Gergely > > >> > > >> On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < > lenikmutungi at gmail.com> > > >> wrote: > > >> > > >> > I think you mean to set it as `current_user.is_authenticated = > True`. > > >> > > > >> > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > > >> > > Hello everyone, > > >> > > I am trying to toggle between "Sign in" and > "Sign > > >> > > out" links using the current_user.is_authenticated variable such > > that > > >> > > when it returns False, the "Sign in" is displayed and when True > the > > >> > > "Sign out" link is displayed. At some point in the login code I > set > > >> > > current_user.authenticated = True. The thing is that by the I am > > >> > > successfully logged in and presented with the next view, it is the > > >> > > "Sign in" link that is still displayed. When I check > > >> > > current_user.is_authenticated, it returns False, even though I had > > >> > > explicitly set it to True. Please can anyone point out what I am > > might > > >> > > be doing wrong? Here is my code: > > >> > > > > >> > > I have a base.html file that contains the "Sign in" and "Sign out" > > >> > > links that is extended by the other templates: > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > {% block page_content %}{% endblock %} > > >> > > > > >> > > > > >> > > > > >> > > When the app first loads in the browser it displays a login form, > > >> > > login.html: > > >> > > > > >> > > {% extends "base.html" %} > > >> > > > > >> > > {% block content %} > > >> > > {% import "bootstrap/wtf.html" as wtf %} > > >> > > {% block title %}Flasky - Login{% endblock %} > > >> > > {% block page_content %} > > >> > > > > >> > >
> > >> > > {{ wtf.quick_form(form) }} > > >> > >
> > >> > > {% endblock %} > > >> > > {% endblock %} > > >> > > > > >> > > When a user logs in, it loads a template dashboard.html that > > displays > > >> > > a map. The top part looks like this: > > >> > > > > >> > > {% extends "base.html" %} > > >> > > > > >> > > {% block page_content %} > > >> > > > > >> > > > > >> > > Lagos Map > > >> > > > >> > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > > >> > > > > >> > > > >> > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > >> > > crossorigin=""/> > > >> > > > > >> > > > > >> > > > >> > > href=" > > >> > > > >> > > > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > > >> " > > >> > > > >> > > /> > > >> > > > >> > > href=" > > >> > > > >> > > > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > > >> " > > >> > > > >> > > /> > > >> > > > > >> > > > > >> > > ... > > >> > > ... > > >> > > > > >> > > And these are the relevant routes: > > >> > > > > >> > > @app.route('/',methods=['GET','POST']) > > >> > > def index(): > > >> > > form = LoginForm() > > >> > > if form.validate_on_submit(): > > >> > > user = > User.query.filter_by(email=form.email.data).first() > > >> > > if user is not None and > > >> > user.check_password(form.password.data): > > >> > > user.authenticated = True > > >> > > current_user = user > > >> > > db.session.add(current_user) > > >> > > db.session.commit() > > >> > > login_user(current_user, form.remember_me.data) > > >> > > return redirect(request.args.get('next') or > > >> > > url_for('dashboard')) > > >> > > flash('Invalid username or password.') > > >> > > return render_template('auth/login.html', form=form) > > >> > > > > >> > > @app.route('/dashboard') > > >> > > def dashboard(): > > >> > > return render_template("dashboard.html") > > >> > > > > >> > > Thank you for your time. > > >> > > > > >> > > _______________________________________________ > > >> > > Flask mailing list > > >> > > Flask at python.org > > >> > > https://mail.python.org/mailman/listinfo/flask > > >> > > > >> > -- > > >> > -- Kind regards, > > >> > Leni Kadali Mutungi > > >> > > > >> > _______________________________________________ > > >> > Flask mailing list > > >> > Flask at python.org > > >> > https://mail.python.org/mailman/listinfo/flask > > >> > > > >> -------------- next part -------------- > > >> An HTML attachment was scrubbed... > > >> URL: < > > >> > > > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > > >> > > > >> > > >> ------------------------------ > > >> > > >> Subject: Digest Footer > > >> > > >> _______________________________________________ > > >> Flask mailing list > > >> Flask at python.org > > >> https://mail.python.org/mailman/listinfo/flask > > >> > > >> > > >> ------------------------------ > > >> > > >> End of Flask Digest, Vol 49, Issue 5 > > >> ************************************ > > >> > > > _______________________________________________ > > > Flask mailing list > > > Flask at python.org > > > https://mail.python.org/mailman/listinfo/flask > > > > > -------------- next part -------------- > > An HTML attachment was scrubbed... > > URL: < > > > http://mail.python.org/pipermail/flask/attachments/20190704/055df8bc/attachment.html > > > > > > > ------------------------------ > > > > Subject: Digest Footer > > > > _______________________________________________ > > Flask mailing list > > Flask at python.org > > https://mail.python.org/mailman/listinfo/flask > > > > > > ------------------------------ > > > > End of Flask Digest, Vol 49, Issue 6 > > ************************************ > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/flask/attachments/20190704/89bc8e49/attachment.html > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > > ------------------------------ > > End of Flask Digest, Vol 49, Issue 7 > ************************************ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From imonikemohammed at gmail.com Mon Jul 8 10:14:18 2019 From: imonikemohammed at gmail.com (Abdul Mohammed) Date: Mon, 8 Jul 2019 15:14:18 +0100 Subject: [Flask] Unable to set current_user.authenticated to True In-Reply-To: References: Message-ID: Many thanks Scott. Will try thia and let you know how it goes. On Thu, Jul 4, 2019 at 7:52 PM wrote: > Send Flask mailing list submissions to > flask at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/flask > or, via email, send a message with subject or body 'help' to > flask-request at python.org > > You can reach the person managing the list at > flask-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Flask digest..." > > > Today's Topics: > > 1. Re: Unable to set current_user.authenticated to True > (sidwoodstock .) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Thu, 4 Jul 2019 11:50:45 -0700 > From: "sidwoodstock ." > To: flask at python.org > Subject: Re: [Flask] Unable to set current_user.authenticated to True > Message-ID: > < > CALovGGOJSH0M8YkYkkfYV9AsyMOut_3SmR-OfPSYvrpqrLdtbQ at mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > Ahh okay I understand now. > > I haven't tested this myself, but perhaps try {% if current_user %} as your > conditional since it ought to return None if no one is logged in. > > -Scott > > On Thu, Jul 4, 2019 at 8:56 AM wrote: > > > Send Flask mailing list submissions to > > flask at python.org > > > > To subscribe or unsubscribe via the World Wide Web, visit > > https://mail.python.org/mailman/listinfo/flask > > or, via email, send a message with subject or body 'help' to > > flask-request at python.org > > > > You can reach the person managing the list at > > flask-owner at python.org > > > > When replying, please edit your Subject line so it is more specific > > than "Re: Contents of Flask digest..." > > > > > > Today's Topics: > > > > 1. Re: Flask Digest, Vol 49, Issue 5 (Abdul Mohammed) > > 2. Re: Flask Digest, Vol 49, Issue 6 (Abdul Mohammed) > > > > > > ---------------------------------------------------------------------- > > > > Message: 1 > > Date: Thu, 4 Jul 2019 16:22:42 +0100 > > From: Abdul Mohammed > > To: flask at python.org > > Subject: Re: [Flask] Flask Digest, Vol 49, Issue 5 > > Message-ID: > > < > > CAEKkz85XoPnseQ9_jF_0WcfKDruXLAKKCBp4+2k_FogNA8zVcQ at mail.gmail.com> > > Content-Type: text/plain; charset="utf-8" > > > > Thanks Gergely for the response. > > Yes I am using Flask-Login and I think directly because this is how I > > import it: > > > > from flask_login import login_user > > > > My problem is not that I can't log in. I can log in fine. The problem is > > essentially that I can not log out. I am trying to use the value of > > current_user.is_authenticated to determine whether to show the "Sign in" > or > > "Sign out" link. If True, it shows "Sign out" and "Sign in" when False. > > For some reason, the value remains False after I have logged in so the > > "Sign out" link never displays and so I am trapped in the app (Please > save > > me!!!) > > because I can't log out. I hope I have made my problems clearer. > > > > Regards > > > > On Wed, Jul 3, 2019 at 5:04 PM wrote: > > > > > Send Flask mailing list submissions to > > > flask at python.org > > > > > > To subscribe or unsubscribe via the World Wide Web, visit > > > https://mail.python.org/mailman/listinfo/flask > > > or, via email, send a message with subject or body 'help' to > > > flask-request at python.org > > > > > > You can reach the person managing the list at > > > flask-owner at python.org > > > > > > When replying, please edit your Subject line so it is more specific > > > than "Re: Contents of Flask digest..." > > > > > > > > > Today's Topics: > > > > > > 1. Re: Unable to set current_user.authenticated to True > > > (Gergely Polonkai) > > > > > > > > > ---------------------------------------------------------------------- > > > > > > Message: 1 > > > Date: Tue, 2 Jul 2019 19:01:20 +0200 > > > From: Gergely Polonkai > > > To: Leni Kadali Mutungi > > > Cc: flask > > > Subject: Re: [Flask] Unable to set current_user.authenticated to True > > > Message-ID: > > > > > zxtk3bMO+n-+-y3Q at mail.gmail.com> > > > Content-Type: text/plain; charset="utf-8" > > > > > > Hello, > > > > > > I assume you are using Flask-Login (either directly or via another > > > extension like Flask-Security). If this is the case, you can import > > > login_user and call it like login_user(user). > > > > > > If that does not work, you may want to check if the user is active (ie. > > not > > > disabled), as it is the most common culprit when a user can?t be logged > > in. > > > > > > Best, > > > Gergely > > > > > > On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, > > > > wrote: > > > > > > > I think you mean to set it as `current_user.is_authenticated = True`. > > > > > > > > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > > > > > Hello everyone, > > > > > I am trying to toggle between "Sign in" and "Sign > > > > > out" links using the current_user.is_authenticated variable such > that > > > > > when it returns False, the "Sign in" is displayed and when True the > > > > > "Sign out" link is displayed. At some point in the login code I set > > > > > current_user.authenticated = True. The thing is that by the I am > > > > > successfully logged in and presented with the next view, it is the > > > > > "Sign in" link that is still displayed. When I check > > > > > current_user.is_authenticated, it returns False, even though I had > > > > > explicitly set it to True. Please can anyone point out what I am > > might > > > > > be doing wrong? Here is my code: > > > > > > > > > > I have a base.html file that contains the "Sign in" and "Sign out" > > > > > links that is extended by the other templates: > > > > > > > > > > > > > > > > > > > > > > > > > {% block page_content %}{% endblock %} > > > > > > > > > > > > > > > > > > > > When the app first loads in the browser it displays a login form, > > > > > login.html: > > > > > > > > > > {% extends "base.html" %} > > > > > > > > > > {% block content %} > > > > > {% import "bootstrap/wtf.html" as wtf %} > > > > > {% block title %}Flasky - Login{% endblock %} > > > > > {% block page_content %} > > > > > > > > > >
> > > > > {{ wtf.quick_form(form) }} > > > > >
> > > > > {% endblock %} > > > > > {% endblock %} > > > > > > > > > > When a user logs in, it loads a template dashboard.html that > displays > > > > > a map. The top part looks like this: > > > > > > > > > > {% extends "base.html" %} > > > > > > > > > > {% block page_content %} > > > > > > > > > > > > > > > Lagos Map > > > > > > > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > > > > > > > > > > > > > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > > > > crossorigin=""/> > > > > > > > > > > > > > > > > > > > href=" > > > > > > > > > > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > > > " > > > > > > > > > /> > > > > > > > > > href=" > > > > > > > > > > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > > > " > > > > > > > > > /> > > > > > > > > > > > > > > > ... > > > > > ... > > > > > > > > > > And these are the relevant routes: > > > > > > > > > > @app.route('/',methods=['GET','POST']) > > > > > def index(): > > > > > form = LoginForm() > > > > > if form.validate_on_submit(): > > > > > user = > User.query.filter_by(email=form.email.data).first() > > > > > if user is not None and > > > > user.check_password(form.password.data): > > > > > user.authenticated = True > > > > > current_user = user > > > > > db.session.add(current_user) > > > > > db.session.commit() > > > > > login_user(current_user, form.remember_me.data) > > > > > return redirect(request.args.get('next') or > > > > > url_for('dashboard')) > > > > > flash('Invalid username or password.') > > > > > return render_template('auth/login.html', form=form) > > > > > > > > > > @app.route('/dashboard') > > > > > def dashboard(): > > > > > return render_template("dashboard.html") > > > > > > > > > > Thank you for your time. > > > > > > > > > > _______________________________________________ > > > > > Flask mailing list > > > > > Flask at python.org > > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > > -- > > > > -- Kind regards, > > > > Leni Kadali Mutungi > > > > > > > > _______________________________________________ > > > > Flask mailing list > > > > Flask at python.org > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > -------------- next part -------------- > > > An HTML attachment was scrubbed... > > > URL: < > > > > > > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > > > > > > > > > > ------------------------------ > > > > > > Subject: Digest Footer > > > > > > _______________________________________________ > > > Flask mailing list > > > Flask at python.org > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > > > ------------------------------ > > > > > > End of Flask Digest, Vol 49, Issue 5 > > > ************************************ > > > > > -------------- next part -------------- > > An HTML attachment was scrubbed... > > URL: < > > > http://mail.python.org/pipermail/flask/attachments/20190704/29797e8e/attachment-0001.html > > > > > > > ------------------------------ > > > > Message: 2 > > Date: Thu, 4 Jul 2019 16:55:18 +0100 > > From: Abdul Mohammed > > To: flask at python.org > > Subject: Re: [Flask] Flask Digest, Vol 49, Issue 6 > > Message-ID: > > > g at mail.gmail.com> > > Content-Type: text/plain; charset="utf-8" > > > > Thanks Scott. > > I just explained to Gergely that my problem is not logging in but getting > > the value of current_user.is_authenticated to change to True so that I > > can log out. I wasn't originally doing the current_user = user > assignment. > > I could log in with either current_user or user. When the value of > > current_user.is_authenticated wouldn't change to True, I added it > because i > > was just trying to see whether it would solve my problem. I will get rid > of > > it > > but the problem is likely to remain. > > > > On Thu, Jul 4, 2019 at 5:26 AM wrote: > > > > > Send Flask mailing list submissions to > > > flask at python.org > > > > > > To subscribe or unsubscribe via the World Wide Web, visit > > > https://mail.python.org/mailman/listinfo/flask > > > or, via email, send a message with subject or body 'help' to > > > flask-request at python.org > > > > > > You can reach the person managing the list at > > > flask-owner at python.org > > > > > > When replying, please edit your Subject line so it is more specific > > > than "Re: Contents of Flask digest..." > > > > > > > > > Today's Topics: > > > > > > 1. Re: Unable to set current_user.authenticated to True > > > (sidwoodstock .) > > > 2. Re: Unable to set current_user.authenticated to True > > > (Gergely Polonkai) > > > > > > > > > ---------------------------------------------------------------------- > > > > > > Message: 1 > > > Date: Wed, 3 Jul 2019 09:19:20 -0700 > > > From: "sidwoodstock ." > > > To: flask at python.org > > > Subject: Re: [Flask] Unable to set current_user.authenticated to True > > > Message-ID: > > > > > KV78LHGK2k8hA at mail.gmail.com> > > > Content-Type: text/plain; charset="utf-8" > > > > > > Also, if Gergely's suggestion doesn't work, you could try removing your > > > variable assignment of current_user = user. I see no practical reason > to > > do > > > this, and since current_user is a built-in (and very handy) variable, > > maybe > > > that is somehow related to your issue? > > > > > > > > current_user = user > > > > > > and then just call login_user directly with your user you already have > at > > > hand: > > > > > > > > login_user(user, form.remember_me.data) > > > > > > -Scott > > > > > > On Wed, Jul 3, 2019 at 9:03 AM wrote: > > > > > > > Send Flask mailing list submissions to > > > > flask at python.org > > > > > > > > To subscribe or unsubscribe via the World Wide Web, visit > > > > https://mail.python.org/mailman/listinfo/flask > > > > or, via email, send a message with subject or body 'help' to > > > > flask-request at python.org > > > > > > > > You can reach the person managing the list at > > > > flask-owner at python.org > > > > > > > > When replying, please edit your Subject line so it is more specific > > > > than "Re: Contents of Flask digest..." > > > > > > > > > > > > Today's Topics: > > > > > > > > 1. Re: Unable to set current_user.authenticated to True > > > > (Gergely Polonkai) > > > > > > > > > > > > > ---------------------------------------------------------------------- > > > > > > > > Message: 1 > > > > Date: Tue, 2 Jul 2019 19:01:20 +0200 > > > > From: Gergely Polonkai > > > > To: Leni Kadali Mutungi > > > > Cc: flask > > > > Subject: Re: [Flask] Unable to set current_user.authenticated to True > > > > Message-ID: > > > > > > > zxtk3bMO+n-+-y3Q at mail.gmail.com> > > > > Content-Type: text/plain; charset="utf-8" > > > > > > > > Hello, > > > > > > > > I assume you are using Flask-Login (either directly or via another > > > > extension like Flask-Security). If this is the case, you can import > > > > login_user and call it like login_user(user). > > > > > > > > If that does not work, you may want to check if the user is active > (ie. > > > not > > > > disabled), as it is the most common culprit when a user can?t be > logged > > > in. > > > > > > > > Best, > > > > Gergely > > > > > > > > On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < > lenikmutungi at gmail.com > > > > > > > wrote: > > > > > > > > > I think you mean to set it as `current_user.is_authenticated = > True`. > > > > > > > > > > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > > > > > > Hello everyone, > > > > > > I am trying to toggle between "Sign in" and > "Sign > > > > > > out" links using the current_user.is_authenticated variable such > > that > > > > > > when it returns False, the "Sign in" is displayed and when True > the > > > > > > "Sign out" link is displayed. At some point in the login code I > set > > > > > > current_user.authenticated = True. The thing is that by the I am > > > > > > successfully logged in and presented with the next view, it is > the > > > > > > "Sign in" link that is still displayed. When I check > > > > > > current_user.is_authenticated, it returns False, even though I > had > > > > > > explicitly set it to True. Please can anyone point out what I am > > > might > > > > > > be doing wrong? Here is my code: > > > > > > > > > > > > I have a base.html file that contains the "Sign in" and "Sign > out" > > > > > > links that is extended by the other templates: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > {% block page_content %}{% endblock %} > > > > > > > > > > > > > > > > > > > > > > > > When the app first loads in the browser it displays a login > form, > > > > > > login.html: > > > > > > > > > > > > {% extends "base.html" %} > > > > > > > > > > > > {% block content %} > > > > > > {% import "bootstrap/wtf.html" as wtf %} > > > > > > {% block title %}Flasky - Login{% endblock %} > > > > > > {% block page_content %} > > > > > > > > > > > >
> > > > > > {{ wtf.quick_form(form) }} > > > > > >
> > > > > > {% endblock %} > > > > > > {% endblock %} > > > > > > > > > > > > When a user logs in, it loads a template dashboard.html that > > displays > > > > > > a map. The top part looks like this: > > > > > > > > > > > > {% extends "base.html" %} > > > > > > > > > > > > {% block page_content %} > > > > > > > > > > > > > > > > > > Lagos Map > > > > > > > > > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > > > > > > > > > > > > > > > > > > > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > > > > > crossorigin=""/> > > > > > > > > > > > > > > > > > > > > > > > href=" > > > > > > > > > > > > > > > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > > > > " > > > > > > > > > > > /> > > > > > > > > > > > href=" > > > > > > > > > > > > > > > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > > > > " > > > > > > > > > > > /> > > > > > > > > > > > > > > > > > > ... > > > > > > ... > > > > > > > > > > > > And these are the relevant routes: > > > > > > > > > > > > @app.route('/',methods=['GET','POST']) > > > > > > def index(): > > > > > > form = LoginForm() > > > > > > if form.validate_on_submit(): > > > > > > user = > > User.query.filter_by(email=form.email.data).first() > > > > > > if user is not None and > > > > > user.check_password(form.password.data): > > > > > > user.authenticated = True > > > > > > current_user = user > > > > > > db.session.add(current_user) > > > > > > db.session.commit() > > > > > > login_user(current_user, form.remember_me.data) > > > > > > return redirect(request.args.get('next') or > > > > > > url_for('dashboard')) > > > > > > flash('Invalid username or password.') > > > > > > return render_template('auth/login.html', form=form) > > > > > > > > > > > > @app.route('/dashboard') > > > > > > def dashboard(): > > > > > > return render_template("dashboard.html") > > > > > > > > > > > > Thank you for your time. > > > > > > > > > > > > _______________________________________________ > > > > > > Flask mailing list > > > > > > Flask at python.org > > > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > > > > -- > > > > > -- Kind regards, > > > > > Leni Kadali Mutungi > > > > > > > > > > _______________________________________________ > > > > > Flask mailing list > > > > > Flask at python.org > > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > > > -------------- next part -------------- > > > > An HTML attachment was scrubbed... > > > > URL: < > > > > > > > > > > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > > > > > > > > > > > > > ------------------------------ > > > > > > > > Subject: Digest Footer > > > > > > > > _______________________________________________ > > > > Flask mailing list > > > > Flask at python.org > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > > > > > > ------------------------------ > > > > > > > > End of Flask Digest, Vol 49, Issue 5 > > > > ************************************ > > > > > > > -------------- next part -------------- > > > An HTML attachment was scrubbed... > > > URL: < > > > > > > http://mail.python.org/pipermail/flask/attachments/20190703/c47bb246/attachment-0001.html > > > > > > > > > > ------------------------------ > > > > > > Message: 2 > > > Date: Thu, 4 Jul 2019 06:25:40 +0200 > > > From: Gergely Polonkai > > > To: "sidwoodstock ." > > > Cc: flask > > > Subject: Re: [Flask] Unable to set current_user.authenticated to True > > > Message-ID: > > > < > > > CACczBUJaj67qxPCEi9Tmjku42QDxDsuVLmEGQGuFaC2nndT7eA at mail.gmail.com> > > > Content-Type: text/plain; charset="utf-8" > > > > > > No, modifying current_user directly is not possible (at least it won?t > > > propagate outside the function). current_user is a proxy object that > > points > > > to the logged in user in the current request. If you assign a different > > > value to it, its proxy nature goes away which is definitely not what > you > > > want: in extreme cases it might introduce security issues where users > can > > > access each the data of other. > > > > > > On Wed, 3 Jul 2019, 18:19 sidwoodstock ., > > wrote: > > > > > > > Also, if Gergely's suggestion doesn't work, you could try removing > your > > > > variable assignment of current_user = user. I see no practical reason > > to > > > do > > > > this, and since current_user is a built-in (and very handy) variable, > > > maybe > > > > that is somehow related to your issue? > > > > > > > > > > current_user = user > > > > > > > > and then just call login_user directly with your user you already > have > > at > > > > hand: > > > > > > > > > > login_user(user, form.remember_me.data) > > > > > > > > -Scott > > > > > > > > On Wed, Jul 3, 2019 at 9:03 AM wrote: > > > > > > > >> Send Flask mailing list submissions to > > > >> flask at python.org > > > >> > > > >> To subscribe or unsubscribe via the World Wide Web, visit > > > >> https://mail.python.org/mailman/listinfo/flask > > > >> or, via email, send a message with subject or body 'help' to > > > >> flask-request at python.org > > > >> > > > >> You can reach the person managing the list at > > > >> flask-owner at python.org > > > >> > > > >> When replying, please edit your Subject line so it is more specific > > > >> than "Re: Contents of Flask digest..." > > > >> > > > >> > > > >> Today's Topics: > > > >> > > > >> 1. Re: Unable to set current_user.authenticated to True > > > >> (Gergely Polonkai) > > > >> > > > >> > > > >> > ---------------------------------------------------------------------- > > > >> > > > >> Message: 1 > > > >> Date: Tue, 2 Jul 2019 19:01:20 +0200 > > > >> From: Gergely Polonkai > > > >> To: Leni Kadali Mutungi > > > >> Cc: flask > > > >> Subject: Re: [Flask] Unable to set current_user.authenticated to > True > > > >> Message-ID: > > > >> > > >> zxtk3bMO+n-+-y3Q at mail.gmail.com> > > > >> Content-Type: text/plain; charset="utf-8" > > > >> > > > >> Hello, > > > >> > > > >> I assume you are using Flask-Login (either directly or via another > > > >> extension like Flask-Security). If this is the case, you can import > > > >> login_user and call it like login_user(user). > > > >> > > > >> If that does not work, you may want to check if the user is active > > (ie. > > > >> not > > > >> disabled), as it is the most common culprit when a user can?t be > > logged > > > >> in. > > > >> > > > >> Best, > > > >> Gergely > > > >> > > > >> On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < > > lenikmutungi at gmail.com> > > > >> wrote: > > > >> > > > >> > I think you mean to set it as `current_user.is_authenticated = > > True`. > > > >> > > > > >> > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > > > >> > > Hello everyone, > > > >> > > I am trying to toggle between "Sign in" and > > "Sign > > > >> > > out" links using the current_user.is_authenticated variable such > > > that > > > >> > > when it returns False, the "Sign in" is displayed and when True > > the > > > >> > > "Sign out" link is displayed. At some point in the login code I > > set > > > >> > > current_user.authenticated = True. The thing is that by the I am > > > >> > > successfully logged in and presented with the next view, it is > the > > > >> > > "Sign in" link that is still displayed. When I check > > > >> > > current_user.is_authenticated, it returns False, even though I > had > > > >> > > explicitly set it to True. Please can anyone point out what I am > > > might > > > >> > > be doing wrong? Here is my code: > > > >> > > > > > >> > > I have a base.html file that contains the "Sign in" and "Sign > out" > > > >> > > links that is extended by the other templates: > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > {% block page_content %}{% endblock %} > > > >> > > > > > >> > > > > > >> > > > > > >> > > When the app first loads in the browser it displays a login > form, > > > >> > > login.html: > > > >> > > > > > >> > > {% extends "base.html" %} > > > >> > > > > > >> > > {% block content %} > > > >> > > {% import "bootstrap/wtf.html" as wtf %} > > > >> > > {% block title %}Flasky - Login{% endblock %} > > > >> > > {% block page_content %} > > > >> > > > > > >> > >
> > > >> > > {{ wtf.quick_form(form) }} > > > >> > >
> > > >> > > {% endblock %} > > > >> > > {% endblock %} > > > >> > > > > > >> > > When a user logs in, it loads a template dashboard.html that > > > displays > > > >> > > a map. The top part looks like this: > > > >> > > > > > >> > > {% extends "base.html" %} > > > >> > > > > > >> > > {% block page_content %} > > > >> > > > > > >> > > > > > >> > > Lagos Map > > > >> > > > > >> > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > > > >> > > > > > >> > > > > >> > > > > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > > >> > > crossorigin=""/> > > > >> > > > > > >> > > > > > >> > > > > >> > > href=" > > > >> > > > > >> > > > > > > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > > > >> " > > > >> > > > > >> > > /> > > > >> > > > > >> > > href=" > > > >> > > > > >> > > > > > > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > > > >> " > > > >> > > > > >> > > /> > > > >> > > > > > >> > > > > > >> > > ... > > > >> > > ... > > > >> > > > > > >> > > And these are the relevant routes: > > > >> > > > > > >> > > @app.route('/',methods=['GET','POST']) > > > >> > > def index(): > > > >> > > form = LoginForm() > > > >> > > if form.validate_on_submit(): > > > >> > > user = > > User.query.filter_by(email=form.email.data).first() > > > >> > > if user is not None and > > > >> > user.check_password(form.password.data): > > > >> > > user.authenticated = True > > > >> > > current_user = user > > > >> > > db.session.add(current_user) > > > >> > > db.session.commit() > > > >> > > login_user(current_user, form.remember_me.data) > > > >> > > return redirect(request.args.get('next') or > > > >> > > url_for('dashboard')) > > > >> > > flash('Invalid username or password.') > > > >> > > return render_template('auth/login.html', form=form) > > > >> > > > > > >> > > @app.route('/dashboard') > > > >> > > def dashboard(): > > > >> > > return render_template("dashboard.html") > > > >> > > > > > >> > > Thank you for your time. > > > >> > > > > > >> > > _______________________________________________ > > > >> > > Flask mailing list > > > >> > > Flask at python.org > > > >> > > https://mail.python.org/mailman/listinfo/flask > > > >> > > > > >> > -- > > > >> > -- Kind regards, > > > >> > Leni Kadali Mutungi > > > >> > > > > >> > _______________________________________________ > > > >> > Flask mailing list > > > >> > Flask at python.org > > > >> > https://mail.python.org/mailman/listinfo/flask > > > >> > > > > >> -------------- next part -------------- > > > >> An HTML attachment was scrubbed... > > > >> URL: < > > > >> > > > > > > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > > > >> > > > > >> > > > >> ------------------------------ > > > >> > > > >> Subject: Digest Footer > > > >> > > > >> _______________________________________________ > > > >> Flask mailing list > > > >> Flask at python.org > > > >> https://mail.python.org/mailman/listinfo/flask > > > >> > > > >> > > > >> ------------------------------ > > > >> > > > >> End of Flask Digest, Vol 49, Issue 5 > > > >> ************************************ > > > >> > > > > _______________________________________________ > > > > Flask mailing list > > > > Flask at python.org > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > > > > On Wed, 3 Jul 2019, 18:19 sidwoodstock ., > > wrote: > > > > > > > Also, if Gergely's suggestion doesn't work, you could try removing > your > > > > variable assignment of current_user = user. I see no practical reason > > to > > > do > > > > this, and since current_user is a built-in (and very handy) variable, > > > maybe > > > > that is somehow related to your issue? > > > > > > > > > > current_user = user > > > > > > > > and then just call login_user directly with your user you already > have > > at > > > > hand: > > > > > > > > > > login_user(user, form.remember_me.data) > > > > > > > > -Scott > > > > > > > > On Wed, Jul 3, 2019 at 9:03 AM wrote: > > > > > > > >> Send Flask mailing list submissions to > > > >> flask at python.org > > > >> > > > >> To subscribe or unsubscribe via the World Wide Web, visit > > > >> https://mail.python.org/mailman/listinfo/flask > > > >> or, via email, send a message with subject or body 'help' to > > > >> flask-request at python.org > > > >> > > > >> You can reach the person managing the list at > > > >> flask-owner at python.org > > > >> > > > >> When replying, please edit your Subject line so it is more specific > > > >> than "Re: Contents of Flask digest..." > > > >> > > > >> > > > >> Today's Topics: > > > >> > > > >> 1. Re: Unable to set current_user.authenticated to True > > > >> (Gergely Polonkai) > > > >> > > > >> > > > >> > ---------------------------------------------------------------------- > > > >> > > > >> Message: 1 > > > >> Date: Tue, 2 Jul 2019 19:01:20 +0200 > > > >> From: Gergely Polonkai > > > >> To: Leni Kadali Mutungi > > > >> Cc: flask > > > >> Subject: Re: [Flask] Unable to set current_user.authenticated to > True > > > >> Message-ID: > > > >> > > >> zxtk3bMO+n-+-y3Q at mail.gmail.com> > > > >> Content-Type: text/plain; charset="utf-8" > > > >> > > > >> Hello, > > > >> > > > >> I assume you are using Flask-Login (either directly or via another > > > >> extension like Flask-Security). If this is the case, you can import > > > >> login_user and call it like login_user(user). > > > >> > > > >> If that does not work, you may want to check if the user is active > > (ie. > > > >> not > > > >> disabled), as it is the most common culprit when a user can?t be > > logged > > > >> in. > > > >> > > > >> Best, > > > >> Gergely > > > >> > > > >> On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < > > lenikmutungi at gmail.com> > > > >> wrote: > > > >> > > > >> > I think you mean to set it as `current_user.is_authenticated = > > True`. > > > >> > > > > >> > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > > > >> > > Hello everyone, > > > >> > > I am trying to toggle between "Sign in" and > > "Sign > > > >> > > out" links using the current_user.is_authenticated variable such > > > that > > > >> > > when it returns False, the "Sign in" is displayed and when True > > the > > > >> > > "Sign out" link is displayed. At some point in the login code I > > set > > > >> > > current_user.authenticated = True. The thing is that by the I am > > > >> > > successfully logged in and presented with the next view, it is > the > > > >> > > "Sign in" link that is still displayed. When I check > > > >> > > current_user.is_authenticated, it returns False, even though I > had > > > >> > > explicitly set it to True. Please can anyone point out what I am > > > might > > > >> > > be doing wrong? Here is my code: > > > >> > > > > > >> > > I have a base.html file that contains the "Sign in" and "Sign > out" > > > >> > > links that is extended by the other templates: > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > {% block page_content %}{% endblock %} > > > >> > > > > > >> > > > > > >> > > > > > >> > > When the app first loads in the browser it displays a login > form, > > > >> > > login.html: > > > >> > > > > > >> > > {% extends "base.html" %} > > > >> > > > > > >> > > {% block content %} > > > >> > > {% import "bootstrap/wtf.html" as wtf %} > > > >> > > {% block title %}Flasky - Login{% endblock %} > > > >> > > {% block page_content %} > > > >> > > > > > >> > >
> > > >> > > {{ wtf.quick_form(form) }} > > > >> > >
> > > >> > > {% endblock %} > > > >> > > {% endblock %} > > > >> > > > > > >> > > When a user logs in, it loads a template dashboard.html that > > > displays > > > >> > > a map. The top part looks like this: > > > >> > > > > > >> > > {% extends "base.html" %} > > > >> > > > > > >> > > {% block page_content %} > > > >> > > > > > >> > > > > > >> > > Lagos Map > > > >> > > > > >> > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > > > >> > > > > > >> > > > > >> > > > > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > > >> > > crossorigin=""/> > > > >> > > > > > >> > > > > > >> > > > > >> > > href=" > > > >> > > > > >> > > > > > > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > > > >> " > > > >> > > > > >> > > /> > > > >> > > > > >> > > href=" > > > >> > > > > >> > > > > > > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > > > >> " > > > >> > > > > >> > > /> > > > >> > > > > > >> > > > > > >> > > ... > > > >> > > ... > > > >> > > > > > >> > > And these are the relevant routes: > > > >> > > > > > >> > > @app.route('/',methods=['GET','POST']) > > > >> > > def index(): > > > >> > > form = LoginForm() > > > >> > > if form.validate_on_submit(): > > > >> > > user = > > User.query.filter_by(email=form.email.data).first() > > > >> > > if user is not None and > > > >> > user.check_password(form.password.data): > > > >> > > user.authenticated = True > > > >> > > current_user = user > > > >> > > db.session.add(current_user) > > > >> > > db.session.commit() > > > >> > > login_user(current_user, form.remember_me.data) > > > >> > > return redirect(request.args.get('next') or > > > >> > > url_for('dashboard')) > > > >> > > flash('Invalid username or password.') > > > >> > > return render_template('auth/login.html', form=form) > > > >> > > > > > >> > > @app.route('/dashboard') > > > >> > > def dashboard(): > > > >> > > return render_template("dashboard.html") > > > >> > > > > > >> > > Thank you for your time. > > > >> > > > > > >> > > _______________________________________________ > > > >> > > Flask mailing list > > > >> > > Flask at python.org > > > >> > > https://mail.python.org/mailman/listinfo/flask > > > >> > > > > >> > -- > > > >> > -- Kind regards, > > > >> > Leni Kadali Mutungi > > > >> > > > > >> > _______________________________________________ > > > >> > Flask mailing list > > > >> > Flask at python.org > > > >> > https://mail.python.org/mailman/listinfo/flask > > > >> > > > > >> -------------- next part -------------- > > > >> An HTML attachment was scrubbed... > > > >> URL: < > > > >> > > > > > > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > > > >> > > > > >> > > > >> ------------------------------ > > > >> > > > >> Subject: Digest Footer > > > >> > > > >> _______________________________________________ > > > >> Flask mailing list > > > >> Flask at python.org > > > >> https://mail.python.org/mailman/listinfo/flask > > > >> > > > >> > > > >> ------------------------------ > > > >> > > > >> End of Flask Digest, Vol 49, Issue 5 > > > >> ************************************ > > > >> > > > > _______________________________________________ > > > > Flask mailing list > > > > Flask at python.org > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > -------------- next part -------------- > > > An HTML attachment was scrubbed... > > > URL: < > > > > > > http://mail.python.org/pipermail/flask/attachments/20190704/055df8bc/attachment.html > > > > > > > > > > ------------------------------ > > > > > > Subject: Digest Footer > > > > > > _______________________________________________ > > > Flask mailing list > > > Flask at python.org > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > > > ------------------------------ > > > > > > End of Flask Digest, Vol 49, Issue 6 > > > ************************************ > > > > > -------------- next part -------------- > > An HTML attachment was scrubbed... > > URL: < > > > http://mail.python.org/pipermail/flask/attachments/20190704/89bc8e49/attachment.html > > > > > > > ------------------------------ > > > > Subject: Digest Footer > > > > _______________________________________________ > > Flask mailing list > > Flask at python.org > > https://mail.python.org/mailman/listinfo/flask > > > > > > ------------------------------ > > > > End of Flask Digest, Vol 49, Issue 7 > > ************************************ > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/flask/attachments/20190704/04cbab56/attachment.html > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > > ------------------------------ > > End of Flask Digest, Vol 49, Issue 8 > ************************************ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sidwoodstock at gmail.com Mon Jul 8 13:00:34 2019 From: sidwoodstock at gmail.com (Scott Woodstock) Date: Mon, 8 Jul 2019 10:00:34 -0700 Subject: [Flask] Unable to set current_user.authenticated to True In-Reply-To: References: Message-ID: Because of what Gergely said, I went ahead and tested my suggestion to you since began doubting it would work. He is right, when not signed in Flask-Login returns an AnonymousUser rather than None. I was able to get my concept working by changing it as below, however, since Anonymous users do not have ID's. {% if current_user.id %}
Signout
{% else %}
Sign In
{% endif %} -Scott Woodstock On Mon, Jul 8, 2019 at 7:14 AM wrote: > Send Flask mailing list submissions to > flask at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/flask > or, via email, send a message with subject or body 'help' to > flask-request at python.org > > You can reach the person managing the list at > flask-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Flask digest..." > > > Today's Topics: > > 1. Re: Unable to set current_user.authenticated to True > (Abdul Mohammed) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Mon, 8 Jul 2019 15:14:18 +0100 > From: Abdul Mohammed > To: flask at python.org > Subject: Re: [Flask] Unable to set current_user.authenticated to True > Message-ID: > VuETw at mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > Many thanks Scott. Will try thia and let you know how it goes. > > On Thu, Jul 4, 2019 at 7:52 PM wrote: > > > Send Flask mailing list submissions to > > flask at python.org > > > > To subscribe or unsubscribe via the World Wide Web, visit > > https://mail.python.org/mailman/listinfo/flask > > or, via email, send a message with subject or body 'help' to > > flask-request at python.org > > > > You can reach the person managing the list at > > flask-owner at python.org > > > > When replying, please edit your Subject line so it is more specific > > than "Re: Contents of Flask digest..." > > > > > > Today's Topics: > > > > 1. Re: Unable to set current_user.authenticated to True > > (sidwoodstock .) > > > > > > ---------------------------------------------------------------------- > > > > Message: 1 > > Date: Thu, 4 Jul 2019 11:50:45 -0700 > > From: "sidwoodstock ." > > To: flask at python.org > > Subject: Re: [Flask] Unable to set current_user.authenticated to True > > Message-ID: > > < > > CALovGGOJSH0M8YkYkkfYV9AsyMOut_3SmR-OfPSYvrpqrLdtbQ at mail.gmail.com> > > Content-Type: text/plain; charset="utf-8" > > > > Ahh okay I understand now. > > > > I haven't tested this myself, but perhaps try {% if current_user %} as > your > > conditional since it ought to return None if no one is logged in. > > > > -Scott > > > > On Thu, Jul 4, 2019 at 8:56 AM wrote: > > > > > Send Flask mailing list submissions to > > > flask at python.org > > > > > > To subscribe or unsubscribe via the World Wide Web, visit > > > https://mail.python.org/mailman/listinfo/flask > > > or, via email, send a message with subject or body 'help' to > > > flask-request at python.org > > > > > > You can reach the person managing the list at > > > flask-owner at python.org > > > > > > When replying, please edit your Subject line so it is more specific > > > than "Re: Contents of Flask digest..." > > > > > > > > > Today's Topics: > > > > > > 1. Re: Flask Digest, Vol 49, Issue 5 (Abdul Mohammed) > > > 2. Re: Flask Digest, Vol 49, Issue 6 (Abdul Mohammed) > > > > > > > > > ---------------------------------------------------------------------- > > > > > > Message: 1 > > > Date: Thu, 4 Jul 2019 16:22:42 +0100 > > > From: Abdul Mohammed > > > To: flask at python.org > > > Subject: Re: [Flask] Flask Digest, Vol 49, Issue 5 > > > Message-ID: > > > < > > > CAEKkz85XoPnseQ9_jF_0WcfKDruXLAKKCBp4+2k_FogNA8zVcQ at mail.gmail.com> > > > Content-Type: text/plain; charset="utf-8" > > > > > > Thanks Gergely for the response. > > > Yes I am using Flask-Login and I think directly because this is how I > > > import it: > > > > > > from flask_login import login_user > > > > > > My problem is not that I can't log in. I can log in fine. The problem > is > > > essentially that I can not log out. I am trying to use the value of > > > current_user.is_authenticated to determine whether to show the "Sign > in" > > or > > > "Sign out" link. If True, it shows "Sign out" and "Sign in" when False. > > > For some reason, the value remains False after I have logged in so the > > > "Sign out" link never displays and so I am trapped in the app (Please > > save > > > me!!!) > > > because I can't log out. I hope I have made my problems clearer. > > > > > > Regards > > > > > > On Wed, Jul 3, 2019 at 5:04 PM wrote: > > > > > > > Send Flask mailing list submissions to > > > > flask at python.org > > > > > > > > To subscribe or unsubscribe via the World Wide Web, visit > > > > https://mail.python.org/mailman/listinfo/flask > > > > or, via email, send a message with subject or body 'help' to > > > > flask-request at python.org > > > > > > > > You can reach the person managing the list at > > > > flask-owner at python.org > > > > > > > > When replying, please edit your Subject line so it is more specific > > > > than "Re: Contents of Flask digest..." > > > > > > > > > > > > Today's Topics: > > > > > > > > 1. Re: Unable to set current_user.authenticated to True > > > > (Gergely Polonkai) > > > > > > > > > > > > > ---------------------------------------------------------------------- > > > > > > > > Message: 1 > > > > Date: Tue, 2 Jul 2019 19:01:20 +0200 > > > > From: Gergely Polonkai > > > > To: Leni Kadali Mutungi > > > > Cc: flask > > > > Subject: Re: [Flask] Unable to set current_user.authenticated to True > > > > Message-ID: > > > > > > > zxtk3bMO+n-+-y3Q at mail.gmail.com> > > > > Content-Type: text/plain; charset="utf-8" > > > > > > > > Hello, > > > > > > > > I assume you are using Flask-Login (either directly or via another > > > > extension like Flask-Security). If this is the case, you can import > > > > login_user and call it like login_user(user). > > > > > > > > If that does not work, you may want to check if the user is active > (ie. > > > not > > > > disabled), as it is the most common culprit when a user can?t be > logged > > > in. > > > > > > > > Best, > > > > Gergely > > > > > > > > On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < > lenikmutungi at gmail.com > > > > > > > wrote: > > > > > > > > > I think you mean to set it as `current_user.is_authenticated = > True`. > > > > > > > > > > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > > > > > > Hello everyone, > > > > > > I am trying to toggle between "Sign in" and > "Sign > > > > > > out" links using the current_user.is_authenticated variable such > > that > > > > > > when it returns False, the "Sign in" is displayed and when True > the > > > > > > "Sign out" link is displayed. At some point in the login code I > set > > > > > > current_user.authenticated = True. The thing is that by the I am > > > > > > successfully logged in and presented with the next view, it is > the > > > > > > "Sign in" link that is still displayed. When I check > > > > > > current_user.is_authenticated, it returns False, even though I > had > > > > > > explicitly set it to True. Please can anyone point out what I am > > > might > > > > > > be doing wrong? Here is my code: > > > > > > > > > > > > I have a base.html file that contains the "Sign in" and "Sign > out" > > > > > > links that is extended by the other templates: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > {% block page_content %}{% endblock %} > > > > > > > > > > > > > > > > > > > > > > > > When the app first loads in the browser it displays a login > form, > > > > > > login.html: > > > > > > > > > > > > {% extends "base.html" %} > > > > > > > > > > > > {% block content %} > > > > > > {% import "bootstrap/wtf.html" as wtf %} > > > > > > {% block title %}Flasky - Login{% endblock %} > > > > > > {% block page_content %} > > > > > > > > > > > >
> > > > > > {{ wtf.quick_form(form) }} > > > > > >
> > > > > > {% endblock %} > > > > > > {% endblock %} > > > > > > > > > > > > When a user logs in, it loads a template dashboard.html that > > displays > > > > > > a map. The top part looks like this: > > > > > > > > > > > > {% extends "base.html" %} > > > > > > > > > > > > {% block page_content %} > > > > > > > > > > > > > > > > > > Lagos Map > > > > > > > > > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > > > > > > > > > > > > > > > > > > > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > > > > > crossorigin=""/> > > > > > > > > > > > > > > > > > > > > > > > href=" > > > > > > > > > > > > > > > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > > > > " > > > > > > > > > > > /> > > > > > > > > > > > href=" > > > > > > > > > > > > > > > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > > > > " > > > > > > > > > > > /> > > > > > > > > > > > > > > > > > > ... > > > > > > ... > > > > > > > > > > > > And these are the relevant routes: > > > > > > > > > > > > @app.route('/',methods=['GET','POST']) > > > > > > def index(): > > > > > > form = LoginForm() > > > > > > if form.validate_on_submit(): > > > > > > user = > > User.query.filter_by(email=form.email.data).first() > > > > > > if user is not None and > > > > > user.check_password(form.password.data): > > > > > > user.authenticated = True > > > > > > current_user = user > > > > > > db.session.add(current_user) > > > > > > db.session.commit() > > > > > > login_user(current_user, form.remember_me.data) > > > > > > return redirect(request.args.get('next') or > > > > > > url_for('dashboard')) > > > > > > flash('Invalid username or password.') > > > > > > return render_template('auth/login.html', form=form) > > > > > > > > > > > > @app.route('/dashboard') > > > > > > def dashboard(): > > > > > > return render_template("dashboard.html") > > > > > > > > > > > > Thank you for your time. > > > > > > > > > > > > _______________________________________________ > > > > > > Flask mailing list > > > > > > Flask at python.org > > > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > > > > -- > > > > > -- Kind regards, > > > > > Leni Kadali Mutungi > > > > > > > > > > _______________________________________________ > > > > > Flask mailing list > > > > > Flask at python.org > > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > > > -------------- next part -------------- > > > > An HTML attachment was scrubbed... > > > > URL: < > > > > > > > > > > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > > > > > > > > > > > > > ------------------------------ > > > > > > > > Subject: Digest Footer > > > > > > > > _______________________________________________ > > > > Flask mailing list > > > > Flask at python.org > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > > > > > > ------------------------------ > > > > > > > > End of Flask Digest, Vol 49, Issue 5 > > > > ************************************ > > > > > > > -------------- next part -------------- > > > An HTML attachment was scrubbed... > > > URL: < > > > > > > http://mail.python.org/pipermail/flask/attachments/20190704/29797e8e/attachment-0001.html > > > > > > > > > > ------------------------------ > > > > > > Message: 2 > > > Date: Thu, 4 Jul 2019 16:55:18 +0100 > > > From: Abdul Mohammed > > > To: flask at python.org > > > Subject: Re: [Flask] Flask Digest, Vol 49, Issue 6 > > > Message-ID: > > > > > g at mail.gmail.com> > > > Content-Type: text/plain; charset="utf-8" > > > > > > Thanks Scott. > > > I just explained to Gergely that my problem is not logging in but > getting > > > the value of current_user.is_authenticated to change to True so that I > > > can log out. I wasn't originally doing the current_user = user > > assignment. > > > I could log in with either current_user or user. When the value of > > > current_user.is_authenticated wouldn't change to True, I added it > > because i > > > was just trying to see whether it would solve my problem. I will get > rid > > of > > > it > > > but the problem is likely to remain. > > > > > > On Thu, Jul 4, 2019 at 5:26 AM wrote: > > > > > > > Send Flask mailing list submissions to > > > > flask at python.org > > > > > > > > To subscribe or unsubscribe via the World Wide Web, visit > > > > https://mail.python.org/mailman/listinfo/flask > > > > or, via email, send a message with subject or body 'help' to > > > > flask-request at python.org > > > > > > > > You can reach the person managing the list at > > > > flask-owner at python.org > > > > > > > > When replying, please edit your Subject line so it is more specific > > > > than "Re: Contents of Flask digest..." > > > > > > > > > > > > Today's Topics: > > > > > > > > 1. Re: Unable to set current_user.authenticated to True > > > > (sidwoodstock .) > > > > 2. Re: Unable to set current_user.authenticated to True > > > > (Gergely Polonkai) > > > > > > > > > > > > > ---------------------------------------------------------------------- > > > > > > > > Message: 1 > > > > Date: Wed, 3 Jul 2019 09:19:20 -0700 > > > > From: "sidwoodstock ." > > > > To: flask at python.org > > > > Subject: Re: [Flask] Unable to set current_user.authenticated to True > > > > Message-ID: > > > > > > > KV78LHGK2k8hA at mail.gmail.com> > > > > Content-Type: text/plain; charset="utf-8" > > > > > > > > Also, if Gergely's suggestion doesn't work, you could try removing > your > > > > variable assignment of current_user = user. I see no practical reason > > to > > > do > > > > this, and since current_user is a built-in (and very handy) variable, > > > maybe > > > > that is somehow related to your issue? > > > > > > > > > > current_user = user > > > > > > > > and then just call login_user directly with your user you already > have > > at > > > > hand: > > > > > > > > > > login_user(user, form.remember_me.data) > > > > > > > > -Scott > > > > > > > > On Wed, Jul 3, 2019 at 9:03 AM wrote: > > > > > > > > > Send Flask mailing list submissions to > > > > > flask at python.org > > > > > > > > > > To subscribe or unsubscribe via the World Wide Web, visit > > > > > https://mail.python.org/mailman/listinfo/flask > > > > > or, via email, send a message with subject or body 'help' to > > > > > flask-request at python.org > > > > > > > > > > You can reach the person managing the list at > > > > > flask-owner at python.org > > > > > > > > > > When replying, please edit your Subject line so it is more specific > > > > > than "Re: Contents of Flask digest..." > > > > > > > > > > > > > > > Today's Topics: > > > > > > > > > > 1. Re: Unable to set current_user.authenticated to True > > > > > (Gergely Polonkai) > > > > > > > > > > > > > > > > > ---------------------------------------------------------------------- > > > > > > > > > > Message: 1 > > > > > Date: Tue, 2 Jul 2019 19:01:20 +0200 > > > > > From: Gergely Polonkai > > > > > To: Leni Kadali Mutungi > > > > > Cc: flask > > > > > Subject: Re: [Flask] Unable to set current_user.authenticated to > True > > > > > Message-ID: > > > > > > > > > zxtk3bMO+n-+-y3Q at mail.gmail.com> > > > > > Content-Type: text/plain; charset="utf-8" > > > > > > > > > > Hello, > > > > > > > > > > I assume you are using Flask-Login (either directly or via another > > > > > extension like Flask-Security). If this is the case, you can import > > > > > login_user and call it like login_user(user). > > > > > > > > > > If that does not work, you may want to check if the user is active > > (ie. > > > > not > > > > > disabled), as it is the most common culprit when a user can?t be > > logged > > > > in. > > > > > > > > > > Best, > > > > > Gergely > > > > > > > > > > On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < > > lenikmutungi at gmail.com > > > > > > > > > wrote: > > > > > > > > > > > I think you mean to set it as `current_user.is_authenticated = > > True`. > > > > > > > > > > > > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > > > > > > > Hello everyone, > > > > > > > I am trying to toggle between "Sign in" and > > "Sign > > > > > > > out" links using the current_user.is_authenticated variable > such > > > that > > > > > > > when it returns False, the "Sign in" is displayed and when True > > the > > > > > > > "Sign out" link is displayed. At some point in the login code I > > set > > > > > > > current_user.authenticated = True. The thing is that by the I > am > > > > > > > successfully logged in and presented with the next view, it is > > the > > > > > > > "Sign in" link that is still displayed. When I check > > > > > > > current_user.is_authenticated, it returns False, even though I > > had > > > > > > > explicitly set it to True. Please can anyone point out what I > am > > > > might > > > > > > > be doing wrong? Here is my code: > > > > > > > > > > > > > > I have a base.html file that contains the "Sign in" and "Sign > > out" > > > > > > > links that is extended by the other templates: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > {% block page_content %}{% endblock %} > > > > > > > > > > > > > > > > > > > > > > > > > > > > When the app first loads in the browser it displays a login > > form, > > > > > > > login.html: > > > > > > > > > > > > > > {% extends "base.html" %} > > > > > > > > > > > > > > {% block content %} > > > > > > > {% import "bootstrap/wtf.html" as wtf %} > > > > > > > {% block title %}Flasky - Login{% endblock %} > > > > > > > {% block page_content %} > > > > > > > > > > > > > >
> > > > > > > {{ wtf.quick_form(form) }} > > > > > > >
> > > > > > > {% endblock %} > > > > > > > {% endblock %} > > > > > > > > > > > > > > When a user logs in, it loads a template dashboard.html that > > > displays > > > > > > > a map. The top part looks like this: > > > > > > > > > > > > > > {% extends "base.html" %} > > > > > > > > > > > > > > {% block page_content %} > > > > > > > > > > > > > > > > > > > > > Lagos Map > > > > > > > > > > > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > > > > > > > > > > > > > > > > > > > > > > > > > > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > > > > > > crossorigin=""/> > > > > > > > > > > > > > > > > > > > > > > > > > > > href=" > > > > > > > > > > > > > > > > > > > > > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > > > > > " > > > > > > > > > > > > > /> > > > > > > > > > > > > > href=" > > > > > > > > > > > > > > > > > > > > > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > > > > > " > > > > > > > > > > > > > /> > > > > > > > > > > > > > > > > > > > > > ... > > > > > > > ... > > > > > > > > > > > > > > And these are the relevant routes: > > > > > > > > > > > > > > @app.route('/',methods=['GET','POST']) > > > > > > > def index(): > > > > > > > form = LoginForm() > > > > > > > if form.validate_on_submit(): > > > > > > > user = > > > User.query.filter_by(email=form.email.data).first() > > > > > > > if user is not None and > > > > > > user.check_password(form.password.data): > > > > > > > user.authenticated = True > > > > > > > current_user = user > > > > > > > db.session.add(current_user) > > > > > > > db.session.commit() > > > > > > > login_user(current_user, form.remember_me.data) > > > > > > > return redirect(request.args.get('next') or > > > > > > > url_for('dashboard')) > > > > > > > flash('Invalid username or password.') > > > > > > > return render_template('auth/login.html', form=form) > > > > > > > > > > > > > > @app.route('/dashboard') > > > > > > > def dashboard(): > > > > > > > return render_template("dashboard.html") > > > > > > > > > > > > > > Thank you for your time. > > > > > > > > > > > > > > _______________________________________________ > > > > > > > Flask mailing list > > > > > > > Flask at python.org > > > > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > > > > > > -- > > > > > > -- Kind regards, > > > > > > Leni Kadali Mutungi > > > > > > > > > > > > _______________________________________________ > > > > > > Flask mailing list > > > > > > Flask at python.org > > > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > > > > > -------------- next part -------------- > > > > > An HTML attachment was scrubbed... > > > > > URL: < > > > > > > > > > > > > > > > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > > > > > > > > > > > > > > > > ------------------------------ > > > > > > > > > > Subject: Digest Footer > > > > > > > > > > _______________________________________________ > > > > > Flask mailing list > > > > > Flask at python.org > > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > > > > > > > > > ------------------------------ > > > > > > > > > > End of Flask Digest, Vol 49, Issue 5 > > > > > ************************************ > > > > > > > > > -------------- next part -------------- > > > > An HTML attachment was scrubbed... > > > > URL: < > > > > > > > > > > http://mail.python.org/pipermail/flask/attachments/20190703/c47bb246/attachment-0001.html > > > > > > > > > > > > > ------------------------------ > > > > > > > > Message: 2 > > > > Date: Thu, 4 Jul 2019 06:25:40 +0200 > > > > From: Gergely Polonkai > > > > To: "sidwoodstock ." > > > > Cc: flask > > > > Subject: Re: [Flask] Unable to set current_user.authenticated to True > > > > Message-ID: > > > > < > > > > CACczBUJaj67qxPCEi9Tmjku42QDxDsuVLmEGQGuFaC2nndT7eA at mail.gmail.com> > > > > Content-Type: text/plain; charset="utf-8" > > > > > > > > No, modifying current_user directly is not possible (at least it > won?t > > > > propagate outside the function). current_user is a proxy object that > > > points > > > > to the logged in user in the current request. If you assign a > different > > > > value to it, its proxy nature goes away which is definitely not what > > you > > > > want: in extreme cases it might introduce security issues where users > > can > > > > access each the data of other. > > > > > > > > On Wed, 3 Jul 2019, 18:19 sidwoodstock ., > > > wrote: > > > > > > > > > Also, if Gergely's suggestion doesn't work, you could try removing > > your > > > > > variable assignment of current_user = user. I see no practical > reason > > > to > > > > do > > > > > this, and since current_user is a built-in (and very handy) > variable, > > > > maybe > > > > > that is somehow related to your issue? > > > > > > > > > > > > current_user = user > > > > > > > > > > and then just call login_user directly with your user you already > > have > > > at > > > > > hand: > > > > > > > > > > > > login_user(user, form.remember_me.data) > > > > > > > > > > -Scott > > > > > > > > > > On Wed, Jul 3, 2019 at 9:03 AM wrote: > > > > > > > > > >> Send Flask mailing list submissions to > > > > >> flask at python.org > > > > >> > > > > >> To subscribe or unsubscribe via the World Wide Web, visit > > > > >> https://mail.python.org/mailman/listinfo/flask > > > > >> or, via email, send a message with subject or body 'help' to > > > > >> flask-request at python.org > > > > >> > > > > >> You can reach the person managing the list at > > > > >> flask-owner at python.org > > > > >> > > > > >> When replying, please edit your Subject line so it is more > specific > > > > >> than "Re: Contents of Flask digest..." > > > > >> > > > > >> > > > > >> Today's Topics: > > > > >> > > > > >> 1. Re: Unable to set current_user.authenticated to True > > > > >> (Gergely Polonkai) > > > > >> > > > > >> > > > > >> > > ---------------------------------------------------------------------- > > > > >> > > > > >> Message: 1 > > > > >> Date: Tue, 2 Jul 2019 19:01:20 +0200 > > > > >> From: Gergely Polonkai > > > > >> To: Leni Kadali Mutungi > > > > >> Cc: flask > > > > >> Subject: Re: [Flask] Unable to set current_user.authenticated to > > True > > > > >> Message-ID: > > > > >> > > > >> zxtk3bMO+n-+-y3Q at mail.gmail.com> > > > > >> Content-Type: text/plain; charset="utf-8" > > > > >> > > > > >> Hello, > > > > >> > > > > >> I assume you are using Flask-Login (either directly or via another > > > > >> extension like Flask-Security). If this is the case, you can > import > > > > >> login_user and call it like login_user(user). > > > > >> > > > > >> If that does not work, you may want to check if the user is active > > > (ie. > > > > >> not > > > > >> disabled), as it is the most common culprit when a user can?t be > > > logged > > > > >> in. > > > > >> > > > > >> Best, > > > > >> Gergely > > > > >> > > > > >> On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < > > > lenikmutungi at gmail.com> > > > > >> wrote: > > > > >> > > > > >> > I think you mean to set it as `current_user.is_authenticated = > > > True`. > > > > >> > > > > > >> > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > > > > >> > > Hello everyone, > > > > >> > > I am trying to toggle between "Sign in" and > > > "Sign > > > > >> > > out" links using the current_user.is_authenticated variable > such > > > > that > > > > >> > > when it returns False, the "Sign in" is displayed and when > True > > > the > > > > >> > > "Sign out" link is displayed. At some point in the login code > I > > > set > > > > >> > > current_user.authenticated = True. The thing is that by the I > am > > > > >> > > successfully logged in and presented with the next view, it is > > the > > > > >> > > "Sign in" link that is still displayed. When I check > > > > >> > > current_user.is_authenticated, it returns False, even though I > > had > > > > >> > > explicitly set it to True. Please can anyone point out what I > am > > > > might > > > > >> > > be doing wrong? Here is my code: > > > > >> > > > > > > >> > > I have a base.html file that contains the "Sign in" and "Sign > > out" > > > > >> > > links that is extended by the other templates: > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > {% block page_content %}{% endblock %} > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > When the app first loads in the browser it displays a login > > form, > > > > >> > > login.html: > > > > >> > > > > > > >> > > {% extends "base.html" %} > > > > >> > > > > > > >> > > {% block content %} > > > > >> > > {% import "bootstrap/wtf.html" as wtf %} > > > > >> > > {% block title %}Flasky - Login{% endblock %} > > > > >> > > {% block page_content %} > > > > >> > > > > > > >> > >
> > > > >> > > {{ wtf.quick_form(form) }} > > > > >> > >
> > > > >> > > {% endblock %} > > > > >> > > {% endblock %} > > > > >> > > > > > > >> > > When a user logs in, it loads a template dashboard.html that > > > > displays > > > > >> > > a map. The top part looks like this: > > > > >> > > > > > > >> > > {% extends "base.html" %} > > > > >> > > > > > > >> > > {% block page_content %} > > > > >> > > > > > > >> > > > > > > >> > > Lagos Map > > > > >> > > > > > >> > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > > > > >> > > > > > > >> > > > > > >> > > > > > > > > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > > > >> > > crossorigin=""/> > > > > >> > > > > > > >> > > > > > > >> > > > > > >> > > href=" > > > > >> > > > > > >> > > > > > > > > > > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > > > > >> " > > > > >> > > > > > >> > > /> > > > > >> > > > > > >> > > href=" > > > > >> > > > > > >> > > > > > > > > > > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > > > > >> " > > > > >> > > > > > >> > > /> > > > > >> > > > > > > >> > > > > > > >> > > ... > > > > >> > > ... > > > > >> > > > > > > >> > > And these are the relevant routes: > > > > >> > > > > > > >> > > @app.route('/',methods=['GET','POST']) > > > > >> > > def index(): > > > > >> > > form = LoginForm() > > > > >> > > if form.validate_on_submit(): > > > > >> > > user = > > > User.query.filter_by(email=form.email.data).first() > > > > >> > > if user is not None and > > > > >> > user.check_password(form.password.data): > > > > >> > > user.authenticated = True > > > > >> > > current_user = user > > > > >> > > db.session.add(current_user) > > > > >> > > db.session.commit() > > > > >> > > login_user(current_user, form.remember_me.data) > > > > >> > > return redirect(request.args.get('next') or > > > > >> > > url_for('dashboard')) > > > > >> > > flash('Invalid username or password.') > > > > >> > > return render_template('auth/login.html', form=form) > > > > >> > > > > > > >> > > @app.route('/dashboard') > > > > >> > > def dashboard(): > > > > >> > > return render_template("dashboard.html") > > > > >> > > > > > > >> > > Thank you for your time. > > > > >> > > > > > > >> > > _______________________________________________ > > > > >> > > Flask mailing list > > > > >> > > Flask at python.org > > > > >> > > https://mail.python.org/mailman/listinfo/flask > > > > >> > > > > > >> > -- > > > > >> > -- Kind regards, > > > > >> > Leni Kadali Mutungi > > > > >> > > > > > >> > _______________________________________________ > > > > >> > Flask mailing list > > > > >> > Flask at python.org > > > > >> > https://mail.python.org/mailman/listinfo/flask > > > > >> > > > > > >> -------------- next part -------------- > > > > >> An HTML attachment was scrubbed... > > > > >> URL: < > > > > >> > > > > > > > > > > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > > > > >> > > > > > >> > > > > >> ------------------------------ > > > > >> > > > > >> Subject: Digest Footer > > > > >> > > > > >> _______________________________________________ > > > > >> Flask mailing list > > > > >> Flask at python.org > > > > >> https://mail.python.org/mailman/listinfo/flask > > > > >> > > > > >> > > > > >> ------------------------------ > > > > >> > > > > >> End of Flask Digest, Vol 49, Issue 5 > > > > >> ************************************ > > > > >> > > > > > _______________________________________________ > > > > > Flask mailing list > > > > > Flask at python.org > > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > > > > > > > On Wed, 3 Jul 2019, 18:19 sidwoodstock ., > > > wrote: > > > > > > > > > Also, if Gergely's suggestion doesn't work, you could try removing > > your > > > > > variable assignment of current_user = user. I see no practical > reason > > > to > > > > do > > > > > this, and since current_user is a built-in (and very handy) > variable, > > > > maybe > > > > > that is somehow related to your issue? > > > > > > > > > > > > current_user = user > > > > > > > > > > and then just call login_user directly with your user you already > > have > > > at > > > > > hand: > > > > > > > > > > > > login_user(user, form.remember_me.data) > > > > > > > > > > -Scott > > > > > > > > > > On Wed, Jul 3, 2019 at 9:03 AM wrote: > > > > > > > > > >> Send Flask mailing list submissions to > > > > >> flask at python.org > > > > >> > > > > >> To subscribe or unsubscribe via the World Wide Web, visit > > > > >> https://mail.python.org/mailman/listinfo/flask > > > > >> or, via email, send a message with subject or body 'help' to > > > > >> flask-request at python.org > > > > >> > > > > >> You can reach the person managing the list at > > > > >> flask-owner at python.org > > > > >> > > > > >> When replying, please edit your Subject line so it is more > specific > > > > >> than "Re: Contents of Flask digest..." > > > > >> > > > > >> > > > > >> Today's Topics: > > > > >> > > > > >> 1. Re: Unable to set current_user.authenticated to True > > > > >> (Gergely Polonkai) > > > > >> > > > > >> > > > > >> > > ---------------------------------------------------------------------- > > > > >> > > > > >> Message: 1 > > > > >> Date: Tue, 2 Jul 2019 19:01:20 +0200 > > > > >> From: Gergely Polonkai > > > > >> To: Leni Kadali Mutungi > > > > >> Cc: flask > > > > >> Subject: Re: [Flask] Unable to set current_user.authenticated to > > True > > > > >> Message-ID: > > > > >> > > > >> zxtk3bMO+n-+-y3Q at mail.gmail.com> > > > > >> Content-Type: text/plain; charset="utf-8" > > > > >> > > > > >> Hello, > > > > >> > > > > >> I assume you are using Flask-Login (either directly or via another > > > > >> extension like Flask-Security). If this is the case, you can > import > > > > >> login_user and call it like login_user(user). > > > > >> > > > > >> If that does not work, you may want to check if the user is active > > > (ie. > > > > >> not > > > > >> disabled), as it is the most common culprit when a user can?t be > > > logged > > > > >> in. > > > > >> > > > > >> Best, > > > > >> Gergely > > > > >> > > > > >> On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < > > > lenikmutungi at gmail.com> > > > > >> wrote: > > > > >> > > > > >> > I think you mean to set it as `current_user.is_authenticated = > > > True`. > > > > >> > > > > > >> > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > > > > >> > > Hello everyone, > > > > >> > > I am trying to toggle between "Sign in" and > > > "Sign > > > > >> > > out" links using the current_user.is_authenticated variable > such > > > > that > > > > >> > > when it returns False, the "Sign in" is displayed and when > True > > > the > > > > >> > > "Sign out" link is displayed. At some point in the login code > I > > > set > > > > >> > > current_user.authenticated = True. The thing is that by the I > am > > > > >> > > successfully logged in and presented with the next view, it is > > the > > > > >> > > "Sign in" link that is still displayed. When I check > > > > >> > > current_user.is_authenticated, it returns False, even though I > > had > > > > >> > > explicitly set it to True. Please can anyone point out what I > am > > > > might > > > > >> > > be doing wrong? Here is my code: > > > > >> > > > > > > >> > > I have a base.html file that contains the "Sign in" and "Sign > > out" > > > > >> > > links that is extended by the other templates: > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > {% block page_content %}{% endblock %} > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > When the app first loads in the browser it displays a login > > form, > > > > >> > > login.html: > > > > >> > > > > > > >> > > {% extends "base.html" %} > > > > >> > > > > > > >> > > {% block content %} > > > > >> > > {% import "bootstrap/wtf.html" as wtf %} > > > > >> > > {% block title %}Flasky - Login{% endblock %} > > > > >> > > {% block page_content %} > > > > >> > > > > > > >> > >
> > > > >> > > {{ wtf.quick_form(form) }} > > > > >> > >
> > > > >> > > {% endblock %} > > > > >> > > {% endblock %} > > > > >> > > > > > > >> > > When a user logs in, it loads a template dashboard.html that > > > > displays > > > > >> > > a map. The top part looks like this: > > > > >> > > > > > > >> > > {% extends "base.html" %} > > > > >> > > > > > > >> > > {% block page_content %} > > > > >> > > > > > > >> > > > > > > >> > > Lagos Map > > > > >> > > > > > >> > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > > > > >> > > > > > > >> > > > > > >> > > > > > > > > > > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > > > > >> > > crossorigin=""/> > > > > >> > > > > > > >> > > > > > > >> > > > > > >> > > href=" > > > > >> > > > > > >> > > > > > > > > > > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > > > > >> " > > > > >> > > > > > >> > > /> > > > > >> > > > > > >> > > href=" > > > > >> > > > > > >> > > > > > > > > > > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > > > > >> " > > > > >> > > > > > >> > > /> > > > > >> > > > > > > >> > > > > > > >> > > ... > > > > >> > > ... > > > > >> > > > > > > >> > > And these are the relevant routes: > > > > >> > > > > > > >> > > @app.route('/',methods=['GET','POST']) > > > > >> > > def index(): > > > > >> > > form = LoginForm() > > > > >> > > if form.validate_on_submit(): > > > > >> > > user = > > > User.query.filter_by(email=form.email.data).first() > > > > >> > > if user is not None and > > > > >> > user.check_password(form.password.data): > > > > >> > > user.authenticated = True > > > > >> > > current_user = user > > > > >> > > db.session.add(current_user) > > > > >> > > db.session.commit() > > > > >> > > login_user(current_user, form.remember_me.data) > > > > >> > > return redirect(request.args.get('next') or > > > > >> > > url_for('dashboard')) > > > > >> > > flash('Invalid username or password.') > > > > >> > > return render_template('auth/login.html', form=form) > > > > >> > > > > > > >> > > @app.route('/dashboard') > > > > >> > > def dashboard(): > > > > >> > > return render_template("dashboard.html") > > > > >> > > > > > > >> > > Thank you for your time. > > > > >> > > > > > > >> > > _______________________________________________ > > > > >> > > Flask mailing list > > > > >> > > Flask at python.org > > > > >> > > https://mail.python.org/mailman/listinfo/flask > > > > >> > > > > > >> > -- > > > > >> > -- Kind regards, > > > > >> > Leni Kadali Mutungi > > > > >> > > > > > >> > _______________________________________________ > > > > >> > Flask mailing list > > > > >> > Flask at python.org > > > > >> > https://mail.python.org/mailman/listinfo/flask > > > > >> > > > > > >> -------------- next part -------------- > > > > >> An HTML attachment was scrubbed... > > > > >> URL: < > > > > >> > > > > > > > > > > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > > > > >> > > > > > >> > > > > >> ------------------------------ > > > > >> > > > > >> Subject: Digest Footer > > > > >> > > > > >> _______________________________________________ > > > > >> Flask mailing list > > > > >> Flask at python.org > > > > >> https://mail.python.org/mailman/listinfo/flask > > > > >> > > > > >> > > > > >> ------------------------------ > > > > >> > > > > >> End of Flask Digest, Vol 49, Issue 5 > > > > >> ************************************ > > > > >> > > > > > _______________________________________________ > > > > > Flask mailing list > > > > > Flask at python.org > > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > > > -------------- next part -------------- > > > > An HTML attachment was scrubbed... > > > > URL: < > > > > > > > > > > http://mail.python.org/pipermail/flask/attachments/20190704/055df8bc/attachment.html > > > > > > > > > > > > > ------------------------------ > > > > > > > > Subject: Digest Footer > > > > > > > > _______________________________________________ > > > > Flask mailing list > > > > Flask at python.org > > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > > > > > > ------------------------------ > > > > > > > > End of Flask Digest, Vol 49, Issue 6 > > > > ************************************ > > > > > > > -------------- next part -------------- > > > An HTML attachment was scrubbed... > > > URL: < > > > > > > http://mail.python.org/pipermail/flask/attachments/20190704/89bc8e49/attachment.html > > > > > > > > > > ------------------------------ > > > > > > Subject: Digest Footer > > > > > > _______________________________________________ > > > Flask mailing list > > > Flask at python.org > > > https://mail.python.org/mailman/listinfo/flask > > > > > > > > > ------------------------------ > > > > > > End of Flask Digest, Vol 49, Issue 7 > > > ************************************ > > > > > -------------- next part -------------- > > An HTML attachment was scrubbed... > > URL: < > > > http://mail.python.org/pipermail/flask/attachments/20190704/04cbab56/attachment.html > > > > > > > ------------------------------ > > > > Subject: Digest Footer > > > > _______________________________________________ > > Flask mailing list > > Flask at python.org > > https://mail.python.org/mailman/listinfo/flask > > > > > > ------------------------------ > > > > End of Flask Digest, Vol 49, Issue 8 > > ************************************ > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/flask/attachments/20190708/47a60007/attachment.html > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > > ------------------------------ > > End of Flask Digest, Vol 49, Issue 11 > ************************************* > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gergely at polonkai.eu Tue Jul 9 02:55:20 2019 From: gergely at polonkai.eu (Gergely Polonkai) Date: Tue, 9 Jul 2019 08:55:20 +0200 Subject: [Flask] Unable to set current_user.authenticated to True In-Reply-To: References: Message-ID: I usually go with this snippet instead: {% if current_user.is_authenticated %} Login button {% else %} Logged in as {{ current_user}} Logout button {% endif %} Depending on your logic, a logged in user may not have an id property, or the anonymous user can have an id. is_authenticated is consistently available. Best, Gergely On Mon, 8 Jul 2019, 19:01 Scott Woodstock, wrote: > Because of what Gergely said, I went ahead and tested my suggestion to you > since began doubting it would work. He is right, when not signed in > Flask-Login returns an AnonymousUser rather than None. I was able to get my > concept working by changing it as below, however, since Anonymous users do > not have ID's. > > {% if current_user.id %} >
Signout
> {% else %} >
Sign In
> {% endif %} > > -Scott Woodstock > > On Mon, Jul 8, 2019 at 7:14 AM wrote: > >> Send Flask mailing list submissions to >> flask at python.org >> >> To subscribe or unsubscribe via the World Wide Web, visit >> https://mail.python.org/mailman/listinfo/flask >> or, via email, send a message with subject or body 'help' to >> flask-request at python.org >> >> You can reach the person managing the list at >> flask-owner at python.org >> >> When replying, please edit your Subject line so it is more specific >> than "Re: Contents of Flask digest..." >> >> >> Today's Topics: >> >> 1. Re: Unable to set current_user.authenticated to True >> (Abdul Mohammed) >> >> >> ---------------------------------------------------------------------- >> >> Message: 1 >> Date: Mon, 8 Jul 2019 15:14:18 +0100 >> From: Abdul Mohammed >> To: flask at python.org >> Subject: Re: [Flask] Unable to set current_user.authenticated to True >> Message-ID: >> > VuETw at mail.gmail.com> >> Content-Type: text/plain; charset="utf-8" >> >> Many thanks Scott. Will try thia and let you know how it goes. >> >> On Thu, Jul 4, 2019 at 7:52 PM wrote: >> >> > Send Flask mailing list submissions to >> > flask at python.org >> > >> > To subscribe or unsubscribe via the World Wide Web, visit >> > https://mail.python.org/mailman/listinfo/flask >> > or, via email, send a message with subject or body 'help' to >> > flask-request at python.org >> > >> > You can reach the person managing the list at >> > flask-owner at python.org >> > >> > When replying, please edit your Subject line so it is more specific >> > than "Re: Contents of Flask digest..." >> > >> > >> > Today's Topics: >> > >> > 1. Re: Unable to set current_user.authenticated to True >> > (sidwoodstock .) >> > >> > >> > ---------------------------------------------------------------------- >> > >> > Message: 1 >> > Date: Thu, 4 Jul 2019 11:50:45 -0700 >> > From: "sidwoodstock ." >> > To: flask at python.org >> > Subject: Re: [Flask] Unable to set current_user.authenticated to True >> > Message-ID: >> > < >> > CALovGGOJSH0M8YkYkkfYV9AsyMOut_3SmR-OfPSYvrpqrLdtbQ at mail.gmail.com> >> > Content-Type: text/plain; charset="utf-8" >> > >> > Ahh okay I understand now. >> > >> > I haven't tested this myself, but perhaps try {% if current_user %} as >> your >> > conditional since it ought to return None if no one is logged in. >> > >> > -Scott >> > >> > On Thu, Jul 4, 2019 at 8:56 AM wrote: >> > >> > > Send Flask mailing list submissions to >> > > flask at python.org >> > > >> > > To subscribe or unsubscribe via the World Wide Web, visit >> > > https://mail.python.org/mailman/listinfo/flask >> > > or, via email, send a message with subject or body 'help' to >> > > flask-request at python.org >> > > >> > > You can reach the person managing the list at >> > > flask-owner at python.org >> > > >> > > When replying, please edit your Subject line so it is more specific >> > > than "Re: Contents of Flask digest..." >> > > >> > > >> > > Today's Topics: >> > > >> > > 1. Re: Flask Digest, Vol 49, Issue 5 (Abdul Mohammed) >> > > 2. Re: Flask Digest, Vol 49, Issue 6 (Abdul Mohammed) >> > > >> > > >> > > ---------------------------------------------------------------------- >> > > >> > > Message: 1 >> > > Date: Thu, 4 Jul 2019 16:22:42 +0100 >> > > From: Abdul Mohammed >> > > To: flask at python.org >> > > Subject: Re: [Flask] Flask Digest, Vol 49, Issue 5 >> > > Message-ID: >> > > < >> > > CAEKkz85XoPnseQ9_jF_0WcfKDruXLAKKCBp4+2k_FogNA8zVcQ at mail.gmail.com> >> > > Content-Type: text/plain; charset="utf-8" >> > > >> > > Thanks Gergely for the response. >> > > Yes I am using Flask-Login and I think directly because this is how I >> > > import it: >> > > >> > > from flask_login import login_user >> > > >> > > My problem is not that I can't log in. I can log in fine. The problem >> is >> > > essentially that I can not log out. I am trying to use the value of >> > > current_user.is_authenticated to determine whether to show the "Sign >> in" >> > or >> > > "Sign out" link. If True, it shows "Sign out" and "Sign in" when >> False. >> > > For some reason, the value remains False after I have logged in so the >> > > "Sign out" link never displays and so I am trapped in the app (Please >> > save >> > > me!!!) >> > > because I can't log out. I hope I have made my problems clearer. >> > > >> > > Regards >> > > >> > > On Wed, Jul 3, 2019 at 5:04 PM wrote: >> > > >> > > > Send Flask mailing list submissions to >> > > > flask at python.org >> > > > >> > > > To subscribe or unsubscribe via the World Wide Web, visit >> > > > https://mail.python.org/mailman/listinfo/flask >> > > > or, via email, send a message with subject or body 'help' to >> > > > flask-request at python.org >> > > > >> > > > You can reach the person managing the list at >> > > > flask-owner at python.org >> > > > >> > > > When replying, please edit your Subject line so it is more specific >> > > > than "Re: Contents of Flask digest..." >> > > > >> > > > >> > > > Today's Topics: >> > > > >> > > > 1. Re: Unable to set current_user.authenticated to True >> > > > (Gergely Polonkai) >> > > > >> > > > >> > > > >> ---------------------------------------------------------------------- >> > > > >> > > > Message: 1 >> > > > Date: Tue, 2 Jul 2019 19:01:20 +0200 >> > > > From: Gergely Polonkai >> > > > To: Leni Kadali Mutungi >> > > > Cc: flask >> > > > Subject: Re: [Flask] Unable to set current_user.authenticated to >> True >> > > > Message-ID: >> > > > > > > > zxtk3bMO+n-+-y3Q at mail.gmail.com> >> > > > Content-Type: text/plain; charset="utf-8" >> > > > >> > > > Hello, >> > > > >> > > > I assume you are using Flask-Login (either directly or via another >> > > > extension like Flask-Security). If this is the case, you can import >> > > > login_user and call it like login_user(user). >> > > > >> > > > If that does not work, you may want to check if the user is active >> (ie. >> > > not >> > > > disabled), as it is the most common culprit when a user can?t be >> logged >> > > in. >> > > > >> > > > Best, >> > > > Gergely >> > > > >> > > > On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < >> lenikmutungi at gmail.com >> > > >> > > > wrote: >> > > > >> > > > > I think you mean to set it as `current_user.is_authenticated = >> True`. >> > > > > >> > > > > On 7/1/19 6:14 PM, Abdul Mohammed wrote: >> > > > > > Hello everyone, >> > > > > > I am trying to toggle between "Sign in" and >> "Sign >> > > > > > out" links using the current_user.is_authenticated variable such >> > that >> > > > > > when it returns False, the "Sign in" is displayed and when True >> the >> > > > > > "Sign out" link is displayed. At some point in the login code I >> set >> > > > > > current_user.authenticated = True. The thing is that by the I am >> > > > > > successfully logged in and presented with the next view, it is >> the >> > > > > > "Sign in" link that is still displayed. When I check >> > > > > > current_user.is_authenticated, it returns False, even though I >> had >> > > > > > explicitly set it to True. Please can anyone point out what I am >> > > might >> > > > > > be doing wrong? Here is my code: >> > > > > > >> > > > > > I have a base.html file that contains the "Sign in" and "Sign >> out" >> > > > > > links that is extended by the other templates: >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > {% block page_content %}{% endblock %} >> > > > > > >> > > > > > >> > > > > > >> > > > > > When the app first loads in the browser it displays a login >> form, >> > > > > > login.html: >> > > > > > >> > > > > > {% extends "base.html" %} >> > > > > > >> > > > > > {% block content %} >> > > > > > {% import "bootstrap/wtf.html" as wtf %} >> > > > > > {% block title %}Flasky - Login{% endblock %} >> > > > > > {% block page_content %} >> > > > > > >> > > > > >
>> > > > > > {{ wtf.quick_form(form) }} >> > > > > >
>> > > > > > {% endblock %} >> > > > > > {% endblock %} >> > > > > > >> > > > > > When a user logs in, it loads a template dashboard.html that >> > displays >> > > > > > a map. The top part looks like this: >> > > > > > >> > > > > > {% extends "base.html" %} >> > > > > > >> > > > > > {% block page_content %} >> > > > > > >> > > > > > >> > > > > > Lagos Map >> > > > > > > > > > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" >> > > > > > >> > > > > >> > > > >> > > >> > >> integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" >> > > > > > crossorigin=""/> >> > > > > > >> > > > > > >> > > > > > > > > > > > href=" >> > > > > >> > > > >> > > >> > >> https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css >> > > > " >> > > > > >> > > > > > /> >> > > > > > > > > > > > href=" >> > > > > >> > > > >> > > >> > >> https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css >> > > > " >> > > > > >> > > > > > /> >> > > > > > >> > > > > > >> > > > > > ... >> > > > > > ... >> > > > > > >> > > > > > And these are the relevant routes: >> > > > > > >> > > > > > @app.route('/',methods=['GET','POST']) >> > > > > > def index(): >> > > > > > form = LoginForm() >> > > > > > if form.validate_on_submit(): >> > > > > > user = >> > User.query.filter_by(email=form.email.data).first() >> > > > > > if user is not None and >> > > > > user.check_password(form.password.data): >> > > > > > user.authenticated = True >> > > > > > current_user = user >> > > > > > db.session.add(current_user) >> > > > > > db.session.commit() >> > > > > > login_user(current_user, form.remember_me.data) >> > > > > > return redirect(request.args.get('next') or >> > > > > > url_for('dashboard')) >> > > > > > flash('Invalid username or password.') >> > > > > > return render_template('auth/login.html', form=form) >> > > > > > >> > > > > > @app.route('/dashboard') >> > > > > > def dashboard(): >> > > > > > return render_template("dashboard.html") >> > > > > > >> > > > > > Thank you for your time. >> > > > > > >> > > > > > _______________________________________________ >> > > > > > Flask mailing list >> > > > > > Flask at python.org >> > > > > > https://mail.python.org/mailman/listinfo/flask >> > > > > >> > > > > -- >> > > > > -- Kind regards, >> > > > > Leni Kadali Mutungi >> > > > > >> > > > > _______________________________________________ >> > > > > Flask mailing list >> > > > > Flask at python.org >> > > > > https://mail.python.org/mailman/listinfo/flask >> > > > > >> > > > -------------- next part -------------- >> > > > An HTML attachment was scrubbed... >> > > > URL: < >> > > > >> > > >> > >> http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html >> > > > > >> > > > >> > > > ------------------------------ >> > > > >> > > > Subject: Digest Footer >> > > > >> > > > _______________________________________________ >> > > > Flask mailing list >> > > > Flask at python.org >> > > > https://mail.python.org/mailman/listinfo/flask >> > > > >> > > > >> > > > ------------------------------ >> > > > >> > > > End of Flask Digest, Vol 49, Issue 5 >> > > > ************************************ >> > > > >> > > -------------- next part -------------- >> > > An HTML attachment was scrubbed... >> > > URL: < >> > > >> > >> http://mail.python.org/pipermail/flask/attachments/20190704/29797e8e/attachment-0001.html >> > > > >> > > >> > > ------------------------------ >> > > >> > > Message: 2 >> > > Date: Thu, 4 Jul 2019 16:55:18 +0100 >> > > From: Abdul Mohammed >> > > To: flask at python.org >> > > Subject: Re: [Flask] Flask Digest, Vol 49, Issue 6 >> > > Message-ID: >> > > > > > g at mail.gmail.com> >> > > Content-Type: text/plain; charset="utf-8" >> > > >> > > Thanks Scott. >> > > I just explained to Gergely that my problem is not logging in but >> getting >> > > the value of current_user.is_authenticated to change to True so that I >> > > can log out. I wasn't originally doing the current_user = user >> > assignment. >> > > I could log in with either current_user or user. When the value of >> > > current_user.is_authenticated wouldn't change to True, I added it >> > because i >> > > was just trying to see whether it would solve my problem. I will get >> rid >> > of >> > > it >> > > but the problem is likely to remain. >> > > >> > > On Thu, Jul 4, 2019 at 5:26 AM wrote: >> > > >> > > > Send Flask mailing list submissions to >> > > > flask at python.org >> > > > >> > > > To subscribe or unsubscribe via the World Wide Web, visit >> > > > https://mail.python.org/mailman/listinfo/flask >> > > > or, via email, send a message with subject or body 'help' to >> > > > flask-request at python.org >> > > > >> > > > You can reach the person managing the list at >> > > > flask-owner at python.org >> > > > >> > > > When replying, please edit your Subject line so it is more specific >> > > > than "Re: Contents of Flask digest..." >> > > > >> > > > >> > > > Today's Topics: >> > > > >> > > > 1. Re: Unable to set current_user.authenticated to True >> > > > (sidwoodstock .) >> > > > 2. Re: Unable to set current_user.authenticated to True >> > > > (Gergely Polonkai) >> > > > >> > > > >> > > > >> ---------------------------------------------------------------------- >> > > > >> > > > Message: 1 >> > > > Date: Wed, 3 Jul 2019 09:19:20 -0700 >> > > > From: "sidwoodstock ." >> > > > To: flask at python.org >> > > > Subject: Re: [Flask] Unable to set current_user.authenticated to >> True >> > > > Message-ID: >> > > > > > > > KV78LHGK2k8hA at mail.gmail.com> >> > > > Content-Type: text/plain; charset="utf-8" >> > > > >> > > > Also, if Gergely's suggestion doesn't work, you could try removing >> your >> > > > variable assignment of current_user = user. I see no practical >> reason >> > to >> > > do >> > > > this, and since current_user is a built-in (and very handy) >> variable, >> > > maybe >> > > > that is somehow related to your issue? >> > > > >> > > > > > current_user = user >> > > > >> > > > and then just call login_user directly with your user you already >> have >> > at >> > > > hand: >> > > > >> > > > > > login_user(user, form.remember_me.data) >> > > > >> > > > -Scott >> > > > >> > > > On Wed, Jul 3, 2019 at 9:03 AM wrote: >> > > > >> > > > > Send Flask mailing list submissions to >> > > > > flask at python.org >> > > > > >> > > > > To subscribe or unsubscribe via the World Wide Web, visit >> > > > > https://mail.python.org/mailman/listinfo/flask >> > > > > or, via email, send a message with subject or body 'help' to >> > > > > flask-request at python.org >> > > > > >> > > > > You can reach the person managing the list at >> > > > > flask-owner at python.org >> > > > > >> > > > > When replying, please edit your Subject line so it is more >> specific >> > > > > than "Re: Contents of Flask digest..." >> > > > > >> > > > > >> > > > > Today's Topics: >> > > > > >> > > > > 1. Re: Unable to set current_user.authenticated to True >> > > > > (Gergely Polonkai) >> > > > > >> > > > > >> > > > > >> > ---------------------------------------------------------------------- >> > > > > >> > > > > Message: 1 >> > > > > Date: Tue, 2 Jul 2019 19:01:20 +0200 >> > > > > From: Gergely Polonkai >> > > > > To: Leni Kadali Mutungi >> > > > > Cc: flask >> > > > > Subject: Re: [Flask] Unable to set current_user.authenticated to >> True >> > > > > Message-ID: >> > > > > > > > > > zxtk3bMO+n-+-y3Q at mail.gmail.com> >> > > > > Content-Type: text/plain; charset="utf-8" >> > > > > >> > > > > Hello, >> > > > > >> > > > > I assume you are using Flask-Login (either directly or via another >> > > > > extension like Flask-Security). If this is the case, you can >> import >> > > > > login_user and call it like login_user(user). >> > > > > >> > > > > If that does not work, you may want to check if the user is active >> > (ie. >> > > > not >> > > > > disabled), as it is the most common culprit when a user can?t be >> > logged >> > > > in. >> > > > > >> > > > > Best, >> > > > > Gergely >> > > > > >> > > > > On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < >> > lenikmutungi at gmail.com >> > > > >> > > > > wrote: >> > > > > >> > > > > > I think you mean to set it as `current_user.is_authenticated = >> > True`. >> > > > > > >> > > > > > On 7/1/19 6:14 PM, Abdul Mohammed wrote: >> > > > > > > Hello everyone, >> > > > > > > I am trying to toggle between "Sign in" and >> > "Sign >> > > > > > > out" links using the current_user.is_authenticated variable >> such >> > > that >> > > > > > > when it returns False, the "Sign in" is displayed and when >> True >> > the >> > > > > > > "Sign out" link is displayed. At some point in the login code >> I >> > set >> > > > > > > current_user.authenticated = True. The thing is that by the I >> am >> > > > > > > successfully logged in and presented with the next view, it is >> > the >> > > > > > > "Sign in" link that is still displayed. When I check >> > > > > > > current_user.is_authenticated, it returns False, even though I >> > had >> > > > > > > explicitly set it to True. Please can anyone point out what I >> am >> > > > might >> > > > > > > be doing wrong? Here is my code: >> > > > > > > >> > > > > > > I have a base.html file that contains the "Sign in" and "Sign >> > out" >> > > > > > > links that is extended by the other templates: >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > {% block page_content %}{% endblock %} >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > When the app first loads in the browser it displays a login >> > form, >> > > > > > > login.html: >> > > > > > > >> > > > > > > {% extends "base.html" %} >> > > > > > > >> > > > > > > {% block content %} >> > > > > > > {% import "bootstrap/wtf.html" as wtf %} >> > > > > > > {% block title %}Flasky - Login{% endblock %} >> > > > > > > {% block page_content %} >> > > > > > > >> > > > > > >
>> > > > > > > {{ wtf.quick_form(form) }} >> > > > > > >
>> > > > > > > {% endblock %} >> > > > > > > {% endblock %} >> > > > > > > >> > > > > > > When a user logs in, it loads a template dashboard.html that >> > > displays >> > > > > > > a map. The top part looks like this: >> > > > > > > >> > > > > > > {% extends "base.html" %} >> > > > > > > >> > > > > > > {% block page_content %} >> > > > > > > >> > > > > > > >> > > > > > > Lagos Map >> > > > > > > > > > > > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" >> > > > > > > >> > > > > > >> > > > > >> > > > >> > > >> > >> integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" >> > > > > > > crossorigin=""/> >> > > > > > > >> > > > > > > >> > > > > > > > > > > > > > href=" >> > > > > > >> > > > > >> > > > >> > > >> > >> https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css >> > > > > " >> > > > > > >> > > > > > > /> >> > > > > > > > > > > > > > href=" >> > > > > > >> > > > > >> > > > >> > > >> > >> https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css >> > > > > " >> > > > > > >> > > > > > > /> >> > > > > > > >> > > > > > > >> > > > > > > ... >> > > > > > > ... >> > > > > > > >> > > > > > > And these are the relevant routes: >> > > > > > > >> > > > > > > @app.route('/',methods=['GET','POST']) >> > > > > > > def index(): >> > > > > > > form = LoginForm() >> > > > > > > if form.validate_on_submit(): >> > > > > > > user = >> > > User.query.filter_by(email=form.email.data).first() >> > > > > > > if user is not None and >> > > > > > user.check_password(form.password.data): >> > > > > > > user.authenticated = True >> > > > > > > current_user = user >> > > > > > > db.session.add(current_user) >> > > > > > > db.session.commit() >> > > > > > > login_user(current_user, form.remember_me.data) >> > > > > > > return redirect(request.args.get('next') or >> > > > > > > url_for('dashboard')) >> > > > > > > flash('Invalid username or password.') >> > > > > > > return render_template('auth/login.html', form=form) >> > > > > > > >> > > > > > > @app.route('/dashboard') >> > > > > > > def dashboard(): >> > > > > > > return render_template("dashboard.html") >> > > > > > > >> > > > > > > Thank you for your time. >> > > > > > > >> > > > > > > _______________________________________________ >> > > > > > > Flask mailing list >> > > > > > > Flask at python.org >> > > > > > > https://mail.python.org/mailman/listinfo/flask >> > > > > > >> > > > > > -- >> > > > > > -- Kind regards, >> > > > > > Leni Kadali Mutungi >> > > > > > >> > > > > > _______________________________________________ >> > > > > > Flask mailing list >> > > > > > Flask at python.org >> > > > > > https://mail.python.org/mailman/listinfo/flask >> > > > > > >> > > > > -------------- next part -------------- >> > > > > An HTML attachment was scrubbed... >> > > > > URL: < >> > > > > >> > > > >> > > >> > >> http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html >> > > > > > >> > > > > >> > > > > ------------------------------ >> > > > > >> > > > > Subject: Digest Footer >> > > > > >> > > > > _______________________________________________ >> > > > > Flask mailing list >> > > > > Flask at python.org >> > > > > https://mail.python.org/mailman/listinfo/flask >> > > > > >> > > > > >> > > > > ------------------------------ >> > > > > >> > > > > End of Flask Digest, Vol 49, Issue 5 >> > > > > ************************************ >> > > > > >> > > > -------------- next part -------------- >> > > > An HTML attachment was scrubbed... >> > > > URL: < >> > > > >> > > >> > >> http://mail.python.org/pipermail/flask/attachments/20190703/c47bb246/attachment-0001.html >> > > > > >> > > > >> > > > ------------------------------ >> > > > >> > > > Message: 2 >> > > > Date: Thu, 4 Jul 2019 06:25:40 +0200 >> > > > From: Gergely Polonkai >> > > > To: "sidwoodstock ." >> > > > Cc: flask >> > > > Subject: Re: [Flask] Unable to set current_user.authenticated to >> True >> > > > Message-ID: >> > > > < >> > > > CACczBUJaj67qxPCEi9Tmjku42QDxDsuVLmEGQGuFaC2nndT7eA at mail.gmail.com> >> > > > Content-Type: text/plain; charset="utf-8" >> > > > >> > > > No, modifying current_user directly is not possible (at least it >> won?t >> > > > propagate outside the function). current_user is a proxy object that >> > > points >> > > > to the logged in user in the current request. If you assign a >> different >> > > > value to it, its proxy nature goes away which is definitely not what >> > you >> > > > want: in extreme cases it might introduce security issues where >> users >> > can >> > > > access each the data of other. >> > > > >> > > > On Wed, 3 Jul 2019, 18:19 sidwoodstock ., >> > > wrote: >> > > > >> > > > > Also, if Gergely's suggestion doesn't work, you could try removing >> > your >> > > > > variable assignment of current_user = user. I see no practical >> reason >> > > to >> > > > do >> > > > > this, and since current_user is a built-in (and very handy) >> variable, >> > > > maybe >> > > > > that is somehow related to your issue? >> > > > > >> > > > > > > current_user = user >> > > > > >> > > > > and then just call login_user directly with your user you already >> > have >> > > at >> > > > > hand: >> > > > > >> > > > > > > login_user(user, form.remember_me.data) >> > > > > >> > > > > -Scott >> > > > > >> > > > > On Wed, Jul 3, 2019 at 9:03 AM wrote: >> > > > > >> > > > >> Send Flask mailing list submissions to >> > > > >> flask at python.org >> > > > >> >> > > > >> To subscribe or unsubscribe via the World Wide Web, visit >> > > > >> https://mail.python.org/mailman/listinfo/flask >> > > > >> or, via email, send a message with subject or body 'help' to >> > > > >> flask-request at python.org >> > > > >> >> > > > >> You can reach the person managing the list at >> > > > >> flask-owner at python.org >> > > > >> >> > > > >> When replying, please edit your Subject line so it is more >> specific >> > > > >> than "Re: Contents of Flask digest..." >> > > > >> >> > > > >> >> > > > >> Today's Topics: >> > > > >> >> > > > >> 1. Re: Unable to set current_user.authenticated to True >> > > > >> (Gergely Polonkai) >> > > > >> >> > > > >> >> > > > >> >> > ---------------------------------------------------------------------- >> > > > >> >> > > > >> Message: 1 >> > > > >> Date: Tue, 2 Jul 2019 19:01:20 +0200 >> > > > >> From: Gergely Polonkai >> > > > >> To: Leni Kadali Mutungi >> > > > >> Cc: flask >> > > > >> Subject: Re: [Flask] Unable to set current_user.authenticated to >> > True >> > > > >> Message-ID: >> > > > >> > > > > >> zxtk3bMO+n-+-y3Q at mail.gmail.com> >> > > > >> Content-Type: text/plain; charset="utf-8" >> > > > >> >> > > > >> Hello, >> > > > >> >> > > > >> I assume you are using Flask-Login (either directly or via >> another >> > > > >> extension like Flask-Security). If this is the case, you can >> import >> > > > >> login_user and call it like login_user(user). >> > > > >> >> > > > >> If that does not work, you may want to check if the user is >> active >> > > (ie. >> > > > >> not >> > > > >> disabled), as it is the most common culprit when a user can?t be >> > > logged >> > > > >> in. >> > > > >> >> > > > >> Best, >> > > > >> Gergely >> > > > >> >> > > > >> On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < >> > > lenikmutungi at gmail.com> >> > > > >> wrote: >> > > > >> >> > > > >> > I think you mean to set it as `current_user.is_authenticated = >> > > True`. >> > > > >> > >> > > > >> > On 7/1/19 6:14 PM, Abdul Mohammed wrote: >> > > > >> > > Hello everyone, >> > > > >> > > I am trying to toggle between "Sign in" and >> > > "Sign >> > > > >> > > out" links using the current_user.is_authenticated variable >> such >> > > > that >> > > > >> > > when it returns False, the "Sign in" is displayed and when >> True >> > > the >> > > > >> > > "Sign out" link is displayed. At some point in the login >> code I >> > > set >> > > > >> > > current_user.authenticated = True. The thing is that by the >> I am >> > > > >> > > successfully logged in and presented with the next view, it >> is >> > the >> > > > >> > > "Sign in" link that is still displayed. When I check >> > > > >> > > current_user.is_authenticated, it returns False, even though >> I >> > had >> > > > >> > > explicitly set it to True. Please can anyone point out what >> I am >> > > > might >> > > > >> > > be doing wrong? Here is my code: >> > > > >> > > >> > > > >> > > I have a base.html file that contains the "Sign in" and "Sign >> > out" >> > > > >> > > links that is extended by the other templates: >> > > > >> > > >> > > > >> > > >> > > > >> > > >> > > > >> > > >> > > > >> > > {% block page_content %}{% endblock %} >> > > > >> > > >> > > > >> > > >> > > > >> > > >> > > > >> > > When the app first loads in the browser it displays a login >> > form, >> > > > >> > > login.html: >> > > > >> > > >> > > > >> > > {% extends "base.html" %} >> > > > >> > > >> > > > >> > > {% block content %} >> > > > >> > > {% import "bootstrap/wtf.html" as wtf %} >> > > > >> > > {% block title %}Flasky - Login{% endblock %} >> > > > >> > > {% block page_content %} >> > > > >> > > >> > > > >> > >
>> > > > >> > > {{ wtf.quick_form(form) }} >> > > > >> > >
>> > > > >> > > {% endblock %} >> > > > >> > > {% endblock %} >> > > > >> > > >> > > > >> > > When a user logs in, it loads a template dashboard.html that >> > > > displays >> > > > >> > > a map. The top part looks like this: >> > > > >> > > >> > > > >> > > {% extends "base.html" %} >> > > > >> > > >> > > > >> > > {% block page_content %} >> > > > >> > > >> > > > >> > > >> > > > >> > > Lagos Map >> > > > >> > > > > > > >> > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" >> > > > >> > > >> > > > >> > >> > > > >> >> > > > >> > > >> > >> integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" >> > > > >> > > crossorigin=""/> >> > > > >> > > >> > > > >> > > >> > > > >> > > > > > > >> > > href=" >> > > > >> > >> > > > >> >> > > > >> > > >> > >> https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css >> > > > >> " >> > > > >> > >> > > > >> > > /> >> > > > >> > > > > > > >> > > href=" >> > > > >> > >> > > > >> >> > > > >> > > >> > >> https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css >> > > > >> " >> > > > >> > >> > > > >> > > /> >> > > > >> > > >> > > > >> > > >> > > > >> > > ... >> > > > >> > > ... >> > > > >> > > >> > > > >> > > And these are the relevant routes: >> > > > >> > > >> > > > >> > > @app.route('/',methods=['GET','POST']) >> > > > >> > > def index(): >> > > > >> > > form = LoginForm() >> > > > >> > > if form.validate_on_submit(): >> > > > >> > > user = >> > > User.query.filter_by(email=form.email.data).first() >> > > > >> > > if user is not None and >> > > > >> > user.check_password(form.password.data): >> > > > >> > > user.authenticated = True >> > > > >> > > current_user = user >> > > > >> > > db.session.add(current_user) >> > > > >> > > db.session.commit() >> > > > >> > > login_user(current_user, form.remember_me.data) >> > > > >> > > return redirect(request.args.get('next') or >> > > > >> > > url_for('dashboard')) >> > > > >> > > flash('Invalid username or password.') >> > > > >> > > return render_template('auth/login.html', form=form) >> > > > >> > > >> > > > >> > > @app.route('/dashboard') >> > > > >> > > def dashboard(): >> > > > >> > > return render_template("dashboard.html") >> > > > >> > > >> > > > >> > > Thank you for your time. >> > > > >> > > >> > > > >> > > _______________________________________________ >> > > > >> > > Flask mailing list >> > > > >> > > Flask at python.org >> > > > >> > > https://mail.python.org/mailman/listinfo/flask >> > > > >> > >> > > > >> > -- >> > > > >> > -- Kind regards, >> > > > >> > Leni Kadali Mutungi >> > > > >> > >> > > > >> > _______________________________________________ >> > > > >> > Flask mailing list >> > > > >> > Flask at python.org >> > > > >> > https://mail.python.org/mailman/listinfo/flask >> > > > >> > >> > > > >> -------------- next part -------------- >> > > > >> An HTML attachment was scrubbed... >> > > > >> URL: < >> > > > >> >> > > > >> > > >> > >> http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html >> > > > >> > >> > > > >> >> > > > >> ------------------------------ >> > > > >> >> > > > >> Subject: Digest Footer >> > > > >> >> > > > >> _______________________________________________ >> > > > >> Flask mailing list >> > > > >> Flask at python.org >> > > > >> https://mail.python.org/mailman/listinfo/flask >> > > > >> >> > > > >> >> > > > >> ------------------------------ >> > > > >> >> > > > >> End of Flask Digest, Vol 49, Issue 5 >> > > > >> ************************************ >> > > > >> >> > > > > _______________________________________________ >> > > > > Flask mailing list >> > > > > Flask at python.org >> > > > > https://mail.python.org/mailman/listinfo/flask >> > > > > >> > > > >> > > > On Wed, 3 Jul 2019, 18:19 sidwoodstock ., >> > > wrote: >> > > > >> > > > > Also, if Gergely's suggestion doesn't work, you could try removing >> > your >> > > > > variable assignment of current_user = user. I see no practical >> reason >> > > to >> > > > do >> > > > > this, and since current_user is a built-in (and very handy) >> variable, >> > > > maybe >> > > > > that is somehow related to your issue? >> > > > > >> > > > > > > current_user = user >> > > > > >> > > > > and then just call login_user directly with your user you already >> > have >> > > at >> > > > > hand: >> > > > > >> > > > > > > login_user(user, form.remember_me.data) >> > > > > >> > > > > -Scott >> > > > > >> > > > > On Wed, Jul 3, 2019 at 9:03 AM wrote: >> > > > > >> > > > >> Send Flask mailing list submissions to >> > > > >> flask at python.org >> > > > >> >> > > > >> To subscribe or unsubscribe via the World Wide Web, visit >> > > > >> https://mail.python.org/mailman/listinfo/flask >> > > > >> or, via email, send a message with subject or body 'help' to >> > > > >> flask-request at python.org >> > > > >> >> > > > >> You can reach the person managing the list at >> > > > >> flask-owner at python.org >> > > > >> >> > > > >> When replying, please edit your Subject line so it is more >> specific >> > > > >> than "Re: Contents of Flask digest..." >> > > > >> >> > > > >> >> > > > >> Today's Topics: >> > > > >> >> > > > >> 1. Re: Unable to set current_user.authenticated to True >> > > > >> (Gergely Polonkai) >> > > > >> >> > > > >> >> > > > >> >> > ---------------------------------------------------------------------- >> > > > >> >> > > > >> Message: 1 >> > > > >> Date: Tue, 2 Jul 2019 19:01:20 +0200 >> > > > >> From: Gergely Polonkai >> > > > >> To: Leni Kadali Mutungi >> > > > >> Cc: flask >> > > > >> Subject: Re: [Flask] Unable to set current_user.authenticated to >> > True >> > > > >> Message-ID: >> > > > >> > > > > >> zxtk3bMO+n-+-y3Q at mail.gmail.com> >> > > > >> Content-Type: text/plain; charset="utf-8" >> > > > >> >> > > > >> Hello, >> > > > >> >> > > > >> I assume you are using Flask-Login (either directly or via >> another >> > > > >> extension like Flask-Security). If this is the case, you can >> import >> > > > >> login_user and call it like login_user(user). >> > > > >> >> > > > >> If that does not work, you may want to check if the user is >> active >> > > (ie. >> > > > >> not >> > > > >> disabled), as it is the most common culprit when a user can?t be >> > > logged >> > > > >> in. >> > > > >> >> > > > >> Best, >> > > > >> Gergely >> > > > >> >> > > > >> On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < >> > > lenikmutungi at gmail.com> >> > > > >> wrote: >> > > > >> >> > > > >> > I think you mean to set it as `current_user.is_authenticated = >> > > True`. >> > > > >> > >> > > > >> > On 7/1/19 6:14 PM, Abdul Mohammed wrote: >> > > > >> > > Hello everyone, >> > > > >> > > I am trying to toggle between "Sign in" and >> > > "Sign >> > > > >> > > out" links using the current_user.is_authenticated variable >> such >> > > > that >> > > > >> > > when it returns False, the "Sign in" is displayed and when >> True >> > > the >> > > > >> > > "Sign out" link is displayed. At some point in the login >> code I >> > > set >> > > > >> > > current_user.authenticated = True. The thing is that by the >> I am >> > > > >> > > successfully logged in and presented with the next view, it >> is >> > the >> > > > >> > > "Sign in" link that is still displayed. When I check >> > > > >> > > current_user.is_authenticated, it returns False, even though >> I >> > had >> > > > >> > > explicitly set it to True. Please can anyone point out what >> I am >> > > > might >> > > > >> > > be doing wrong? Here is my code: >> > > > >> > > >> > > > >> > > I have a base.html file that contains the "Sign in" and "Sign >> > out" >> > > > >> > > links that is extended by the other templates: >> > > > >> > > >> > > > >> > > >> > > > >> > > >> > > > >> > > >> > > > >> > > {% block page_content %}{% endblock %} >> > > > >> > > >> > > > >> > > >> > > > >> > > >> > > > >> > > When the app first loads in the browser it displays a login >> > form, >> > > > >> > > login.html: >> > > > >> > > >> > > > >> > > {% extends "base.html" %} >> > > > >> > > >> > > > >> > > {% block content %} >> > > > >> > > {% import "bootstrap/wtf.html" as wtf %} >> > > > >> > > {% block title %}Flasky - Login{% endblock %} >> > > > >> > > {% block page_content %} >> > > > >> > > >> > > > >> > >
>> > > > >> > > {{ wtf.quick_form(form) }} >> > > > >> > >
>> > > > >> > > {% endblock %} >> > > > >> > > {% endblock %} >> > > > >> > > >> > > > >> > > When a user logs in, it loads a template dashboard.html that >> > > > displays >> > > > >> > > a map. The top part looks like this: >> > > > >> > > >> > > > >> > > {% extends "base.html" %} >> > > > >> > > >> > > > >> > > {% block page_content %} >> > > > >> > > >> > > > >> > > >> > > > >> > > Lagos Map >> > > > >> > > > > > > >> > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" >> > > > >> > > >> > > > >> > >> > > > >> >> > > > >> > > >> > >> integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" >> > > > >> > > crossorigin=""/> >> > > > >> > > >> > > > >> > > >> > > > >> > > > > > > >> > > href=" >> > > > >> > >> > > > >> >> > > > >> > > >> > >> https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css >> > > > >> " >> > > > >> > >> > > > >> > > /> >> > > > >> > > > > > > >> > > href=" >> > > > >> > >> > > > >> >> > > > >> > > >> > >> https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css >> > > > >> " >> > > > >> > >> > > > >> > > /> >> > > > >> > > >> > > > >> > > >> > > > >> > > ... >> > > > >> > > ... >> > > > >> > > >> > > > >> > > And these are the relevant routes: >> > > > >> > > >> > > > >> > > @app.route('/',methods=['GET','POST']) >> > > > >> > > def index(): >> > > > >> > > form = LoginForm() >> > > > >> > > if form.validate_on_submit(): >> > > > >> > > user = >> > > User.query.filter_by(email=form.email.data).first() >> > > > >> > > if user is not None and >> > > > >> > user.check_password(form.password.data): >> > > > >> > > user.authenticated = True >> > > > >> > > current_user = user >> > > > >> > > db.session.add(current_user) >> > > > >> > > db.session.commit() >> > > > >> > > login_user(current_user, form.remember_me.data) >> > > > >> > > return redirect(request.args.get('next') or >> > > > >> > > url_for('dashboard')) >> > > > >> > > flash('Invalid username or password.') >> > > > >> > > return render_template('auth/login.html', form=form) >> > > > >> > > >> > > > >> > > @app.route('/dashboard') >> > > > >> > > def dashboard(): >> > > > >> > > return render_template("dashboard.html") >> > > > >> > > >> > > > >> > > Thank you for your time. >> > > > >> > > >> > > > >> > > _______________________________________________ >> > > > >> > > Flask mailing list >> > > > >> > > Flask at python.org >> > > > >> > > https://mail.python.org/mailman/listinfo/flask >> > > > >> > >> > > > >> > -- >> > > > >> > -- Kind regards, >> > > > >> > Leni Kadali Mutungi >> > > > >> > >> > > > >> > _______________________________________________ >> > > > >> > Flask mailing list >> > > > >> > Flask at python.org >> > > > >> > https://mail.python.org/mailman/listinfo/flask >> > > > >> > >> > > > >> -------------- next part -------------- >> > > > >> An HTML attachment was scrubbed... >> > > > >> URL: < >> > > > >> >> > > > >> > > >> > >> http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html >> > > > >> > >> > > > >> >> > > > >> ------------------------------ >> > > > >> >> > > > >> Subject: Digest Footer >> > > > >> >> > > > >> _______________________________________________ >> > > > >> Flask mailing list >> > > > >> Flask at python.org >> > > > >> https://mail.python.org/mailman/listinfo/flask >> > > > >> >> > > > >> >> > > > >> ------------------------------ >> > > > >> >> > > > >> End of Flask Digest, Vol 49, Issue 5 >> > > > >> ************************************ >> > > > >> >> > > > > _______________________________________________ >> > > > > Flask mailing list >> > > > > Flask at python.org >> > > > > https://mail.python.org/mailman/listinfo/flask >> > > > > >> > > > -------------- next part -------------- >> > > > An HTML attachment was scrubbed... >> > > > URL: < >> > > > >> > > >> > >> http://mail.python.org/pipermail/flask/attachments/20190704/055df8bc/attachment.html >> > > > > >> > > > >> > > > ------------------------------ >> > > > >> > > > Subject: Digest Footer >> > > > >> > > > _______________________________________________ >> > > > Flask mailing list >> > > > Flask at python.org >> > > > https://mail.python.org/mailman/listinfo/flask >> > > > >> > > > >> > > > ------------------------------ >> > > > >> > > > End of Flask Digest, Vol 49, Issue 6 >> > > > ************************************ >> > > > >> > > -------------- next part -------------- >> > > An HTML attachment was scrubbed... >> > > URL: < >> > > >> > >> http://mail.python.org/pipermail/flask/attachments/20190704/89bc8e49/attachment.html >> > > > >> > > >> > > ------------------------------ >> > > >> > > Subject: Digest Footer >> > > >> > > _______________________________________________ >> > > Flask mailing list >> > > Flask at python.org >> > > https://mail.python.org/mailman/listinfo/flask >> > > >> > > >> > > ------------------------------ >> > > >> > > End of Flask Digest, Vol 49, Issue 7 >> > > ************************************ >> > > >> > -------------- next part -------------- >> > An HTML attachment was scrubbed... >> > URL: < >> > >> http://mail.python.org/pipermail/flask/attachments/20190704/04cbab56/attachment.html >> > > >> > >> > ------------------------------ >> > >> > Subject: Digest Footer >> > >> > _______________________________________________ >> > Flask mailing list >> > Flask at python.org >> > https://mail.python.org/mailman/listinfo/flask >> > >> > >> > ------------------------------ >> > >> > End of Flask Digest, Vol 49, Issue 8 >> > ************************************ >> > >> -------------- next part -------------- >> An HTML attachment was scrubbed... >> URL: < >> http://mail.python.org/pipermail/flask/attachments/20190708/47a60007/attachment.html >> > >> >> ------------------------------ >> >> Subject: Digest Footer >> >> _______________________________________________ >> Flask mailing list >> Flask at python.org >> https://mail.python.org/mailman/listinfo/flask >> >> >> ------------------------------ >> >> End of Flask Digest, Vol 49, Issue 11 >> ************************************* >> > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From imonikemohammed at gmail.com Tue Jul 9 11:29:21 2019 From: imonikemohammed at gmail.com (Abdul Mohammed) Date: Tue, 9 Jul 2019 16:29:21 +0100 Subject: [Flask] Unable to set current_user.authenticated to True In-Reply-To: References: Message-ID: Hi Gergely, Please I am not sure of how to implement your snippet. I did try but it did not come out right (The Logged in as {{ current_user}} came out as text on the login page). The page with the "Sign in" and "Sign out" links looks like this: Hi Scott, when I used {% if current_user.id %} it still only showed the "Sign in" link whether I was logged in or not. When I used {% if current_user %}, it was now only the "Sign out" link that showed whether I was logged in or not. Cheers!! On Tue, Jul 9, 2019 at 7:56 AM Gergely Polonkai wrote: > I usually go with this snippet instead: > > {% if current_user.is_authenticated %} > Login button > {% else %} > Logged in as {{ current_user}} Logout button > {% endif %} > > Depending on your logic, a logged in user may not have an id property, or > the anonymous user can have an id. is_authenticated is consistently > available. > > Best, > Gergely > > > On Mon, 8 Jul 2019, 19:01 Scott Woodstock, wrote: > >> Because of what Gergely said, I went ahead and tested my suggestion to >> you since began doubting it would work. He is right, when not signed in >> Flask-Login returns an AnonymousUser rather than None. I was able to get my >> concept working by changing it as below, however, since Anonymous users do >> not have ID's. >> >> {% if current_user.id %} >>
Signout
>> {% else %} >>
Sign In
>> {% endif %} >> >> -Scott Woodstock >> >> On Mon, Jul 8, 2019 at 7:14 AM wrote: >> >>> Send Flask mailing list submissions to >>> flask at python.org >>> >>> To subscribe or unsubscribe via the World Wide Web, visit >>> https://mail.python.org/mailman/listinfo/flask >>> or, via email, send a message with subject or body 'help' to >>> flask-request at python.org >>> >>> You can reach the person managing the list at >>> flask-owner at python.org >>> >>> When replying, please edit your Subject line so it is more specific >>> than "Re: Contents of Flask digest..." >>> >>> >>> Today's Topics: >>> >>> 1. Re: Unable to set current_user.authenticated to True >>> (Abdul Mohammed) >>> >>> >>> ---------------------------------------------------------------------- >>> >>> Message: 1 >>> Date: Mon, 8 Jul 2019 15:14:18 +0100 >>> From: Abdul Mohammed >>> To: flask at python.org >>> Subject: Re: [Flask] Unable to set current_user.authenticated to True >>> Message-ID: >>> >> VuETw at mail.gmail.com> >>> Content-Type: text/plain; charset="utf-8" >>> >>> Many thanks Scott. Will try thia and let you know how it goes. >>> >>> On Thu, Jul 4, 2019 at 7:52 PM wrote: >>> >>> > Send Flask mailing list submissions to >>> > flask at python.org >>> > >>> > To subscribe or unsubscribe via the World Wide Web, visit >>> > https://mail.python.org/mailman/listinfo/flask >>> > or, via email, send a message with subject or body 'help' to >>> > flask-request at python.org >>> > >>> > You can reach the person managing the list at >>> > flask-owner at python.org >>> > >>> > When replying, please edit your Subject line so it is more specific >>> > than "Re: Contents of Flask digest..." >>> > >>> > >>> > Today's Topics: >>> > >>> > 1. Re: Unable to set current_user.authenticated to True >>> > (sidwoodstock .) >>> > >>> > >>> > ---------------------------------------------------------------------- >>> > >>> > Message: 1 >>> > Date: Thu, 4 Jul 2019 11:50:45 -0700 >>> > From: "sidwoodstock ." >>> > To: flask at python.org >>> > Subject: Re: [Flask] Unable to set current_user.authenticated to True >>> > Message-ID: >>> > < >>> > CALovGGOJSH0M8YkYkkfYV9AsyMOut_3SmR-OfPSYvrpqrLdtbQ at mail.gmail.com> >>> > Content-Type: text/plain; charset="utf-8" >>> > >>> > Ahh okay I understand now. >>> > >>> > I haven't tested this myself, but perhaps try {% if current_user %} as >>> your >>> > conditional since it ought to return None if no one is logged in. >>> > >>> > -Scott >>> > >>> > On Thu, Jul 4, 2019 at 8:56 AM wrote: >>> > >>> > > Send Flask mailing list submissions to >>> > > flask at python.org >>> > > >>> > > To subscribe or unsubscribe via the World Wide Web, visit >>> > > https://mail.python.org/mailman/listinfo/flask >>> > > or, via email, send a message with subject or body 'help' to >>> > > flask-request at python.org >>> > > >>> > > You can reach the person managing the list at >>> > > flask-owner at python.org >>> > > >>> > > When replying, please edit your Subject line so it is more specific >>> > > than "Re: Contents of Flask digest..." >>> > > >>> > > >>> > > Today's Topics: >>> > > >>> > > 1. Re: Flask Digest, Vol 49, Issue 5 (Abdul Mohammed) >>> > > 2. Re: Flask Digest, Vol 49, Issue 6 (Abdul Mohammed) >>> > > >>> > > >>> > > >>> ---------------------------------------------------------------------- >>> > > >>> > > Message: 1 >>> > > Date: Thu, 4 Jul 2019 16:22:42 +0100 >>> > > From: Abdul Mohammed >>> > > To: flask at python.org >>> > > Subject: Re: [Flask] Flask Digest, Vol 49, Issue 5 >>> > > Message-ID: >>> > > < >>> > > CAEKkz85XoPnseQ9_jF_0WcfKDruXLAKKCBp4+2k_FogNA8zVcQ at mail.gmail.com> >>> > > Content-Type: text/plain; charset="utf-8" >>> > > >>> > > Thanks Gergely for the response. >>> > > Yes I am using Flask-Login and I think directly because this is how I >>> > > import it: >>> > > >>> > > from flask_login import login_user >>> > > >>> > > My problem is not that I can't log in. I can log in fine. The >>> problem is >>> > > essentially that I can not log out. I am trying to use the value of >>> > > current_user.is_authenticated to determine whether to show the "Sign >>> in" >>> > or >>> > > "Sign out" link. If True, it shows "Sign out" and "Sign in" when >>> False. >>> > > For some reason, the value remains False after I have logged in so >>> the >>> > > "Sign out" link never displays and so I am trapped in the app (Please >>> > save >>> > > me!!!) >>> > > because I can't log out. I hope I have made my problems clearer. >>> > > >>> > > Regards >>> > > >>> > > On Wed, Jul 3, 2019 at 5:04 PM wrote: >>> > > >>> > > > Send Flask mailing list submissions to >>> > > > flask at python.org >>> > > > >>> > > > To subscribe or unsubscribe via the World Wide Web, visit >>> > > > https://mail.python.org/mailman/listinfo/flask >>> > > > or, via email, send a message with subject or body 'help' to >>> > > > flask-request at python.org >>> > > > >>> > > > You can reach the person managing the list at >>> > > > flask-owner at python.org >>> > > > >>> > > > When replying, please edit your Subject line so it is more specific >>> > > > than "Re: Contents of Flask digest..." >>> > > > >>> > > > >>> > > > Today's Topics: >>> > > > >>> > > > 1. Re: Unable to set current_user.authenticated to True >>> > > > (Gergely Polonkai) >>> > > > >>> > > > >>> > > > >>> ---------------------------------------------------------------------- >>> > > > >>> > > > Message: 1 >>> > > > Date: Tue, 2 Jul 2019 19:01:20 +0200 >>> > > > From: Gergely Polonkai >>> > > > To: Leni Kadali Mutungi >>> > > > Cc: flask >>> > > > Subject: Re: [Flask] Unable to set current_user.authenticated to >>> True >>> > > > Message-ID: >>> > > > >> > > > zxtk3bMO+n-+-y3Q at mail.gmail.com> >>> > > > Content-Type: text/plain; charset="utf-8" >>> > > > >>> > > > Hello, >>> > > > >>> > > > I assume you are using Flask-Login (either directly or via another >>> > > > extension like Flask-Security). If this is the case, you can import >>> > > > login_user and call it like login_user(user). >>> > > > >>> > > > If that does not work, you may want to check if the user is active >>> (ie. >>> > > not >>> > > > disabled), as it is the most common culprit when a user can?t be >>> logged >>> > > in. >>> > > > >>> > > > Best, >>> > > > Gergely >>> > > > >>> > > > On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < >>> lenikmutungi at gmail.com >>> > > >>> > > > wrote: >>> > > > >>> > > > > I think you mean to set it as `current_user.is_authenticated = >>> True`. >>> > > > > >>> > > > > On 7/1/19 6:14 PM, Abdul Mohammed wrote: >>> > > > > > Hello everyone, >>> > > > > > I am trying to toggle between "Sign in" and >>> "Sign >>> > > > > > out" links using the current_user.is_authenticated variable >>> such >>> > that >>> > > > > > when it returns False, the "Sign in" is displayed and when >>> True the >>> > > > > > "Sign out" link is displayed. At some point in the login code >>> I set >>> > > > > > current_user.authenticated = True. The thing is that by the I >>> am >>> > > > > > successfully logged in and presented with the next view, it is >>> the >>> > > > > > "Sign in" link that is still displayed. When I check >>> > > > > > current_user.is_authenticated, it returns False, even though I >>> had >>> > > > > > explicitly set it to True. Please can anyone point out what I >>> am >>> > > might >>> > > > > > be doing wrong? Here is my code: >>> > > > > > >>> > > > > > I have a base.html file that contains the "Sign in" and "Sign >>> out" >>> > > > > > links that is extended by the other templates: >>> > > > > > >>> > > > > > >>> > > > > > >>> > > > > > >>> > > > > > {% block page_content %}{% endblock %} >>> > > > > > >>> > > > > > >>> > > > > > >>> > > > > > When the app first loads in the browser it displays a login >>> form, >>> > > > > > login.html: >>> > > > > > >>> > > > > > {% extends "base.html" %} >>> > > > > > >>> > > > > > {% block content %} >>> > > > > > {% import "bootstrap/wtf.html" as wtf %} >>> > > > > > {% block title %}Flasky - Login{% endblock %} >>> > > > > > {% block page_content %} >>> > > > > > >>> > > > > >
>>> > > > > > {{ wtf.quick_form(form) }} >>> > > > > >
>>> > > > > > {% endblock %} >>> > > > > > {% endblock %} >>> > > > > > >>> > > > > > When a user logs in, it loads a template dashboard.html that >>> > displays >>> > > > > > a map. The top part looks like this: >>> > > > > > >>> > > > > > {% extends "base.html" %} >>> > > > > > >>> > > > > > {% block page_content %} >>> > > > > > >>> > > > > > >>> > > > > > Lagos Map >>> > > > > > >> > > > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" >>> > > > > > >>> > > > > >>> > > > >>> > > >>> > >>> integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" >>> > > > > > crossorigin=""/> >>> > > > > > >>> > > > > > >>> > > > > > >> > > > > > href=" >>> > > > > >>> > > > >>> > > >>> > >>> https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css >>> > > > " >>> > > > > >>> > > > > > /> >>> > > > > > >> > > > > > href=" >>> > > > > >>> > > > >>> > > >>> > >>> https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css >>> > > > " >>> > > > > >>> > > > > > /> >>> > > > > > >>> > > > > > >>> > > > > > ... >>> > > > > > ... >>> > > > > > >>> > > > > > And these are the relevant routes: >>> > > > > > >>> > > > > > @app.route('/',methods=['GET','POST']) >>> > > > > > def index(): >>> > > > > > form = LoginForm() >>> > > > > > if form.validate_on_submit(): >>> > > > > > user = >>> > User.query.filter_by(email=form.email.data).first() >>> > > > > > if user is not None and >>> > > > > user.check_password(form.password.data): >>> > > > > > user.authenticated = True >>> > > > > > current_user = user >>> > > > > > db.session.add(current_user) >>> > > > > > db.session.commit() >>> > > > > > login_user(current_user, form.remember_me.data) >>> > > > > > return redirect(request.args.get('next') or >>> > > > > > url_for('dashboard')) >>> > > > > > flash('Invalid username or password.') >>> > > > > > return render_template('auth/login.html', form=form) >>> > > > > > >>> > > > > > @app.route('/dashboard') >>> > > > > > def dashboard(): >>> > > > > > return render_template("dashboard.html") >>> > > > > > >>> > > > > > Thank you for your time. >>> > > > > > >>> > > > > > _______________________________________________ >>> > > > > > Flask mailing list >>> > > > > > Flask at python.org >>> > > > > > https://mail.python.org/mailman/listinfo/flask >>> > > > > >>> > > > > -- >>> > > > > -- Kind regards, >>> > > > > Leni Kadali Mutungi >>> > > > > >>> > > > > _______________________________________________ >>> > > > > Flask mailing list >>> > > > > Flask at python.org >>> > > > > https://mail.python.org/mailman/listinfo/flask >>> > > > > >>> > > > -------------- next part -------------- >>> > > > An HTML attachment was scrubbed... >>> > > > URL: < >>> > > > >>> > > >>> > >>> http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html >>> > > > > >>> > > > >>> > > > ------------------------------ >>> > > > >>> > > > Subject: Digest Footer >>> > > > >>> > > > _______________________________________________ >>> > > > Flask mailing list >>> > > > Flask at python.org >>> > > > https://mail.python.org/mailman/listinfo/flask >>> > > > >>> > > > >>> > > > ------------------------------ >>> > > > >>> > > > End of Flask Digest, Vol 49, Issue 5 >>> > > > ************************************ >>> > > > >>> > > -------------- next part -------------- >>> > > An HTML attachment was scrubbed... >>> > > URL: < >>> > > >>> > >>> http://mail.python.org/pipermail/flask/attachments/20190704/29797e8e/attachment-0001.html >>> > > > >>> > > >>> > > ------------------------------ >>> > > >>> > > Message: 2 >>> > > Date: Thu, 4 Jul 2019 16:55:18 +0100 >>> > > From: Abdul Mohammed >>> > > To: flask at python.org >>> > > Subject: Re: [Flask] Flask Digest, Vol 49, Issue 6 >>> > > Message-ID: >>> > > >> > > g at mail.gmail.com> >>> > > Content-Type: text/plain; charset="utf-8" >>> > > >>> > > Thanks Scott. >>> > > I just explained to Gergely that my problem is not logging in but >>> getting >>> > > the value of current_user.is_authenticated to change to True so that >>> I >>> > > can log out. I wasn't originally doing the current_user = user >>> > assignment. >>> > > I could log in with either current_user or user. When the value of >>> > > current_user.is_authenticated wouldn't change to True, I added it >>> > because i >>> > > was just trying to see whether it would solve my problem. I will get >>> rid >>> > of >>> > > it >>> > > but the problem is likely to remain. >>> > > >>> > > On Thu, Jul 4, 2019 at 5:26 AM wrote: >>> > > >>> > > > Send Flask mailing list submissions to >>> > > > flask at python.org >>> > > > >>> > > > To subscribe or unsubscribe via the World Wide Web, visit >>> > > > https://mail.python.org/mailman/listinfo/flask >>> > > > or, via email, send a message with subject or body 'help' to >>> > > > flask-request at python.org >>> > > > >>> > > > You can reach the person managing the list at >>> > > > flask-owner at python.org >>> > > > >>> > > > When replying, please edit your Subject line so it is more specific >>> > > > than "Re: Contents of Flask digest..." >>> > > > >>> > > > >>> > > > Today's Topics: >>> > > > >>> > > > 1. Re: Unable to set current_user.authenticated to True >>> > > > (sidwoodstock .) >>> > > > 2. Re: Unable to set current_user.authenticated to True >>> > > > (Gergely Polonkai) >>> > > > >>> > > > >>> > > > >>> ---------------------------------------------------------------------- >>> > > > >>> > > > Message: 1 >>> > > > Date: Wed, 3 Jul 2019 09:19:20 -0700 >>> > > > From: "sidwoodstock ." >>> > > > To: flask at python.org >>> > > > Subject: Re: [Flask] Unable to set current_user.authenticated to >>> True >>> > > > Message-ID: >>> > > > >> > > > KV78LHGK2k8hA at mail.gmail.com> >>> > > > Content-Type: text/plain; charset="utf-8" >>> > > > >>> > > > Also, if Gergely's suggestion doesn't work, you could try removing >>> your >>> > > > variable assignment of current_user = user. I see no practical >>> reason >>> > to >>> > > do >>> > > > this, and since current_user is a built-in (and very handy) >>> variable, >>> > > maybe >>> > > > that is somehow related to your issue? >>> > > > >>> > > > > > current_user = user >>> > > > >>> > > > and then just call login_user directly with your user you already >>> have >>> > at >>> > > > hand: >>> > > > >>> > > > > > login_user(user, form.remember_me.data) >>> > > > >>> > > > -Scott >>> > > > >>> > > > On Wed, Jul 3, 2019 at 9:03 AM wrote: >>> > > > >>> > > > > Send Flask mailing list submissions to >>> > > > > flask at python.org >>> > > > > >>> > > > > To subscribe or unsubscribe via the World Wide Web, visit >>> > > > > https://mail.python.org/mailman/listinfo/flask >>> > > > > or, via email, send a message with subject or body 'help' to >>> > > > > flask-request at python.org >>> > > > > >>> > > > > You can reach the person managing the list at >>> > > > > flask-owner at python.org >>> > > > > >>> > > > > When replying, please edit your Subject line so it is more >>> specific >>> > > > > than "Re: Contents of Flask digest..." >>> > > > > >>> > > > > >>> > > > > Today's Topics: >>> > > > > >>> > > > > 1. Re: Unable to set current_user.authenticated to True >>> > > > > (Gergely Polonkai) >>> > > > > >>> > > > > >>> > > > > >>> > ---------------------------------------------------------------------- >>> > > > > >>> > > > > Message: 1 >>> > > > > Date: Tue, 2 Jul 2019 19:01:20 +0200 >>> > > > > From: Gergely Polonkai >>> > > > > To: Leni Kadali Mutungi >>> > > > > Cc: flask >>> > > > > Subject: Re: [Flask] Unable to set current_user.authenticated to >>> True >>> > > > > Message-ID: >>> > > > > >> > > > > zxtk3bMO+n-+-y3Q at mail.gmail.com> >>> > > > > Content-Type: text/plain; charset="utf-8" >>> > > > > >>> > > > > Hello, >>> > > > > >>> > > > > I assume you are using Flask-Login (either directly or via >>> another >>> > > > > extension like Flask-Security). If this is the case, you can >>> import >>> > > > > login_user and call it like login_user(user). >>> > > > > >>> > > > > If that does not work, you may want to check if the user is >>> active >>> > (ie. >>> > > > not >>> > > > > disabled), as it is the most common culprit when a user can?t be >>> > logged >>> > > > in. >>> > > > > >>> > > > > Best, >>> > > > > Gergely >>> > > > > >>> > > > > On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < >>> > lenikmutungi at gmail.com >>> > > > >>> > > > > wrote: >>> > > > > >>> > > > > > I think you mean to set it as `current_user.is_authenticated = >>> > True`. >>> > > > > > >>> > > > > > On 7/1/19 6:14 PM, Abdul Mohammed wrote: >>> > > > > > > Hello everyone, >>> > > > > > > I am trying to toggle between "Sign in" and >>> > "Sign >>> > > > > > > out" links using the current_user.is_authenticated variable >>> such >>> > > that >>> > > > > > > when it returns False, the "Sign in" is displayed and when >>> True >>> > the >>> > > > > > > "Sign out" link is displayed. At some point in the login >>> code I >>> > set >>> > > > > > > current_user.authenticated = True. The thing is that by the >>> I am >>> > > > > > > successfully logged in and presented with the next view, it >>> is >>> > the >>> > > > > > > "Sign in" link that is still displayed. When I check >>> > > > > > > current_user.is_authenticated, it returns False, even though >>> I >>> > had >>> > > > > > > explicitly set it to True. Please can anyone point out what >>> I am >>> > > > might >>> > > > > > > be doing wrong? Here is my code: >>> > > > > > > >>> > > > > > > I have a base.html file that contains the "Sign in" and "Sign >>> > out" >>> > > > > > > links that is extended by the other templates: >>> > > > > > > >>> > > > > > > >>> > > > > > > >>> > > > > > > >>> > > > > > > {% block page_content %}{% endblock %} >>> > > > > > > >>> > > > > > > >>> > > > > > > >>> > > > > > > When the app first loads in the browser it displays a login >>> > form, >>> > > > > > > login.html: >>> > > > > > > >>> > > > > > > {% extends "base.html" %} >>> > > > > > > >>> > > > > > > {% block content %} >>> > > > > > > {% import "bootstrap/wtf.html" as wtf %} >>> > > > > > > {% block title %}Flasky - Login{% endblock %} >>> > > > > > > {% block page_content %} >>> > > > > > > >>> > > > > > >
>>> > > > > > > {{ wtf.quick_form(form) }} >>> > > > > > >
>>> > > > > > > {% endblock %} >>> > > > > > > {% endblock %} >>> > > > > > > >>> > > > > > > When a user logs in, it loads a template dashboard.html that >>> > > displays >>> > > > > > > a map. The top part looks like this: >>> > > > > > > >>> > > > > > > {% extends "base.html" %} >>> > > > > > > >>> > > > > > > {% block page_content %} >>> > > > > > > >>> > > > > > > >>> > > > > > > Lagos Map >>> > > > > > > >> > > > > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" >>> > > > > > > >>> > > > > > >>> > > > > >>> > > > >>> > > >>> > >>> integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" >>> > > > > > > crossorigin=""/> >>> > > > > > > >>> > > > > > > >>> > > > > > > >> > > > > > > href=" >>> > > > > > >>> > > > > >>> > > > >>> > > >>> > >>> https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css >>> > > > > " >>> > > > > > >>> > > > > > > /> >>> > > > > > > >> > > > > > > href=" >>> > > > > > >>> > > > > >>> > > > >>> > > >>> > >>> https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css >>> > > > > " >>> > > > > > >>> > > > > > > /> >>> > > > > > > >>> > > > > > > >>> > > > > > > ... >>> > > > > > > ... >>> > > > > > > >>> > > > > > > And these are the relevant routes: >>> > > > > > > >>> > > > > > > @app.route('/',methods=['GET','POST']) >>> > > > > > > def index(): >>> > > > > > > form = LoginForm() >>> > > > > > > if form.validate_on_submit(): >>> > > > > > > user = >>> > > User.query.filter_by(email=form.email.data).first() >>> > > > > > > if user is not None and >>> > > > > > user.check_password(form.password.data): >>> > > > > > > user.authenticated = True >>> > > > > > > current_user = user >>> > > > > > > db.session.add(current_user) >>> > > > > > > db.session.commit() >>> > > > > > > login_user(current_user, form.remember_me.data) >>> > > > > > > return redirect(request.args.get('next') or >>> > > > > > > url_for('dashboard')) >>> > > > > > > flash('Invalid username or password.') >>> > > > > > > return render_template('auth/login.html', form=form) >>> > > > > > > >>> > > > > > > @app.route('/dashboard') >>> > > > > > > def dashboard(): >>> > > > > > > return render_template("dashboard.html") >>> > > > > > > >>> > > > > > > Thank you for your time. >>> > > > > > > >>> > > > > > > _______________________________________________ >>> > > > > > > Flask mailing list >>> > > > > > > Flask at python.org >>> > > > > > > https://mail.python.org/mailman/listinfo/flask >>> > > > > > >>> > > > > > -- >>> > > > > > -- Kind regards, >>> > > > > > Leni Kadali Mutungi >>> > > > > > >>> > > > > > _______________________________________________ >>> > > > > > Flask mailing list >>> > > > > > Flask at python.org >>> > > > > > https://mail.python.org/mailman/listinfo/flask >>> > > > > > >>> > > > > -------------- next part -------------- >>> > > > > An HTML attachment was scrubbed... >>> > > > > URL: < >>> > > > > >>> > > > >>> > > >>> > >>> http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html >>> > > > > > >>> > > > > >>> > > > > ------------------------------ >>> > > > > >>> > > > > Subject: Digest Footer >>> > > > > >>> > > > > _______________________________________________ >>> > > > > Flask mailing list >>> > > > > Flask at python.org >>> > > > > https://mail.python.org/mailman/listinfo/flask >>> > > > > >>> > > > > >>> > > > > ------------------------------ >>> > > > > >>> > > > > End of Flask Digest, Vol 49, Issue 5 >>> > > > > ************************************ >>> > > > > >>> > > > -------------- next part -------------- >>> > > > An HTML attachment was scrubbed... >>> > > > URL: < >>> > > > >>> > > >>> > >>> http://mail.python.org/pipermail/flask/attachments/20190703/c47bb246/attachment-0001.html >>> > > > > >>> > > > >>> > > > ------------------------------ >>> > > > >>> > > > Message: 2 >>> > > > Date: Thu, 4 Jul 2019 06:25:40 +0200 >>> > > > From: Gergely Polonkai >>> > > > To: "sidwoodstock ." >>> > > > Cc: flask >>> > > > Subject: Re: [Flask] Unable to set current_user.authenticated to >>> True >>> > > > Message-ID: >>> > > > < >>> > > > CACczBUJaj67qxPCEi9Tmjku42QDxDsuVLmEGQGuFaC2nndT7eA at mail.gmail.com >>> > >>> > > > Content-Type: text/plain; charset="utf-8" >>> > > > >>> > > > No, modifying current_user directly is not possible (at least it >>> won?t >>> > > > propagate outside the function). current_user is a proxy object >>> that >>> > > points >>> > > > to the logged in user in the current request. If you assign a >>> different >>> > > > value to it, its proxy nature goes away which is definitely not >>> what >>> > you >>> > > > want: in extreme cases it might introduce security issues where >>> users >>> > can >>> > > > access each the data of other. >>> > > > >>> > > > On Wed, 3 Jul 2019, 18:19 sidwoodstock ., >>> > > wrote: >>> > > > >>> > > > > Also, if Gergely's suggestion doesn't work, you could try >>> removing >>> > your >>> > > > > variable assignment of current_user = user. I see no practical >>> reason >>> > > to >>> > > > do >>> > > > > this, and since current_user is a built-in (and very handy) >>> variable, >>> > > > maybe >>> > > > > that is somehow related to your issue? >>> > > > > >>> > > > > > > current_user = user >>> > > > > >>> > > > > and then just call login_user directly with your user you already >>> > have >>> > > at >>> > > > > hand: >>> > > > > >>> > > > > > > login_user(user, form.remember_me.data) >>> > > > > >>> > > > > -Scott >>> > > > > >>> > > > > On Wed, Jul 3, 2019 at 9:03 AM wrote: >>> > > > > >>> > > > >> Send Flask mailing list submissions to >>> > > > >> flask at python.org >>> > > > >> >>> > > > >> To subscribe or unsubscribe via the World Wide Web, visit >>> > > > >> https://mail.python.org/mailman/listinfo/flask >>> > > > >> or, via email, send a message with subject or body 'help' to >>> > > > >> flask-request at python.org >>> > > > >> >>> > > > >> You can reach the person managing the list at >>> > > > >> flask-owner at python.org >>> > > > >> >>> > > > >> When replying, please edit your Subject line so it is more >>> specific >>> > > > >> than "Re: Contents of Flask digest..." >>> > > > >> >>> > > > >> >>> > > > >> Today's Topics: >>> > > > >> >>> > > > >> 1. Re: Unable to set current_user.authenticated to True >>> > > > >> (Gergely Polonkai) >>> > > > >> >>> > > > >> >>> > > > >> >>> > ---------------------------------------------------------------------- >>> > > > >> >>> > > > >> Message: 1 >>> > > > >> Date: Tue, 2 Jul 2019 19:01:20 +0200 >>> > > > >> From: Gergely Polonkai >>> > > > >> To: Leni Kadali Mutungi >>> > > > >> Cc: flask >>> > > > >> Subject: Re: [Flask] Unable to set current_user.authenticated to >>> > True >>> > > > >> Message-ID: >>> > > > >> >> > > > >> zxtk3bMO+n-+-y3Q at mail.gmail.com> >>> > > > >> Content-Type: text/plain; charset="utf-8" >>> > > > >> >>> > > > >> Hello, >>> > > > >> >>> > > > >> I assume you are using Flask-Login (either directly or via >>> another >>> > > > >> extension like Flask-Security). If this is the case, you can >>> import >>> > > > >> login_user and call it like login_user(user). >>> > > > >> >>> > > > >> If that does not work, you may want to check if the user is >>> active >>> > > (ie. >>> > > > >> not >>> > > > >> disabled), as it is the most common culprit when a user can?t be >>> > > logged >>> > > > >> in. >>> > > > >> >>> > > > >> Best, >>> > > > >> Gergely >>> > > > >> >>> > > > >> On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < >>> > > lenikmutungi at gmail.com> >>> > > > >> wrote: >>> > > > >> >>> > > > >> > I think you mean to set it as `current_user.is_authenticated = >>> > > True`. >>> > > > >> > >>> > > > >> > On 7/1/19 6:14 PM, Abdul Mohammed wrote: >>> > > > >> > > Hello everyone, >>> > > > >> > > I am trying to toggle between "Sign in" >>> and >>> > > "Sign >>> > > > >> > > out" links using the current_user.is_authenticated variable >>> such >>> > > > that >>> > > > >> > > when it returns False, the "Sign in" is displayed and when >>> True >>> > > the >>> > > > >> > > "Sign out" link is displayed. At some point in the login >>> code I >>> > > set >>> > > > >> > > current_user.authenticated = True. The thing is that by the >>> I am >>> > > > >> > > successfully logged in and presented with the next view, it >>> is >>> > the >>> > > > >> > > "Sign in" link that is still displayed. When I check >>> > > > >> > > current_user.is_authenticated, it returns False, even >>> though I >>> > had >>> > > > >> > > explicitly set it to True. Please can anyone point out what >>> I am >>> > > > might >>> > > > >> > > be doing wrong? Here is my code: >>> > > > >> > > >>> > > > >> > > I have a base.html file that contains the "Sign in" and >>> "Sign >>> > out" >>> > > > >> > > links that is extended by the other templates: >>> > > > >> > > >>> > > > >> > > >>> > > > >> > > >>> > > > >> > > >>> > > > >> > > {% block page_content %}{% endblock %} >>> > > > >> > > >>> > > > >> > > >>> > > > >> > > >>> > > > >> > > When the app first loads in the browser it displays a login >>> > form, >>> > > > >> > > login.html: >>> > > > >> > > >>> > > > >> > > {% extends "base.html" %} >>> > > > >> > > >>> > > > >> > > {% block content %} >>> > > > >> > > {% import "bootstrap/wtf.html" as wtf %} >>> > > > >> > > {% block title %}Flasky - Login{% endblock %} >>> > > > >> > > {% block page_content %} >>> > > > >> > > >>> > > > >> > >
>>> > > > >> > > {{ wtf.quick_form(form) }} >>> > > > >> > >
>>> > > > >> > > {% endblock %} >>> > > > >> > > {% endblock %} >>> > > > >> > > >>> > > > >> > > When a user logs in, it loads a template dashboard.html that >>> > > > displays >>> > > > >> > > a map. The top part looks like this: >>> > > > >> > > >>> > > > >> > > {% extends "base.html" %} >>> > > > >> > > >>> > > > >> > > {% block page_content %} >>> > > > >> > > >>> > > > >> > > >>> > > > >> > > Lagos Map >>> > > > >> > > >> > > > >> > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" >>> > > > >> > > >>> > > > >> > >>> > > > >> >>> > > > >>> > > >>> > >>> integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" >>> > > > >> > > crossorigin=""/> >>> > > > >> > > >>> > > > >> > > >>> > > > >> > > >> > > > >> > > href=" >>> > > > >> > >>> > > > >> >>> > > > >>> > > >>> > >>> https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css >>> > > > >> " >>> > > > >> > >>> > > > >> > > /> >>> > > > >> > > >> > > > >> > > href=" >>> > > > >> > >>> > > > >> >>> > > > >>> > > >>> > >>> https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css >>> > > > >> " >>> > > > >> > >>> > > > >> > > /> >>> > > > >> > > >>> > > > >> > > >>> > > > >> > > ... >>> > > > >> > > ... >>> > > > >> > > >>> > > > >> > > And these are the relevant routes: >>> > > > >> > > >>> > > > >> > > @app.route('/',methods=['GET','POST']) >>> > > > >> > > def index(): >>> > > > >> > > form = LoginForm() >>> > > > >> > > if form.validate_on_submit(): >>> > > > >> > > user = >>> > > User.query.filter_by(email=form.email.data).first() >>> > > > >> > > if user is not None and >>> > > > >> > user.check_password(form.password.data): >>> > > > >> > > user.authenticated = True >>> > > > >> > > current_user = user >>> > > > >> > > db.session.add(current_user) >>> > > > >> > > db.session.commit() >>> > > > >> > > login_user(current_user, >>> form.remember_me.data) >>> > > > >> > > return redirect(request.args.get('next') or >>> > > > >> > > url_for('dashboard')) >>> > > > >> > > flash('Invalid username or password.') >>> > > > >> > > return render_template('auth/login.html', form=form) >>> > > > >> > > >>> > > > >> > > @app.route('/dashboard') >>> > > > >> > > def dashboard(): >>> > > > >> > > return render_template("dashboard.html") >>> > > > >> > > >>> > > > >> > > Thank you for your time. >>> > > > >> > > >>> > > > >> > > _______________________________________________ >>> > > > >> > > Flask mailing list >>> > > > >> > > Flask at python.org >>> > > > >> > > https://mail.python.org/mailman/listinfo/flask >>> > > > >> > >>> > > > >> > -- >>> > > > >> > -- Kind regards, >>> > > > >> > Leni Kadali Mutungi >>> > > > >> > >>> > > > >> > _______________________________________________ >>> > > > >> > Flask mailing list >>> > > > >> > Flask at python.org >>> > > > >> > https://mail.python.org/mailman/listinfo/flask >>> > > > >> > >>> > > > >> -------------- next part -------------- >>> > > > >> An HTML attachment was scrubbed... >>> > > > >> URL: < >>> > > > >> >>> > > > >>> > > >>> > >>> http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html >>> > > > >> > >>> > > > >> >>> > > > >> ------------------------------ >>> > > > >> >>> > > > >> Subject: Digest Footer >>> > > > >> >>> > > > >> _______________________________________________ >>> > > > >> Flask mailing list >>> > > > >> Flask at python.org >>> > > > >> https://mail.python.org/mailman/listinfo/flask >>> > > > >> >>> > > > >> >>> > > > >> ------------------------------ >>> > > > >> >>> > > > >> End of Flask Digest, Vol 49, Issue 5 >>> > > > >> ************************************ >>> > > > >> >>> > > > > _______________________________________________ >>> > > > > Flask mailing list >>> > > > > Flask at python.org >>> > > > > https://mail.python.org/mailman/listinfo/flask >>> > > > > >>> > > > >>> > > > On Wed, 3 Jul 2019, 18:19 sidwoodstock ., >>> > > wrote: >>> > > > >>> > > > > Also, if Gergely's suggestion doesn't work, you could try >>> removing >>> > your >>> > > > > variable assignment of current_user = user. I see no practical >>> reason >>> > > to >>> > > > do >>> > > > > this, and since current_user is a built-in (and very handy) >>> variable, >>> > > > maybe >>> > > > > that is somehow related to your issue? >>> > > > > >>> > > > > > > current_user = user >>> > > > > >>> > > > > and then just call login_user directly with your user you already >>> > have >>> > > at >>> > > > > hand: >>> > > > > >>> > > > > > > login_user(user, form.remember_me.data) >>> > > > > >>> > > > > -Scott >>> > > > > >>> > > > > On Wed, Jul 3, 2019 at 9:03 AM wrote: >>> > > > > >>> > > > >> Send Flask mailing list submissions to >>> > > > >> flask at python.org >>> > > > >> >>> > > > >> To subscribe or unsubscribe via the World Wide Web, visit >>> > > > >> https://mail.python.org/mailman/listinfo/flask >>> > > > >> or, via email, send a message with subject or body 'help' to >>> > > > >> flask-request at python.org >>> > > > >> >>> > > > >> You can reach the person managing the list at >>> > > > >> flask-owner at python.org >>> > > > >> >>> > > > >> When replying, please edit your Subject line so it is more >>> specific >>> > > > >> than "Re: Contents of Flask digest..." >>> > > > >> >>> > > > >> >>> > > > >> Today's Topics: >>> > > > >> >>> > > > >> 1. Re: Unable to set current_user.authenticated to True >>> > > > >> (Gergely Polonkai) >>> > > > >> >>> > > > >> >>> > > > >> >>> > ---------------------------------------------------------------------- >>> > > > >> >>> > > > >> Message: 1 >>> > > > >> Date: Tue, 2 Jul 2019 19:01:20 +0200 >>> > > > >> From: Gergely Polonkai >>> > > > >> To: Leni Kadali Mutungi >>> > > > >> Cc: flask >>> > > > >> Subject: Re: [Flask] Unable to set current_user.authenticated to >>> > True >>> > > > >> Message-ID: >>> > > > >> >> > > > >> zxtk3bMO+n-+-y3Q at mail.gmail.com> >>> > > > >> Content-Type: text/plain; charset="utf-8" >>> > > > >> >>> > > > >> Hello, >>> > > > >> >>> > > > >> I assume you are using Flask-Login (either directly or via >>> another >>> > > > >> extension like Flask-Security). If this is the case, you can >>> import >>> > > > >> login_user and call it like login_user(user). >>> > > > >> >>> > > > >> If that does not work, you may want to check if the user is >>> active >>> > > (ie. >>> > > > >> not >>> > > > >> disabled), as it is the most common culprit when a user can?t be >>> > > logged >>> > > > >> in. >>> > > > >> >>> > > > >> Best, >>> > > > >> Gergely >>> > > > >> >>> > > > >> On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < >>> > > lenikmutungi at gmail.com> >>> > > > >> wrote: >>> > > > >> >>> > > > >> > I think you mean to set it as `current_user.is_authenticated = >>> > > True`. >>> > > > >> > >>> > > > >> > On 7/1/19 6:14 PM, Abdul Mohammed wrote: >>> > > > >> > > Hello everyone, >>> > > > >> > > I am trying to toggle between "Sign in" >>> and >>> > > "Sign >>> > > > >> > > out" links using the current_user.is_authenticated variable >>> such >>> > > > that >>> > > > >> > > when it returns False, the "Sign in" is displayed and when >>> True >>> > > the >>> > > > >> > > "Sign out" link is displayed. At some point in the login >>> code I >>> > > set >>> > > > >> > > current_user.authenticated = True. The thing is that by the >>> I am >>> > > > >> > > successfully logged in and presented with the next view, it >>> is >>> > the >>> > > > >> > > "Sign in" link that is still displayed. When I check >>> > > > >> > > current_user.is_authenticated, it returns False, even >>> though I >>> > had >>> > > > >> > > explicitly set it to True. Please can anyone point out what >>> I am >>> > > > might >>> > > > >> > > be doing wrong? Here is my code: >>> > > > >> > > >>> > > > >> > > I have a base.html file that contains the "Sign in" and >>> "Sign >>> > out" >>> > > > >> > > links that is extended by the other templates: >>> > > > >> > > >>> > > > >> > > >>> > > > >> > > >>> > > > >> > > >>> > > > >> > > {% block page_content %}{% endblock %} >>> > > > >> > > >>> > > > >> > > >>> > > > >> > > >>> > > > >> > > When the app first loads in the browser it displays a login >>> > form, >>> > > > >> > > login.html: >>> > > > >> > > >>> > > > >> > > {% extends "base.html" %} >>> > > > >> > > >>> > > > >> > > {% block content %} >>> > > > >> > > {% import "bootstrap/wtf.html" as wtf %} >>> > > > >> > > {% block title %}Flasky - Login{% endblock %} >>> > > > >> > > {% block page_content %} >>> > > > >> > > >>> > > > >> > >
>>> > > > >> > > {{ wtf.quick_form(form) }} >>> > > > >> > >
>>> > > > >> > > {% endblock %} >>> > > > >> > > {% endblock %} >>> > > > >> > > >>> > > > >> > > When a user logs in, it loads a template dashboard.html that >>> > > > displays >>> > > > >> > > a map. The top part looks like this: >>> > > > >> > > >>> > > > >> > > {% extends "base.html" %} >>> > > > >> > > >>> > > > >> > > {% block page_content %} >>> > > > >> > > >>> > > > >> > > >>> > > > >> > > Lagos Map >>> > > > >> > > >> > > > >> > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" >>> > > > >> > > >>> > > > >> > >>> > > > >> >>> > > > >>> > > >>> > >>> integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" >>> > > > >> > > crossorigin=""/> >>> > > > >> > > >>> > > > >> > > >>> > > > >> > > >> > > > >> > > href=" >>> > > > >> > >>> > > > >> >>> > > > >>> > > >>> > >>> https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css >>> > > > >> " >>> > > > >> > >>> > > > >> > > /> >>> > > > >> > > >> > > > >> > > href=" >>> > > > >> > >>> > > > >> >>> > > > >>> > > >>> > >>> https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css >>> > > > >> " >>> > > > >> > >>> > > > >> > > /> >>> > > > >> > > >>> > > > >> > > >>> > > > >> > > ... >>> > > > >> > > ... >>> > > > >> > > >>> > > > >> > > And these are the relevant routes: >>> > > > >> > > >>> > > > >> > > @app.route('/',methods=['GET','POST']) >>> > > > >> > > def index(): >>> > > > >> > > form = LoginForm() >>> > > > >> > > if form.validate_on_submit(): >>> > > > >> > > user = >>> > > User.query.filter_by(email=form.email.data).first() >>> > > > >> > > if user is not None and >>> > > > >> > user.check_password(form.password.data): >>> > > > >> > > user.authenticated = True >>> > > > >> > > current_user = user >>> > > > >> > > db.session.add(current_user) >>> > > > >> > > db.session.commit() >>> > > > >> > > login_user(current_user, >>> form.remember_me.data) >>> > > > >> > > return redirect(request.args.get('next') or >>> > > > >> > > url_for('dashboard')) >>> > > > >> > > flash('Invalid username or password.') >>> > > > >> > > return render_template('auth/login.html', form=form) >>> > > > >> > > >>> > > > >> > > @app.route('/dashboard') >>> > > > >> > > def dashboard(): >>> > > > >> > > return render_template("dashboard.html") >>> > > > >> > > >>> > > > >> > > Thank you for your time. >>> > > > >> > > >>> > > > >> > > _______________________________________________ >>> > > > >> > > Flask mailing list >>> > > > >> > > Flask at python.org >>> > > > >> > > https://mail.python.org/mailman/listinfo/flask >>> > > > >> > >>> > > > >> > -- >>> > > > >> > -- Kind regards, >>> > > > >> > Leni Kadali Mutungi >>> > > > >> > >>> > > > >> > _______________________________________________ >>> > > > >> > Flask mailing list >>> > > > >> > Flask at python.org >>> > > > >> > https://mail.python.org/mailman/listinfo/flask >>> > > > >> > >>> > > > >> -------------- next part -------------- >>> > > > >> An HTML attachment was scrubbed... >>> > > > >> URL: < >>> > > > >> >>> > > > >>> > > >>> > >>> http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html >>> > > > >> > >>> > > > >> >>> > > > >> ------------------------------ >>> > > > >> >>> > > > >> Subject: Digest Footer >>> > > > >> >>> > > > >> _______________________________________________ >>> > > > >> Flask mailing list >>> > > > >> Flask at python.org >>> > > > >> https://mail.python.org/mailman/listinfo/flask >>> > > > >> >>> > > > >> >>> > > > >> ------------------------------ >>> > > > >> >>> > > > >> End of Flask Digest, Vol 49, Issue 5 >>> > > > >> ************************************ >>> > > > >> >>> > > > > _______________________________________________ >>> > > > > Flask mailing list >>> > > > > Flask at python.org >>> > > > > https://mail.python.org/mailman/listinfo/flask >>> > > > > >>> > > > -------------- next part -------------- >>> > > > An HTML attachment was scrubbed... >>> > > > URL: < >>> > > > >>> > > >>> > >>> http://mail.python.org/pipermail/flask/attachments/20190704/055df8bc/attachment.html >>> > > > > >>> > > > >>> > > > ------------------------------ >>> > > > >>> > > > Subject: Digest Footer >>> > > > >>> > > > _______________________________________________ >>> > > > Flask mailing list >>> > > > Flask at python.org >>> > > > https://mail.python.org/mailman/listinfo/flask >>> > > > >>> > > > >>> > > > ------------------------------ >>> > > > >>> > > > End of Flask Digest, Vol 49, Issue 6 >>> > > > ************************************ >>> > > > >>> > > -------------- next part -------------- >>> > > An HTML attachment was scrubbed... >>> > > URL: < >>> > > >>> > >>> http://mail.python.org/pipermail/flask/attachments/20190704/89bc8e49/attachment.html >>> > > > >>> > > >>> > > ------------------------------ >>> > > >>> > > Subject: Digest Footer >>> > > >>> > > _______________________________________________ >>> > > Flask mailing list >>> > > Flask at python.org >>> > > https://mail.python.org/mailman/listinfo/flask >>> > > >>> > > >>> > > ------------------------------ >>> > > >>> > > End of Flask Digest, Vol 49, Issue 7 >>> > > ************************************ >>> > > >>> > -------------- next part -------------- >>> > An HTML attachment was scrubbed... >>> > URL: < >>> > >>> http://mail.python.org/pipermail/flask/attachments/20190704/04cbab56/attachment.html >>> > > >>> > >>> > ------------------------------ >>> > >>> > Subject: Digest Footer >>> > >>> > _______________________________________________ >>> > Flask mailing list >>> > Flask at python.org >>> > https://mail.python.org/mailman/listinfo/flask >>> > >>> > >>> > ------------------------------ >>> > >>> > End of Flask Digest, Vol 49, Issue 8 >>> > ************************************ >>> > >>> -------------- next part -------------- >>> An HTML attachment was scrubbed... >>> URL: < >>> http://mail.python.org/pipermail/flask/attachments/20190708/47a60007/attachment.html >>> > >>> >>> ------------------------------ >>> >>> Subject: Digest Footer >>> >>> _______________________________________________ >>> Flask mailing list >>> Flask at python.org >>> https://mail.python.org/mailman/listinfo/flask >>> >>> >>> ------------------------------ >>> >>> End of Flask Digest, Vol 49, Issue 11 >>> ************************************* >>> >> _______________________________________________ >> Flask mailing list >> Flask at python.org >> https://mail.python.org/mailman/listinfo/flask >> > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sidwoodstock at gmail.com Tue Jul 9 12:10:24 2019 From: sidwoodstock at gmail.com (Scott Woodstock) Date: Tue, 9 Jul 2019 09:10:24 -0700 Subject: [Flask] Unable to set current_user.authenticated to True In-Reply-To: References: Message-ID: My mistake. I recalled that Abdul had already tried that to no avail so I was attempting to find another way. I use an entirely different templates before and after login so this is something I hadn't had to do, but using id worked with my logic. I just tested {% if current_user.is_authenticated %} and it works as Gergely indicated, so if that isn't happening for you Abdul, then indeed we'll need more code to determine why. -Scott On Mon, Jul 8, 2019 at 11:56 PM wrote: > Send Flask mailing list submissions to > flask at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/flask > or, via email, send a message with subject or body 'help' to > flask-request at python.org > > You can reach the person managing the list at > flask-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Flask digest..." > > > Today's Topics: > > 1. Re: Unable to set current_user.authenticated to True > (Gergely Polonkai) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Tue, 9 Jul 2019 08:55:20 +0200 > From: Gergely Polonkai > To: "sidwoodstock ." > Cc: flask > Subject: Re: [Flask] Unable to set current_user.authenticated to True > Message-ID: > xtpa5kCesZ3hXn8Zm80DMBeO2qS4NMw at mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > I usually go with this snippet instead: > > {% if current_user.is_authenticated %} > Login button > {% else %} > Logged in as {{ current_user}} Logout button > {% endif %} > > Depending on your logic, a logged in user may not have an id property, or > the anonymous user can have an id. is_authenticated is consistently > available. > > Best, > Gergely > > > On Mon, 8 Jul 2019, 19:01 Scott Woodstock, wrote: > > > Because of what Gergely said, I went ahead and tested my suggestion to > you > > since began doubting it would work. He is right, when not signed in > > Flask-Login returns an AnonymousUser rather than None. I was able to get > my > > concept working by changing it as below, however, since Anonymous users > do > > not have ID's. > > > > {% if current_user.id %} > >
Signout
> > {% else %} > >
Sign In
> > {% endif %} > > > > -Scott Woodstock > > > > On Mon, Jul 8, 2019 at 7:14 AM wrote: > > > >> Send Flask mailing list submissions to > >> flask at python.org > >> > >> To subscribe or unsubscribe via the World Wide Web, visit > >> https://mail.python.org/mailman/listinfo/flask > >> or, via email, send a message with subject or body 'help' to > >> flask-request at python.org > >> > >> You can reach the person managing the list at > >> flask-owner at python.org > >> > >> When replying, please edit your Subject line so it is more specific > >> than "Re: Contents of Flask digest..." > >> > >> > >> Today's Topics: > >> > >> 1. Re: Unable to set current_user.authenticated to True > >> (Abdul Mohammed) > >> > >> > >> ---------------------------------------------------------------------- > >> > >> Message: 1 > >> Date: Mon, 8 Jul 2019 15:14:18 +0100 > >> From: Abdul Mohammed > >> To: flask at python.org > >> Subject: Re: [Flask] Unable to set current_user.authenticated to True > >> Message-ID: > >> >> VuETw at mail.gmail.com> > >> Content-Type: text/plain; charset="utf-8" > >> > >> Many thanks Scott. Will try thia and let you know how it goes. > >> > >> On Thu, Jul 4, 2019 at 7:52 PM wrote: > >> > >> > Send Flask mailing list submissions to > >> > flask at python.org > >> > > >> > To subscribe or unsubscribe via the World Wide Web, visit > >> > https://mail.python.org/mailman/listinfo/flask > >> > or, via email, send a message with subject or body 'help' to > >> > flask-request at python.org > >> > > >> > You can reach the person managing the list at > >> > flask-owner at python.org > >> > > >> > When replying, please edit your Subject line so it is more specific > >> > than "Re: Contents of Flask digest..." > >> > > >> > > >> > Today's Topics: > >> > > >> > 1. Re: Unable to set current_user.authenticated to True > >> > (sidwoodstock .) > >> > > >> > > >> > ---------------------------------------------------------------------- > >> > > >> > Message: 1 > >> > Date: Thu, 4 Jul 2019 11:50:45 -0700 > >> > From: "sidwoodstock ." > >> > To: flask at python.org > >> > Subject: Re: [Flask] Unable to set current_user.authenticated to True > >> > Message-ID: > >> > < > >> > CALovGGOJSH0M8YkYkkfYV9AsyMOut_3SmR-OfPSYvrpqrLdtbQ at mail.gmail.com> > >> > Content-Type: text/plain; charset="utf-8" > >> > > >> > Ahh okay I understand now. > >> > > >> > I haven't tested this myself, but perhaps try {% if current_user %} as > >> your > >> > conditional since it ought to return None if no one is logged in. > >> > > >> > -Scott > >> > > >> > On Thu, Jul 4, 2019 at 8:56 AM wrote: > >> > > >> > > Send Flask mailing list submissions to > >> > > flask at python.org > >> > > > >> > > To subscribe or unsubscribe via the World Wide Web, visit > >> > > https://mail.python.org/mailman/listinfo/flask > >> > > or, via email, send a message with subject or body 'help' to > >> > > flask-request at python.org > >> > > > >> > > You can reach the person managing the list at > >> > > flask-owner at python.org > >> > > > >> > > When replying, please edit your Subject line so it is more specific > >> > > than "Re: Contents of Flask digest..." > >> > > > >> > > > >> > > Today's Topics: > >> > > > >> > > 1. Re: Flask Digest, Vol 49, Issue 5 (Abdul Mohammed) > >> > > 2. Re: Flask Digest, Vol 49, Issue 6 (Abdul Mohammed) > >> > > > >> > > > >> > > > ---------------------------------------------------------------------- > >> > > > >> > > Message: 1 > >> > > Date: Thu, 4 Jul 2019 16:22:42 +0100 > >> > > From: Abdul Mohammed > >> > > To: flask at python.org > >> > > Subject: Re: [Flask] Flask Digest, Vol 49, Issue 5 > >> > > Message-ID: > >> > > < > >> > > CAEKkz85XoPnseQ9_jF_0WcfKDruXLAKKCBp4+2k_FogNA8zVcQ at mail.gmail.com> > >> > > Content-Type: text/plain; charset="utf-8" > >> > > > >> > > Thanks Gergely for the response. > >> > > Yes I am using Flask-Login and I think directly because this is how > I > >> > > import it: > >> > > > >> > > from flask_login import login_user > >> > > > >> > > My problem is not that I can't log in. I can log in fine. The > problem > >> is > >> > > essentially that I can not log out. I am trying to use the value of > >> > > current_user.is_authenticated to determine whether to show the "Sign > >> in" > >> > or > >> > > "Sign out" link. If True, it shows "Sign out" and "Sign in" when > >> False. > >> > > For some reason, the value remains False after I have logged in so > the > >> > > "Sign out" link never displays and so I am trapped in the app > (Please > >> > save > >> > > me!!!) > >> > > because I can't log out. I hope I have made my problems clearer. > >> > > > >> > > Regards > >> > > > >> > > On Wed, Jul 3, 2019 at 5:04 PM wrote: > >> > > > >> > > > Send Flask mailing list submissions to > >> > > > flask at python.org > >> > > > > >> > > > To subscribe or unsubscribe via the World Wide Web, visit > >> > > > https://mail.python.org/mailman/listinfo/flask > >> > > > or, via email, send a message with subject or body 'help' to > >> > > > flask-request at python.org > >> > > > > >> > > > You can reach the person managing the list at > >> > > > flask-owner at python.org > >> > > > > >> > > > When replying, please edit your Subject line so it is more > specific > >> > > > than "Re: Contents of Flask digest..." > >> > > > > >> > > > > >> > > > Today's Topics: > >> > > > > >> > > > 1. Re: Unable to set current_user.authenticated to True > >> > > > (Gergely Polonkai) > >> > > > > >> > > > > >> > > > > >> ---------------------------------------------------------------------- > >> > > > > >> > > > Message: 1 > >> > > > Date: Tue, 2 Jul 2019 19:01:20 +0200 > >> > > > From: Gergely Polonkai > >> > > > To: Leni Kadali Mutungi > >> > > > Cc: flask > >> > > > Subject: Re: [Flask] Unable to set current_user.authenticated to > >> True > >> > > > Message-ID: > >> > > > >> > > > zxtk3bMO+n-+-y3Q at mail.gmail.com> > >> > > > Content-Type: text/plain; charset="utf-8" > >> > > > > >> > > > Hello, > >> > > > > >> > > > I assume you are using Flask-Login (either directly or via another > >> > > > extension like Flask-Security). If this is the case, you can > import > >> > > > login_user and call it like login_user(user). > >> > > > > >> > > > If that does not work, you may want to check if the user is active > >> (ie. > >> > > not > >> > > > disabled), as it is the most common culprit when a user can?t be > >> logged > >> > > in. > >> > > > > >> > > > Best, > >> > > > Gergely > >> > > > > >> > > > On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < > >> lenikmutungi at gmail.com > >> > > > >> > > > wrote: > >> > > > > >> > > > > I think you mean to set it as `current_user.is_authenticated = > >> True`. > >> > > > > > >> > > > > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > >> > > > > > Hello everyone, > >> > > > > > I am trying to toggle between "Sign in" and > >> "Sign > >> > > > > > out" links using the current_user.is_authenticated variable > such > >> > that > >> > > > > > when it returns False, the "Sign in" is displayed and when > True > >> the > >> > > > > > "Sign out" link is displayed. At some point in the login code > I > >> set > >> > > > > > current_user.authenticated = True. The thing is that by the I > am > >> > > > > > successfully logged in and presented with the next view, it is > >> the > >> > > > > > "Sign in" link that is still displayed. When I check > >> > > > > > current_user.is_authenticated, it returns False, even though I > >> had > >> > > > > > explicitly set it to True. Please can anyone point out what I > am > >> > > might > >> > > > > > be doing wrong? Here is my code: > >> > > > > > > >> > > > > > I have a base.html file that contains the "Sign in" and "Sign > >> out" > >> > > > > > links that is extended by the other templates: > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > {% block page_content %}{% endblock %} > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > When the app first loads in the browser it displays a login > >> form, > >> > > > > > login.html: > >> > > > > > > >> > > > > > {% extends "base.html" %} > >> > > > > > > >> > > > > > {% block content %} > >> > > > > > {% import "bootstrap/wtf.html" as wtf %} > >> > > > > > {% block title %}Flasky - Login{% endblock %} > >> > > > > > {% block page_content %} > >> > > > > > > >> > > > > >
> >> > > > > > {{ wtf.quick_form(form) }} > >> > > > > >
> >> > > > > > {% endblock %} > >> > > > > > {% endblock %} > >> > > > > > > >> > > > > > When a user logs in, it loads a template dashboard.html that > >> > displays > >> > > > > > a map. The top part looks like this: > >> > > > > > > >> > > > > > {% extends "base.html" %} > >> > > > > > > >> > > > > > {% block page_content %} > >> > > > > > > >> > > > > > > >> > > > > > Lagos Map > >> > > > > > >> > > > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > >> > > > > > > >> > > > > > >> > > > > >> > > > >> > > >> > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > >> > > > > > crossorigin=""/> > >> > > > > > > >> > > > > > > >> > > > > > >> > > > > > href=" > >> > > > > > >> > > > > >> > > > >> > > >> > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > >> > > > " > >> > > > > > >> > > > > > /> > >> > > > > > >> > > > > > href=" > >> > > > > > >> > > > > >> > > > >> > > >> > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > >> > > > " > >> > > > > > >> > > > > > /> > >> > > > > > > >> > > > > > > >> > > > > > ... > >> > > > > > ... > >> > > > > > > >> > > > > > And these are the relevant routes: > >> > > > > > > >> > > > > > @app.route('/',methods=['GET','POST']) > >> > > > > > def index(): > >> > > > > > form = LoginForm() > >> > > > > > if form.validate_on_submit(): > >> > > > > > user = > >> > User.query.filter_by(email=form.email.data).first() > >> > > > > > if user is not None and > >> > > > > user.check_password(form.password.data): > >> > > > > > user.authenticated = True > >> > > > > > current_user = user > >> > > > > > db.session.add(current_user) > >> > > > > > db.session.commit() > >> > > > > > login_user(current_user, form.remember_me.data) > >> > > > > > return redirect(request.args.get('next') or > >> > > > > > url_for('dashboard')) > >> > > > > > flash('Invalid username or password.') > >> > > > > > return render_template('auth/login.html', form=form) > >> > > > > > > >> > > > > > @app.route('/dashboard') > >> > > > > > def dashboard(): > >> > > > > > return render_template("dashboard.html") > >> > > > > > > >> > > > > > Thank you for your time. > >> > > > > > > >> > > > > > _______________________________________________ > >> > > > > > Flask mailing list > >> > > > > > Flask at python.org > >> > > > > > https://mail.python.org/mailman/listinfo/flask > >> > > > > > >> > > > > -- > >> > > > > -- Kind regards, > >> > > > > Leni Kadali Mutungi > >> > > > > > >> > > > > _______________________________________________ > >> > > > > Flask mailing list > >> > > > > Flask at python.org > >> > > > > https://mail.python.org/mailman/listinfo/flask > >> > > > > > >> > > > -------------- next part -------------- > >> > > > An HTML attachment was scrubbed... > >> > > > URL: < > >> > > > > >> > > > >> > > >> > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > >> > > > > > >> > > > > >> > > > ------------------------------ > >> > > > > >> > > > Subject: Digest Footer > >> > > > > >> > > > _______________________________________________ > >> > > > Flask mailing list > >> > > > Flask at python.org > >> > > > https://mail.python.org/mailman/listinfo/flask > >> > > > > >> > > > > >> > > > ------------------------------ > >> > > > > >> > > > End of Flask Digest, Vol 49, Issue 5 > >> > > > ************************************ > >> > > > > >> > > -------------- next part -------------- > >> > > An HTML attachment was scrubbed... > >> > > URL: < > >> > > > >> > > >> > http://mail.python.org/pipermail/flask/attachments/20190704/29797e8e/attachment-0001.html > >> > > > > >> > > > >> > > ------------------------------ > >> > > > >> > > Message: 2 > >> > > Date: Thu, 4 Jul 2019 16:55:18 +0100 > >> > > From: Abdul Mohammed > >> > > To: flask at python.org > >> > > Subject: Re: [Flask] Flask Digest, Vol 49, Issue 6 > >> > > Message-ID: > >> > > >> > > g at mail.gmail.com> > >> > > Content-Type: text/plain; charset="utf-8" > >> > > > >> > > Thanks Scott. > >> > > I just explained to Gergely that my problem is not logging in but > >> getting > >> > > the value of current_user.is_authenticated to change to True so > that I > >> > > can log out. I wasn't originally doing the current_user = user > >> > assignment. > >> > > I could log in with either current_user or user. When the value of > >> > > current_user.is_authenticated wouldn't change to True, I added it > >> > because i > >> > > was just trying to see whether it would solve my problem. I will get > >> rid > >> > of > >> > > it > >> > > but the problem is likely to remain. > >> > > > >> > > On Thu, Jul 4, 2019 at 5:26 AM wrote: > >> > > > >> > > > Send Flask mailing list submissions to > >> > > > flask at python.org > >> > > > > >> > > > To subscribe or unsubscribe via the World Wide Web, visit > >> > > > https://mail.python.org/mailman/listinfo/flask > >> > > > or, via email, send a message with subject or body 'help' to > >> > > > flask-request at python.org > >> > > > > >> > > > You can reach the person managing the list at > >> > > > flask-owner at python.org > >> > > > > >> > > > When replying, please edit your Subject line so it is more > specific > >> > > > than "Re: Contents of Flask digest..." > >> > > > > >> > > > > >> > > > Today's Topics: > >> > > > > >> > > > 1. Re: Unable to set current_user.authenticated to True > >> > > > (sidwoodstock .) > >> > > > 2. Re: Unable to set current_user.authenticated to True > >> > > > (Gergely Polonkai) > >> > > > > >> > > > > >> > > > > >> ---------------------------------------------------------------------- > >> > > > > >> > > > Message: 1 > >> > > > Date: Wed, 3 Jul 2019 09:19:20 -0700 > >> > > > From: "sidwoodstock ." > >> > > > To: flask at python.org > >> > > > Subject: Re: [Flask] Unable to set current_user.authenticated to > >> True > >> > > > Message-ID: > >> > > > >> > > > KV78LHGK2k8hA at mail.gmail.com> > >> > > > Content-Type: text/plain; charset="utf-8" > >> > > > > >> > > > Also, if Gergely's suggestion doesn't work, you could try removing > >> your > >> > > > variable assignment of current_user = user. I see no practical > >> reason > >> > to > >> > > do > >> > > > this, and since current_user is a built-in (and very handy) > >> variable, > >> > > maybe > >> > > > that is somehow related to your issue? > >> > > > > >> > > > > > current_user = user > >> > > > > >> > > > and then just call login_user directly with your user you already > >> have > >> > at > >> > > > hand: > >> > > > > >> > > > > > login_user(user, form.remember_me.data) > >> > > > > >> > > > -Scott > >> > > > > >> > > > On Wed, Jul 3, 2019 at 9:03 AM wrote: > >> > > > > >> > > > > Send Flask mailing list submissions to > >> > > > > flask at python.org > >> > > > > > >> > > > > To subscribe or unsubscribe via the World Wide Web, visit > >> > > > > https://mail.python.org/mailman/listinfo/flask > >> > > > > or, via email, send a message with subject or body 'help' to > >> > > > > flask-request at python.org > >> > > > > > >> > > > > You can reach the person managing the list at > >> > > > > flask-owner at python.org > >> > > > > > >> > > > > When replying, please edit your Subject line so it is more > >> specific > >> > > > > than "Re: Contents of Flask digest..." > >> > > > > > >> > > > > > >> > > > > Today's Topics: > >> > > > > > >> > > > > 1. Re: Unable to set current_user.authenticated to True > >> > > > > (Gergely Polonkai) > >> > > > > > >> > > > > > >> > > > > > >> > ---------------------------------------------------------------------- > >> > > > > > >> > > > > Message: 1 > >> > > > > Date: Tue, 2 Jul 2019 19:01:20 +0200 > >> > > > > From: Gergely Polonkai > >> > > > > To: Leni Kadali Mutungi > >> > > > > Cc: flask > >> > > > > Subject: Re: [Flask] Unable to set current_user.authenticated to > >> True > >> > > > > Message-ID: > >> > > > > >> > > > > zxtk3bMO+n-+-y3Q at mail.gmail.com> > >> > > > > Content-Type: text/plain; charset="utf-8" > >> > > > > > >> > > > > Hello, > >> > > > > > >> > > > > I assume you are using Flask-Login (either directly or via > another > >> > > > > extension like Flask-Security). If this is the case, you can > >> import > >> > > > > login_user and call it like login_user(user). > >> > > > > > >> > > > > If that does not work, you may want to check if the user is > active > >> > (ie. > >> > > > not > >> > > > > disabled), as it is the most common culprit when a user can?t be > >> > logged > >> > > > in. > >> > > > > > >> > > > > Best, > >> > > > > Gergely > >> > > > > > >> > > > > On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < > >> > lenikmutungi at gmail.com > >> > > > > >> > > > > wrote: > >> > > > > > >> > > > > > I think you mean to set it as `current_user.is_authenticated = > >> > True`. > >> > > > > > > >> > > > > > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > >> > > > > > > Hello everyone, > >> > > > > > > I am trying to toggle between "Sign in" > and > >> > "Sign > >> > > > > > > out" links using the current_user.is_authenticated variable > >> such > >> > > that > >> > > > > > > when it returns False, the "Sign in" is displayed and when > >> True > >> > the > >> > > > > > > "Sign out" link is displayed. At some point in the login > code > >> I > >> > set > >> > > > > > > current_user.authenticated = True. The thing is that by the > I > >> am > >> > > > > > > successfully logged in and presented with the next view, it > is > >> > the > >> > > > > > > "Sign in" link that is still displayed. When I check > >> > > > > > > current_user.is_authenticated, it returns False, even > though I > >> > had > >> > > > > > > explicitly set it to True. Please can anyone point out what > I > >> am > >> > > > might > >> > > > > > > be doing wrong? Here is my code: > >> > > > > > > > >> > > > > > > I have a base.html file that contains the "Sign in" and > "Sign > >> > out" > >> > > > > > > links that is extended by the other templates: > >> > > > > > > > >> > > > > > > > >> > > > > > > > >> > > > > > > > >> > > > > > > {% block page_content %}{% endblock %} > >> > > > > > > > >> > > > > > > > >> > > > > > > > >> > > > > > > When the app first loads in the browser it displays a login > >> > form, > >> > > > > > > login.html: > >> > > > > > > > >> > > > > > > {% extends "base.html" %} > >> > > > > > > > >> > > > > > > {% block content %} > >> > > > > > > {% import "bootstrap/wtf.html" as wtf %} > >> > > > > > > {% block title %}Flasky - Login{% endblock %} > >> > > > > > > {% block page_content %} > >> > > > > > > > >> > > > > > >
> >> > > > > > > {{ wtf.quick_form(form) }} > >> > > > > > >
> >> > > > > > > {% endblock %} > >> > > > > > > {% endblock %} > >> > > > > > > > >> > > > > > > When a user logs in, it loads a template dashboard.html that > >> > > displays > >> > > > > > > a map. The top part looks like this: > >> > > > > > > > >> > > > > > > {% extends "base.html" %} > >> > > > > > > > >> > > > > > > {% block page_content %} > >> > > > > > > > >> > > > > > > > >> > > > > > > Lagos Map > >> > > > > > > >> > > > > > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > >> > > > > > > > >> > > > > > > >> > > > > > >> > > > > >> > > > >> > > >> > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > >> > > > > > > crossorigin=""/> > >> > > > > > > > >> > > > > > > > >> > > > > > > >> > > > > > > href=" > >> > > > > > > >> > > > > > >> > > > > >> > > > >> > > >> > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > >> > > > > " > >> > > > > > > >> > > > > > > /> > >> > > > > > > >> > > > > > > href=" > >> > > > > > > >> > > > > > >> > > > > >> > > > >> > > >> > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > >> > > > > " > >> > > > > > > >> > > > > > > /> > >> > > > > > > > >> > > > > > > > >> > > > > > > ... > >> > > > > > > ... > >> > > > > > > > >> > > > > > > And these are the relevant routes: > >> > > > > > > > >> > > > > > > @app.route('/',methods=['GET','POST']) > >> > > > > > > def index(): > >> > > > > > > form = LoginForm() > >> > > > > > > if form.validate_on_submit(): > >> > > > > > > user = > >> > > User.query.filter_by(email=form.email.data).first() > >> > > > > > > if user is not None and > >> > > > > > user.check_password(form.password.data): > >> > > > > > > user.authenticated = True > >> > > > > > > current_user = user > >> > > > > > > db.session.add(current_user) > >> > > > > > > db.session.commit() > >> > > > > > > login_user(current_user, > form.remember_me.data) > >> > > > > > > return redirect(request.args.get('next') or > >> > > > > > > url_for('dashboard')) > >> > > > > > > flash('Invalid username or password.') > >> > > > > > > return render_template('auth/login.html', form=form) > >> > > > > > > > >> > > > > > > @app.route('/dashboard') > >> > > > > > > def dashboard(): > >> > > > > > > return render_template("dashboard.html") > >> > > > > > > > >> > > > > > > Thank you for your time. > >> > > > > > > > >> > > > > > > _______________________________________________ > >> > > > > > > Flask mailing list > >> > > > > > > Flask at python.org > >> > > > > > > https://mail.python.org/mailman/listinfo/flask > >> > > > > > > >> > > > > > -- > >> > > > > > -- Kind regards, > >> > > > > > Leni Kadali Mutungi > >> > > > > > > >> > > > > > _______________________________________________ > >> > > > > > Flask mailing list > >> > > > > > Flask at python.org > >> > > > > > https://mail.python.org/mailman/listinfo/flask > >> > > > > > > >> > > > > -------------- next part -------------- > >> > > > > An HTML attachment was scrubbed... > >> > > > > URL: < > >> > > > > > >> > > > > >> > > > >> > > >> > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > >> > > > > > > >> > > > > > >> > > > > ------------------------------ > >> > > > > > >> > > > > Subject: Digest Footer > >> > > > > > >> > > > > _______________________________________________ > >> > > > > Flask mailing list > >> > > > > Flask at python.org > >> > > > > https://mail.python.org/mailman/listinfo/flask > >> > > > > > >> > > > > > >> > > > > ------------------------------ > >> > > > > > >> > > > > End of Flask Digest, Vol 49, Issue 5 > >> > > > > ************************************ > >> > > > > > >> > > > -------------- next part -------------- > >> > > > An HTML attachment was scrubbed... > >> > > > URL: < > >> > > > > >> > > > >> > > >> > http://mail.python.org/pipermail/flask/attachments/20190703/c47bb246/attachment-0001.html > >> > > > > > >> > > > > >> > > > ------------------------------ > >> > > > > >> > > > Message: 2 > >> > > > Date: Thu, 4 Jul 2019 06:25:40 +0200 > >> > > > From: Gergely Polonkai > >> > > > To: "sidwoodstock ." > >> > > > Cc: flask > >> > > > Subject: Re: [Flask] Unable to set current_user.authenticated to > >> True > >> > > > Message-ID: > >> > > > < > >> > > > > CACczBUJaj67qxPCEi9Tmjku42QDxDsuVLmEGQGuFaC2nndT7eA at mail.gmail.com> > >> > > > Content-Type: text/plain; charset="utf-8" > >> > > > > >> > > > No, modifying current_user directly is not possible (at least it > >> won?t > >> > > > propagate outside the function). current_user is a proxy object > that > >> > > points > >> > > > to the logged in user in the current request. If you assign a > >> different > >> > > > value to it, its proxy nature goes away which is definitely not > what > >> > you > >> > > > want: in extreme cases it might introduce security issues where > >> users > >> > can > >> > > > access each the data of other. > >> > > > > >> > > > On Wed, 3 Jul 2019, 18:19 sidwoodstock ., > > >> > > wrote: > >> > > > > >> > > > > Also, if Gergely's suggestion doesn't work, you could try > removing > >> > your > >> > > > > variable assignment of current_user = user. I see no practical > >> reason > >> > > to > >> > > > do > >> > > > > this, and since current_user is a built-in (and very handy) > >> variable, > >> > > > maybe > >> > > > > that is somehow related to your issue? > >> > > > > > >> > > > > > > current_user = user > >> > > > > > >> > > > > and then just call login_user directly with your user you > already > >> > have > >> > > at > >> > > > > hand: > >> > > > > > >> > > > > > > login_user(user, form.remember_me.data) > >> > > > > > >> > > > > -Scott > >> > > > > > >> > > > > On Wed, Jul 3, 2019 at 9:03 AM > wrote: > >> > > > > > >> > > > >> Send Flask mailing list submissions to > >> > > > >> flask at python.org > >> > > > >> > >> > > > >> To subscribe or unsubscribe via the World Wide Web, visit > >> > > > >> https://mail.python.org/mailman/listinfo/flask > >> > > > >> or, via email, send a message with subject or body 'help' to > >> > > > >> flask-request at python.org > >> > > > >> > >> > > > >> You can reach the person managing the list at > >> > > > >> flask-owner at python.org > >> > > > >> > >> > > > >> When replying, please edit your Subject line so it is more > >> specific > >> > > > >> than "Re: Contents of Flask digest..." > >> > > > >> > >> > > > >> > >> > > > >> Today's Topics: > >> > > > >> > >> > > > >> 1. Re: Unable to set current_user.authenticated to True > >> > > > >> (Gergely Polonkai) > >> > > > >> > >> > > > >> > >> > > > >> > >> > ---------------------------------------------------------------------- > >> > > > >> > >> > > > >> Message: 1 > >> > > > >> Date: Tue, 2 Jul 2019 19:01:20 +0200 > >> > > > >> From: Gergely Polonkai > >> > > > >> To: Leni Kadali Mutungi > >> > > > >> Cc: flask > >> > > > >> Subject: Re: [Flask] Unable to set current_user.authenticated > to > >> > True > >> > > > >> Message-ID: > >> > > > >> >> > > > >> zxtk3bMO+n-+-y3Q at mail.gmail.com> > >> > > > >> Content-Type: text/plain; charset="utf-8" > >> > > > >> > >> > > > >> Hello, > >> > > > >> > >> > > > >> I assume you are using Flask-Login (either directly or via > >> another > >> > > > >> extension like Flask-Security). If this is the case, you can > >> import > >> > > > >> login_user and call it like login_user(user). > >> > > > >> > >> > > > >> If that does not work, you may want to check if the user is > >> active > >> > > (ie. > >> > > > >> not > >> > > > >> disabled), as it is the most common culprit when a user can?t > be > >> > > logged > >> > > > >> in. > >> > > > >> > >> > > > >> Best, > >> > > > >> Gergely > >> > > > >> > >> > > > >> On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < > >> > > lenikmutungi at gmail.com> > >> > > > >> wrote: > >> > > > >> > >> > > > >> > I think you mean to set it as `current_user.is_authenticated > = > >> > > True`. > >> > > > >> > > >> > > > >> > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > >> > > > >> > > Hello everyone, > >> > > > >> > > I am trying to toggle between "Sign in" > and > >> > > "Sign > >> > > > >> > > out" links using the current_user.is_authenticated variable > >> such > >> > > > that > >> > > > >> > > when it returns False, the "Sign in" is displayed and when > >> True > >> > > the > >> > > > >> > > "Sign out" link is displayed. At some point in the login > >> code I > >> > > set > >> > > > >> > > current_user.authenticated = True. The thing is that by the > >> I am > >> > > > >> > > successfully logged in and presented with the next view, it > >> is > >> > the > >> > > > >> > > "Sign in" link that is still displayed. When I check > >> > > > >> > > current_user.is_authenticated, it returns False, even > though > >> I > >> > had > >> > > > >> > > explicitly set it to True. Please can anyone point out what > >> I am > >> > > > might > >> > > > >> > > be doing wrong? Here is my code: > >> > > > >> > > > >> > > > >> > > I have a base.html file that contains the "Sign in" and > "Sign > >> > out" > >> > > > >> > > links that is extended by the other templates: > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > {% block page_content %}{% endblock %} > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > When the app first loads in the browser it displays a > login > >> > form, > >> > > > >> > > login.html: > >> > > > >> > > > >> > > > >> > > {% extends "base.html" %} > >> > > > >> > > > >> > > > >> > > {% block content %} > >> > > > >> > > {% import "bootstrap/wtf.html" as wtf %} > >> > > > >> > > {% block title %}Flasky - Login{% endblock %} > >> > > > >> > > {% block page_content %} > >> > > > >> > > > >> > > > >> > >
> >> > > > >> > > {{ wtf.quick_form(form) }} > >> > > > >> > >
> >> > > > >> > > {% endblock %} > >> > > > >> > > {% endblock %} > >> > > > >> > > > >> > > > >> > > When a user logs in, it loads a template dashboard.html > that > >> > > > displays > >> > > > >> > > a map. The top part looks like this: > >> > > > >> > > > >> > > > >> > > {% extends "base.html" %} > >> > > > >> > > > >> > > > >> > > {% block page_content %} > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > Lagos Map > >> > > > >> > > >> > > > >> > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > >> > > > >> > > > >> > > > >> > > >> > > > >> > >> > > > > >> > > > >> > > >> > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > >> > > > >> > > crossorigin=""/> > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > >> > > > >> > > href=" > >> > > > >> > > >> > > > >> > >> > > > > >> > > > >> > > >> > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > >> > > > >> " > >> > > > >> > > >> > > > >> > > /> > >> > > > >> > > >> > > > >> > > href=" > >> > > > >> > > >> > > > >> > >> > > > > >> > > > >> > > >> > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > >> > > > >> " > >> > > > >> > > >> > > > >> > > /> > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > ... > >> > > > >> > > ... > >> > > > >> > > > >> > > > >> > > And these are the relevant routes: > >> > > > >> > > > >> > > > >> > > @app.route('/',methods=['GET','POST']) > >> > > > >> > > def index(): > >> > > > >> > > form = LoginForm() > >> > > > >> > > if form.validate_on_submit(): > >> > > > >> > > user = > >> > > User.query.filter_by(email=form.email.data).first() > >> > > > >> > > if user is not None and > >> > > > >> > user.check_password(form.password.data): > >> > > > >> > > user.authenticated = True > >> > > > >> > > current_user = user > >> > > > >> > > db.session.add(current_user) > >> > > > >> > > db.session.commit() > >> > > > >> > > login_user(current_user, > form.remember_me.data) > >> > > > >> > > return redirect(request.args.get('next') or > >> > > > >> > > url_for('dashboard')) > >> > > > >> > > flash('Invalid username or password.') > >> > > > >> > > return render_template('auth/login.html', form=form) > >> > > > >> > > > >> > > > >> > > @app.route('/dashboard') > >> > > > >> > > def dashboard(): > >> > > > >> > > return render_template("dashboard.html") > >> > > > >> > > > >> > > > >> > > Thank you for your time. > >> > > > >> > > > >> > > > >> > > _______________________________________________ > >> > > > >> > > Flask mailing list > >> > > > >> > > Flask at python.org > >> > > > >> > > https://mail.python.org/mailman/listinfo/flask > >> > > > >> > > >> > > > >> > -- > >> > > > >> > -- Kind regards, > >> > > > >> > Leni Kadali Mutungi > >> > > > >> > > >> > > > >> > _______________________________________________ > >> > > > >> > Flask mailing list > >> > > > >> > Flask at python.org > >> > > > >> > https://mail.python.org/mailman/listinfo/flask > >> > > > >> > > >> > > > >> -------------- next part -------------- > >> > > > >> An HTML attachment was scrubbed... > >> > > > >> URL: < > >> > > > >> > >> > > > > >> > > > >> > > >> > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > >> > > > >> > > >> > > > >> > >> > > > >> ------------------------------ > >> > > > >> > >> > > > >> Subject: Digest Footer > >> > > > >> > >> > > > >> _______________________________________________ > >> > > > >> Flask mailing list > >> > > > >> Flask at python.org > >> > > > >> https://mail.python.org/mailman/listinfo/flask > >> > > > >> > >> > > > >> > >> > > > >> ------------------------------ > >> > > > >> > >> > > > >> End of Flask Digest, Vol 49, Issue 5 > >> > > > >> ************************************ > >> > > > >> > >> > > > > _______________________________________________ > >> > > > > Flask mailing list > >> > > > > Flask at python.org > >> > > > > https://mail.python.org/mailman/listinfo/flask > >> > > > > > >> > > > > >> > > > On Wed, 3 Jul 2019, 18:19 sidwoodstock ., > > >> > > wrote: > >> > > > > >> > > > > Also, if Gergely's suggestion doesn't work, you could try > removing > >> > your > >> > > > > variable assignment of current_user = user. I see no practical > >> reason > >> > > to > >> > > > do > >> > > > > this, and since current_user is a built-in (and very handy) > >> variable, > >> > > > maybe > >> > > > > that is somehow related to your issue? > >> > > > > > >> > > > > > > current_user = user > >> > > > > > >> > > > > and then just call login_user directly with your user you > already > >> > have > >> > > at > >> > > > > hand: > >> > > > > > >> > > > > > > login_user(user, form.remember_me.data) > >> > > > > > >> > > > > -Scott > >> > > > > > >> > > > > On Wed, Jul 3, 2019 at 9:03 AM > wrote: > >> > > > > > >> > > > >> Send Flask mailing list submissions to > >> > > > >> flask at python.org > >> > > > >> > >> > > > >> To subscribe or unsubscribe via the World Wide Web, visit > >> > > > >> https://mail.python.org/mailman/listinfo/flask > >> > > > >> or, via email, send a message with subject or body 'help' to > >> > > > >> flask-request at python.org > >> > > > >> > >> > > > >> You can reach the person managing the list at > >> > > > >> flask-owner at python.org > >> > > > >> > >> > > > >> When replying, please edit your Subject line so it is more > >> specific > >> > > > >> than "Re: Contents of Flask digest..." > >> > > > >> > >> > > > >> > >> > > > >> Today's Topics: > >> > > > >> > >> > > > >> 1. Re: Unable to set current_user.authenticated to True > >> > > > >> (Gergely Polonkai) > >> > > > >> > >> > > > >> > >> > > > >> > >> > ---------------------------------------------------------------------- > >> > > > >> > >> > > > >> Message: 1 > >> > > > >> Date: Tue, 2 Jul 2019 19:01:20 +0200 > >> > > > >> From: Gergely Polonkai > >> > > > >> To: Leni Kadali Mutungi > >> > > > >> Cc: flask > >> > > > >> Subject: Re: [Flask] Unable to set current_user.authenticated > to > >> > True > >> > > > >> Message-ID: > >> > > > >> >> > > > >> zxtk3bMO+n-+-y3Q at mail.gmail.com> > >> > > > >> Content-Type: text/plain; charset="utf-8" > >> > > > >> > >> > > > >> Hello, > >> > > > >> > >> > > > >> I assume you are using Flask-Login (either directly or via > >> another > >> > > > >> extension like Flask-Security). If this is the case, you can > >> import > >> > > > >> login_user and call it like login_user(user). > >> > > > >> > >> > > > >> If that does not work, you may want to check if the user is > >> active > >> > > (ie. > >> > > > >> not > >> > > > >> disabled), as it is the most common culprit when a user can?t > be > >> > > logged > >> > > > >> in. > >> > > > >> > >> > > > >> Best, > >> > > > >> Gergely > >> > > > >> > >> > > > >> On Mon, 1 Jul 2019, 19:03 Leni Kadali Mutungi, < > >> > > lenikmutungi at gmail.com> > >> > > > >> wrote: > >> > > > >> > >> > > > >> > I think you mean to set it as `current_user.is_authenticated > = > >> > > True`. > >> > > > >> > > >> > > > >> > On 7/1/19 6:14 PM, Abdul Mohammed wrote: > >> > > > >> > > Hello everyone, > >> > > > >> > > I am trying to toggle between "Sign in" > and > >> > > "Sign > >> > > > >> > > out" links using the current_user.is_authenticated variable > >> such > >> > > > that > >> > > > >> > > when it returns False, the "Sign in" is displayed and when > >> True > >> > > the > >> > > > >> > > "Sign out" link is displayed. At some point in the login > >> code I > >> > > set > >> > > > >> > > current_user.authenticated = True. The thing is that by the > >> I am > >> > > > >> > > successfully logged in and presented with the next view, it > >> is > >> > the > >> > > > >> > > "Sign in" link that is still displayed. When I check > >> > > > >> > > current_user.is_authenticated, it returns False, even > though > >> I > >> > had > >> > > > >> > > explicitly set it to True. Please can anyone point out what > >> I am > >> > > > might > >> > > > >> > > be doing wrong? Here is my code: > >> > > > >> > > > >> > > > >> > > I have a base.html file that contains the "Sign in" and > "Sign > >> > out" > >> > > > >> > > links that is extended by the other templates: > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > {% block page_content %}{% endblock %} > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > When the app first loads in the browser it displays a > login > >> > form, > >> > > > >> > > login.html: > >> > > > >> > > > >> > > > >> > > {% extends "base.html" %} > >> > > > >> > > > >> > > > >> > > {% block content %} > >> > > > >> > > {% import "bootstrap/wtf.html" as wtf %} > >> > > > >> > > {% block title %}Flasky - Login{% endblock %} > >> > > > >> > > {% block page_content %} > >> > > > >> > > > >> > > > >> > >
> >> > > > >> > > {{ wtf.quick_form(form) }} > >> > > > >> > >
> >> > > > >> > > {% endblock %} > >> > > > >> > > {% endblock %} > >> > > > >> > > > >> > > > >> > > When a user logs in, it loads a template dashboard.html > that > >> > > > displays > >> > > > >> > > a map. The top part looks like this: > >> > > > >> > > > >> > > > >> > > {% extends "base.html" %} > >> > > > >> > > > >> > > > >> > > {% block page_content %} > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > Lagos Map > >> > > > >> > > >> > > > >> > > href="https://unpkg.com/leaflet at 1.1.0/dist/leaflet.css" > >> > > > >> > > > >> > > > >> > > >> > > > >> > >> > > > > >> > > > >> > > >> > integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" > >> > > > >> > > crossorigin=""/> > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > >> > > > >> > > href=" > >> > > > >> > > >> > > > >> > >> > > > > >> > > > >> > > >> > https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css > >> > > > >> " > >> > > > >> > > >> > > > >> > > /> > >> > > > >> > > >> > > > >> > > href=" > >> > > > >> > > >> > > > >> > >> > > > > >> > > > >> > > >> > https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css > >> > > > >> " > >> > > > >> > > >> > > > >> > > /> > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > ... > >> > > > >> > > ... > >> > > > >> > > > >> > > > >> > > And these are the relevant routes: > >> > > > >> > > > >> > > > >> > > @app.route('/',methods=['GET','POST']) > >> > > > >> > > def index(): > >> > > > >> > > form = LoginForm() > >> > > > >> > > if form.validate_on_submit(): > >> > > > >> > > user = > >> > > User.query.filter_by(email=form.email.data).first() > >> > > > >> > > if user is not None and > >> > > > >> > user.check_password(form.password.data): > >> > > > >> > > user.authenticated = True > >> > > > >> > > current_user = user > >> > > > >> > > db.session.add(current_user) > >> > > > >> > > db.session.commit() > >> > > > >> > > login_user(current_user, > form.remember_me.data) > >> > > > >> > > return redirect(request.args.get('next') or > >> > > > >> > > url_for('dashboard')) > >> > > > >> > > flash('Invalid username or password.') > >> > > > >> > > return render_template('auth/login.html', form=form) > >> > > > >> > > > >> > > > >> > > @app.route('/dashboard') > >> > > > >> > > def dashboard(): > >> > > > >> > > return render_template("dashboard.html") > >> > > > >> > > > >> > > > >> > > Thank you for your time. > >> > > > >> > > > >> > > > >> > > _______________________________________________ > >> > > > >> > > Flask mailing list > >> > > > >> > > Flask at python.org > >> > > > >> > > https://mail.python.org/mailman/listinfo/flask > >> > > > >> > > >> > > > >> > -- > >> > > > >> > -- Kind regards, > >> > > > >> > Leni Kadali Mutungi > >> > > > >> > > >> > > > >> > _______________________________________________ > >> > > > >> > Flask mailing list > >> > > > >> > Flask at python.org > >> > > > >> > https://mail.python.org/mailman/listinfo/flask > >> > > > >> > > >> > > > >> -------------- next part -------------- > >> > > > >> An HTML attachment was scrubbed... > >> > > > >> URL: < > >> > > > >> > >> > > > > >> > > > >> > > >> > http://mail.python.org/pipermail/flask/attachments/20190702/424f55cc/attachment-0001.html > >> > > > >> > > >> > > > >> > >> > > > >> ------------------------------ > >> > > > >> > >> > > > >> Subject: Digest Footer > >> > > > >> > >> > > > >> _______________________________________________ > >> > > > >> Flask mailing list > >> > > > >> Flask at python.org > >> > > > >> https://mail.python.org/mailman/listinfo/flask > >> > > > >> > >> > > > >> > >> > > > >> ------------------------------ > >> > > > >> > >> > > > >> End of Flask Digest, Vol 49, Issue 5 > >> > > > >> ************************************ > >> > > > >> > >> > > > > _______________________________________________ > >> > > > > Flask mailing list > >> > > > > Flask at python.org > >> > > > > https://mail.python.org/mailman/listinfo/flask > >> > > > > > >> > > > -------------- next part -------------- > >> > > > An HTML attachment was scrubbed... > >> > > > URL: < > >> > > > > >> > > > >> > > >> > http://mail.python.org/pipermail/flask/attachments/20190704/055df8bc/attachment.html > >> > > > > > >> > > > > >> > > > ------------------------------ > >> > > > > >> > > > Subject: Digest Footer > >> > > > > >> > > > _______________________________________________ > >> > > > Flask mailing list > >> > > > Flask at python.org > >> > > > https://mail.python.org/mailman/listinfo/flask > >> > > > > >> > > > > >> > > > ------------------------------ > >> > > > > >> > > > End of Flask Digest, Vol 49, Issue 6 > >> > > > ************************************ > >> > > > > >> > > -------------- next part -------------- > >> > > An HTML attachment was scrubbed... > >> > > URL: < > >> > > > >> > > >> > http://mail.python.org/pipermail/flask/attachments/20190704/89bc8e49/attachment.html > >> > > > > >> > > > >> > > ------------------------------ > >> > > > >> > > Subject: Digest Footer > >> > > > >> > > _______________________________________________ > >> > > Flask mailing list > >> > > Flask at python.org > >> > > https://mail.python.org/mailman/listinfo/flask > >> > > > >> > > > >> > > ------------------------------ > >> > > > >> > > End of Flask Digest, Vol 49, Issue 7 > >> > > ************************************ > >> > > > >> > -------------- next part -------------- > >> > An HTML attachment was scrubbed... > >> > URL: < > >> > > >> > http://mail.python.org/pipermail/flask/attachments/20190704/04cbab56/attachment.html > >> > > > >> > > >> > ------------------------------ > >> > > >> > Subject: Digest Footer > >> > > >> > _______________________________________________ > >> > Flask mailing list > >> > Flask at python.org > >> > https://mail.python.org/mailman/listinfo/flask > >> > > >> > > >> > ------------------------------ > >> > > >> > End of Flask Digest, Vol 49, Issue 8 > >> > ************************************ > >> > > >> -------------- next part -------------- > >> An HTML attachment was scrubbed... > >> URL: < > >> > http://mail.python.org/pipermail/flask/attachments/20190708/47a60007/attachment.html > >> > > >> > >> ------------------------------ > >> > >> Subject: Digest Footer > >> > >> _______________________________________________ > >> Flask mailing list > >> Flask at python.org > >> https://mail.python.org/mailman/listinfo/flask > >> > >> > >> ------------------------------ > >> > >> End of Flask Digest, Vol 49, Issue 11 > >> ************************************* > >> > > _______________________________________________ > > Flask mailing list > > Flask at python.org > > https://mail.python.org/mailman/listinfo/flask > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/flask/attachments/20190709/6609b7c0/attachment.html > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > > ------------------------------ > > End of Flask Digest, Vol 49, Issue 13 > ************************************* > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stappers at stappers.nl Thu Jul 11 17:44:20 2019 From: stappers at stappers.nl (Geert Stappers) Date: Thu, 11 Jul 2019 23:44:20 +0200 Subject: [Flask] reading yaml only at start up Message-ID: <20190711214420.glkwnydv6oiqjwdw@gpm.stappers.nl> Hi, Flask documentation does cover database connection. Thing I'm looking for is how read (only at startup) a YAML file into a dictionary. And how to reference that dict in various routes. Where may I find source code that does that? Groeten Geert Stappers -- Leven en laten leven From gergely at polonkai.eu Fri Jul 12 01:12:38 2019 From: gergely at polonkai.eu (Gergely Polonkai) Date: Fri, 12 Jul 2019 07:12:38 +0200 Subject: [Flask] reading yaml only at start up In-Reply-To: <20190711214420.glkwnydv6oiqjwdw@gpm.stappers.nl> References: <20190711214420.glkwnydv6oiqjwdw@gpm.stappers.nl> Message-ID: Depends on how you initialise your app. If you use a plain Flask object, you may want to override the Flask class with something like a custom FlaskYamlReader and do the reading in __init__(). One advantage of this is that you can store the dict in self.yamldict so you can easily access it with current_app.yamldict. If you use an application factory, you can read it in the factory function and either set it as an attribute of the app object (with setattr) or add it to the g object like from flask import g def factory(): app = Flask(?) g.yamldict = yaml.safe_read(yourfile) return app Then access the object using g.yamldict in your code. However, keep in mind that in a production environment your app can be recreated for each request. If this is the case, you might want to create a proxy object instead, which you can automatically propagate during the first request and use as a cache afterwards. Happy coding! Gergely On Thu, 11 Jul 2019, 23:50 Geert Stappers, wrote: > > Hi, > > Flask documentation does cover database connection. > > > Thing I'm looking for is how read (only at startup) > a YAML file into a dictionary. > And how to reference that dict in various routes. > > Where may I find source code that does that? > > > Groeten > Geert Stappers > -- > Leven en laten leven > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From badrihippo at gmail.com Fri Jul 12 01:54:34 2019 From: badrihippo at gmail.com (Hippo) Date: Fri, 12 Jul 2019 11:24:34 +0530 Subject: [Flask] Where to set up logging in large flask app Message-ID: Hello all, I have a Flask app split into many components like views.py, forms.py, models.py, and so on. The app is in version control, and I'm using the instance folder (with a config.py inside) to handle the local, server-specific settings. The main Flask() object is defined in __init__.py. Now I'm setting up email notifications for error logging, using instructions from this documentation page , but can't decide where to paste the code: import logging from logging.handlers import SMTPHandler mail_handler = SMTPHandler( mailhost='127.0.0.1', fromaddr='server-error at example.com', toaddrs=['admin at example.com'], subject='Application Error' ) mail_handler.setLevel(logging.ERROR) mail_handler.setFormatter(logging.Formatter( '[%(asctime)s] %(levelname)s in %(module)s: %(message)s' )) if not app.debug: app.logger.addHandler(mail_handler) Normally, this would go in instance/config.py. However, the last two lines need the app object, which is not imported to config (since the import goes the other way round). One option I thought of is to make the whole mail handler into a setting (ERROR_EMAIL_HANDLER = SMTPHandler(...)), and then add the following lines to __init__.py where I've defined the app: if app.settings.get('ERROR_EMAIL_HANDLER') and not app.debug: app.logger.addHandler(ERROR_EMAIL_HANDLER) What do you think of this solution? Anything more elegant to suggest? Thanks in advance, Badri -------------- next part -------------- An HTML attachment was scrubbed... URL: From stappers at stappers.nl Fri Jul 12 01:56:26 2019 From: stappers at stappers.nl (Geert Stappers) Date: Fri, 12 Jul 2019 07:56:26 +0200 Subject: [Flask] reading yaml only at start up In-Reply-To: References: <20190711214420.glkwnydv6oiqjwdw@gpm.stappers.nl> Message-ID: <20190712055626.pm6pmwvlirohflqt@gpm.stappers.nl> On Fri, Jul 12, 2019 at 07:12:38AM +0200, Gergely Polonkai wrote: > On Thu, 11 Jul 2019, 23:50 Geert Stappers, wrote: > > > > > Hi, > > > > Flask documentation does cover database connection. > > > > > > Thing I'm looking for is how read (only at startup) > > a YAML file into a dictionary. > > And how to reference that dict in various routes. > > > > Where may I find source code that does that? > > > > Depends on how you initialise your app. > > If you use a plain Flask object, you may want to override the Flask class > with something like a custom FlaskYamlReader and do the reading in > __init__(). Ah, __init__() Yes, now I do see that function in https://flask.palletsprojects.com/en/1.1.x/tutorial/layout/ > One advantage of this is that you can store the dict in self.yamldict > so you can easily access it with current_app.yamldict. Okay, that will be my next clue. > If you use an application factory, you can read it in the factory function > and either set it as an attribute of the app object (with setattr) or add > it to the g object like > > from flask import g > > def factory(): > app = Flask(???) > g.yamldict = yaml.safe_read(yourfile) > return app > > Then access the object using g.yamldict in your code. > > However, keep in mind that in a production environment your app can be > recreated for each request. If this is the case, you might want to create a > proxy object instead, which you can automatically propagate during the > first request and use as a cache afterwards. > > Happy coding! > > Gergely Thanks Groeten Geert Stappers -- Leven en laten leven From nicolas at lemanchet.fr Fri Jul 12 03:22:03 2019 From: nicolas at lemanchet.fr (Nicolas Le Manchet) Date: Fri, 12 Jul 2019 09:22:03 +0200 Subject: [Flask] Where to set up logging in large flask app In-Reply-To: References: Message-ID: On Fri, Jul 12, 2019, at 07:55, Hippo wrote: > Hello all, > I have a Flask app split into many components like views.py, forms.py, > models.py, and so on. The app is in version control, and I'm using the > instance folder (with a config.py inside) to handle the local, > server-specific settings. The main Flask() object is defined in > __init__.py. > > Now I'm setting up email notifications for error logging, using > instructions from this documentation page > , but can't decide where to paste the code: > > import logging > from logging.handlers import SMTPHandler > > mail_handler = SMTPHandler( > mailhost='127.0.0.1', > fromaddr='server-error at example.com', > toaddrs=['admin at example.com'], > subject='Application Error' > ) > mail_handler.setLevel(logging.ERROR) > mail_handler.setFormatter(logging.Formatter( > '[%(asctime)s] %(levelname)s in %(module)s: %(message)s' > )) > > if not app.debug: > app.logger.addHandler(mail_handler) > > Normally, this would go in instance/config.py. However, the last two > lines need the app object, which is not imported to config (since the > import goes the other way round). > > One option I thought of is to make the whole mail handler into a > setting (ERROR_EMAIL_HANDLER = SMTPHandler(...)), and then add the > following lines to __init__.py where I've defined the app: > > if app.settings.get('ERROR_EMAIL_HANDLER') and not app.debug: > app.logger.addHandler(ERROR_EMAIL_HANDLER) > > What do you think of this solution? Anything more elegant to suggest? > > Thanks in advance, > Badri > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > Hi, It's better to do the logging setup as soon as possible. Your `instance/config.py` looks like a good place for that and I guess even if it does not have access to the `app` object it knows somehow if the app runs in debug mode or not (after all this is the config module, isn't it?). Large applications tend to have a logging setup that grows more complicated over time. With that in mind using the `dictConfig` format makes things much more readable than individual calls to `addHandler`, `setLevel`... spread throughout the application. Now for a personal opinion, SMTPHandler is a terrible way to track errors in a large app. You should take a look at Sentry as it does a much better job of getting actionable alerts when something goes wrong. -- Nicolas Le Manchet From badrihippo at gmail.com Fri Jul 12 04:20:08 2019 From: badrihippo at gmail.com (Hippo) Date: Fri, 12 Jul 2019 13:50:08 +0530 Subject: [Flask] Where to set up logging in large flask app In-Reply-To: References: Message-ID: Hi, Thanks for the tips. I don't think my `config.py` knows whether it's it debug mode or not: usually, people keep a separate config for debug and non-debug, and the app selects the appropriate one. (So come to think of it, the config.py does "know" in the sense, if it's being called, then it's not in debug mode). The dictconfig format is convenient though: I looked it up just now. Perhaps what I can do is create a `LOGGING_HANDLERS` setting in my config, and have app register that in `__init__.py`, something like for handler in app.config.get('LOGGING_HANDLERS', []): app.logger.add_handler(handler) I should probably be registering logging even before, putting it in __init__.py before the Flask app is even registered, but then it would need to import from Flask's config.py creating a catch-22 situation. So this is probably the best compromise :P And it's true...emailing error isn't the best way to go about things. I'm currently working on an in-house project for an institute, and the expected volume is very low so email seems the best way to get it up and running fast. But I'll check with them if they're interested in Sentry: once set up, they'll be able to use it for all their other systems as well. Thanks again, Badri Hi, > > It's better to do the logging setup as soon as possible. Your > `instance/config.py` looks like a good place for that and I guess even if > it does not have access to the `app` object it knows somehow if the app > runs in debug mode or not (after all this is the config module, isn't it?). > > Large applications tend to have a logging setup that grows more > complicated over time. With that in mind using the `dictConfig` format > makes things much more readable than individual calls to `addHandler`, > `setLevel`... spread throughout the application. > > Now for a personal opinion, SMTPHandler is a terrible way to track errors > in a large app. You should take a look at Sentry as it does a much better > job of getting actionable alerts when something goes wrong. > > -- > Nicolas Le Manchet > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From marco.py at yahoo.com Fri Jul 12 16:31:49 2019 From: marco.py at yahoo.com (marco boi) Date: Fri, 12 Jul 2019 20:31:49 +0000 (UTC) Subject: [Flask] Flask Basic Server error: could not import "flaskblog" References: <765569945.325169.1562963509935.ref@mail.yahoo.com> Message-ID: <765569945.325169.1562963509935@mail.yahoo.com> Hello everybody, I just started to learn Flask with Corey Schafer on Youtube. I created a Flask_Blog folder, containing flaskblog.py. In the flaskblog.py file, there is the code to create a basic Flask server.http://dpaste.com/0V6G5HS . I go in my cmd and I type the following:http://dpaste.com/13DR9KA . And I get this error:http://dpaste.com/3R1EHM0 Thank you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From badrihippo at gmail.com Sat Jul 13 01:03:28 2019 From: badrihippo at gmail.com (Hippo) Date: Sat, 13 Jul 2019 10:33:28 +0530 Subject: [Flask] Flask Basic Server error: could not import "flaskblog" In-Reply-To: <765569945.325169.1562963509935@mail.yahoo.com> References: <765569945.325169.1562963509935.ref@mail.yahoo.com> <765569945.325169.1562963509935@mail.yahoo.com> Message-ID: Are you using Windows or Linux? n most Linux systems, the command is not `set` but `export`: export FLASK_APP=flaskblog.py flask run You can also set the parameters specifically for the command you're running. The following code sets FLASK_APP only for the `flask_run` command, leaving it untouched everywhere else: FLASK_APP=flaskblog.py flask run Of course, that's only if you're using Linux (or other Unix-based systems). Hope that helps, Badri On Sat, 13 Jul 2019 at 02:02, marco boi via Flask wrote: > Hello everybody, I just started to learn Flask with Corey Schafer on > Youtube. I created a Flask_Blog folder, containing flaskblog.py. In the > flaskblog.py file, there is the code to create a basic Flask server. > http://dpaste.com/0V6G5HS > > . I go in my cmd and I type the following:http://dpaste.com/13DR9KA > > . And I get this error:http://dpaste.com/3R1EHM0 > > > Thank you. > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From badrihippo at gmail.com Sun Jul 14 10:53:31 2019 From: badrihippo at gmail.com (Hippo) Date: Sun, 14 Jul 2019 20:23:31 +0530 Subject: [Flask] Flask Basic Server error: could not import "flaskblog" In-Reply-To: <484779519.460212.1563029489251@mail.yahoo.com> References: <765569945.325169.1562963509935.ref@mail.yahoo.com> <765569945.325169.1562963509935@mail.yahoo.com> <484779519.460212.1563029489251@mail.yahoo.com> Message-ID: Hello Marco, I don't use Windows so I can't help you there, but you could check out https://stackoverflow.com/q/37826016/1196444 ? one of the answers there may work for you. Let me know how it goes. Badri On Sat, 13 Jul 2019 at 20:21, marco boi wrote: > Hello Badri, no I am using Windows. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From linux4ms at gmail.com Thu Jul 25 12:52:04 2019 From: linux4ms at gmail.com (Ben Duncan) Date: Thu, 25 Jul 2019 11:52:04 -0500 Subject: [Flask] Is this group active ...? Message-ID: Making sure. I'm a new convert to flask .. *Ben Duncan* DBA / Chief Software Architect Mississippi State Supreme Court Electronic Filing Division -------------- next part -------------- An HTML attachment was scrubbed... URL: From casahome2000 at gmail.com Thu Jul 25 12:53:15 2019 From: casahome2000 at gmail.com (Carlos Anchia) Date: Thu, 25 Jul 2019 11:53:15 -0500 Subject: [Flask] Is this group active ...? In-Reply-To: References: Message-ID: <0A70908F-2C9A-4AF2-BC8B-432A03F70AB7@gmail.com> Hi - yep, active :) > On Jul 25, 2019, at 11:52 AM, Ben Duncan wrote: > > Making sure. I'm a new convert to flask .. > > Ben Duncan > DBA / Chief Software Architect > Mississippi State Supreme Court > Electronic Filing Division > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask -------------- next part -------------- An HTML attachment was scrubbed... URL: From badrihippo at gmail.com Thu Jul 25 12:53:52 2019 From: badrihippo at gmail.com (Hippo) Date: Thu, 25 Jul 2019 22:23:52 +0530 Subject: [Flask] Is this group active ...? In-Reply-To: References: Message-ID: Yup, it's active alright :) Welcome to the group! ?Badri On Thu, 25 Jul 2019 at 22:22, Ben Duncan wrote: > Making sure. I'm a new convert to flask .. > > *Ben Duncan* > DBA / Chief Software Architect > Mississippi State Supreme Court > Electronic Filing Division > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stappers at stappers.nl Thu Jul 25 13:02:55 2019 From: stappers at stappers.nl (Geert Stappers) Date: Thu, 25 Jul 2019 19:02:55 +0200 Subject: [Flask] Is this group active ...? In-Reply-To: References: Message-ID: <20190725170255.xz5c7l23z7ybw5j4@gpm.stappers.nl> On Thu, Jul 25, 2019 at 11:52:04AM -0500, Ben Duncan wrote: > I'm a new convert to flask .. Welcome Regards Geert Stappers P.S. Smart people have the skill to edit email in way that makes reading in the discussion order possible. It are also those who understand mailinglist are 1-to-N, that most of the readers[1] did not read all previous posts. [1] the pool where you have to actract a replier ... From unai at sysbible.org Thu Jul 25 13:20:02 2019 From: unai at sysbible.org (Unai Rodriguez) Date: Thu, 25 Jul 2019 19:20:02 +0200 Subject: [Flask] Is this group active ...? In-Reply-To: <20190725170255.xz5c7l23z7ybw5j4@gpm.stappers.nl> References: <20190725170255.xz5c7l23z7ybw5j4@gpm.stappers.nl> Message-ID: <41db88a7-3da1-42b1-8645-719999b028df@www.fastmail.com> pong -- unai On Thu, Jul 25, 2019, at 7:11 PM, Geert Stappers wrote: > On Thu, Jul 25, 2019 at 11:52:04AM -0500, Ben Duncan wrote: > > I'm a new convert to flask .. > > Welcome > > > Regards > Geert Stappers > > P.S. > Smart people have the skill to edit email > in way that makes reading in the discussion order possible. > It are also those who understand mailinglist are 1-to-N, > that most of the readers[1] did not read all previous posts. > > [1] the pool where you have to actract a replier ... > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > From linux4ms at gmail.com Fri Jul 26 09:15:56 2019 From: linux4ms at gmail.com (Ben Duncan) Date: Fri, 26 Jul 2019 08:15:56 -0500 Subject: [Flask] Storage Context Message-ID: Ok, I'm coming form web2py and adopting Flask However, one of the things I had under web2py is a module called Storage. It worked much like a memcach database. See: https://web2py.readthedocs.io/en/latest/storage.html Is there anything like that in Flask? I've adapted the storage module for my use in Flask, but I'd rather use anything native to Flask. Thanks .. *Ben Duncan* DBA / Chief Software Architect Mississippi State Supreme Court Electronic Filing Division -------------- next part -------------- An HTML attachment was scrubbed... URL: From gergely at polonkai.eu Fri Jul 26 09:26:33 2019 From: gergely at polonkai.eu (Gergely Polonkai) Date: Fri, 26 Jul 2019 13:26:33 +0000 Subject: [Flask] Storage Context In-Reply-To: References: Message-ID: I never used web2py, but from the documentation it looks like some basic caching functionality. If this is the case, you should check Flask-Caching (a fork of the unmaintained Flask-Cache). It can store the cache in memory or in a file, or connect to memcached, Redis, and a bunch of other storage backends. (Disclaimer: i?m one of the maintainers of that package). If, however, you don?t need a persistent(ish) cache, the simplest solution is probably to set g.my_storage to a dictionary and use the dictionary methods to access it. Best, Gergely Gergely Polonkai [image: https://]about.me/gergely.polonkai f?s., 26. j?l. 2019 kl. 13:16 skrifa?i Ben Duncan : > Ok, I'm coming form web2py and adopting Flask > However, one of the things I had under web2py is a module called Storage. > It worked much like a memcach database. > > See: https://web2py.readthedocs.io/en/latest/storage.html > > Is there anything like that in Flask? > I've adapted the storage module for my use in Flask, but I'd rather use > anything native > to Flask. > > Thanks .. > > *Ben Duncan* > DBA / Chief Software Architect > Mississippi State Supreme Court > Electronic Filing Division > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From linux4ms at gmail.com Fri Jul 26 10:44:56 2019 From: linux4ms at gmail.com (Ben Duncan) Date: Fri, 26 Jul 2019 09:44:56 -0500 Subject: [Flask] Storage Context In-Reply-To: References: Message-ID: Kinda sorta, more like a persistence dict / list Best documentation I could find describing it: Module storagesource code This file is part of the web2py Web Framework Copyrighted by Massimo Di Pierro License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html) Provides: - List; like list but returns None instead of IndexOutOfBounds - Storage; like dictionary allowing also for `obj.foo` for `obj['foo']` Classes [hide private ] List Like a regular python list but a[i] if i is out of bounds return None instead of IndexOutOfBounds Storage A Storage object is like a dictionary except `obj.foo` can be used in addition to `obj['foo']`. StorageList like Storage but missing elements default to [] instead of None Settings Messages Functions [hide private ] load_storage(filename) source code save_storage(storage, filename) source code Home Trees Indices Help *Ben Duncan* DBA / Chief Software Architect Mississippi State Supreme Court Electronic Filing Division On Fri, Jul 26, 2019 at 8:26 AM Gergely Polonkai wrote: > I never used web2py, but from the documentation it looks like some basic > caching functionality. If this is the case, you should check Flask-Caching > (a fork of the unmaintained Flask-Cache). It can store the cache in memory > or in a file, or connect to memcached, Redis, and a bunch of other storage > backends. > > (Disclaimer: i?m one of the maintainers of that package). > > If, however, you don?t need a persistent(ish) cache, the simplest solution > is probably to set g.my_storage to a dictionary and use the dictionary > methods to access it. > > Best, > Gergely > > > Gergely Polonkai > [image: https://]about.me/gergely.polonkai > > > > > f?s., 26. j?l. 2019 kl. 13:16 skrifa?i Ben Duncan : > >> Ok, I'm coming form web2py and adopting Flask >> However, one of the things I had under web2py is a module called Storage. >> It worked much like a memcach database. >> >> See: https://web2py.readthedocs.io/en/latest/storage.html >> >> Is there anything like that in Flask? >> I've adapted the storage module for my use in Flask, but I'd rather use >> anything native >> to Flask. >> >> Thanks .. >> >> *Ben Duncan* >> DBA / Chief Software Architect >> Mississippi State Supreme Court >> Electronic Filing Division >> _______________________________________________ >> Flask mailing list >> Flask at python.org >> https://mail.python.org/mailman/listinfo/flask >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gergely at polonkai.eu Fri Jul 26 10:49:29 2019 From: gergely at polonkai.eu (Gergely Polonkai) Date: Fri, 26 Jul 2019 16:49:29 +0200 Subject: [Flask] Storage Context In-Reply-To: References: Message-ID: That?s exactly what i found. That callable list thing is nothing i have heard before and can?t really see a use case. The persistent dict thing is what I?d use a cache for, Flask-Caching or not. Best, Gergely On Fri, 26 Jul 2019, 16:45 Ben Duncan, wrote: > Kinda sorta, more like a persistence dict / list > > Best documentation I could find describing it: > > Module storagesource code > > > This file is part of the web2py Web Framework > Copyrighted by Massimo Di Pierro > License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html) > > Provides: > > - List; like list but returns None instead of IndexOutOfBounds > - Storage; like dictionary allowing also for `obj.foo` for `obj['foo']` > > > > > Classes [hide private > > ] > List > > Like a regular python list but a[i] if i is out of bounds return None > instead of IndexOutOfBounds > Storage > > A Storage object is like a dictionary except `obj.foo` can be used in > addition to `obj['foo']`. > StorageList > > like Storage but missing elements default to [] instead of None > Settings > > Messages > > Functions [hide private > > ] > > load_storage(filename) source code > > > save_storage(storage, filename) source code > > Home > > Trees > > Indices > > Help > > > > *Ben Duncan* > DBA / Chief Software Architect > Mississippi State Supreme Court > Electronic Filing Division > > > On Fri, Jul 26, 2019 at 8:26 AM Gergely Polonkai > wrote: > >> I never used web2py, but from the documentation it looks like some basic >> caching functionality. If this is the case, you should check Flask-Caching >> (a fork of the unmaintained Flask-Cache). It can store the cache in memory >> or in a file, or connect to memcached, Redis, and a bunch of other storage >> backends. >> >> (Disclaimer: i?m one of the maintainers of that package). >> >> If, however, you don?t need a persistent(ish) cache, the simplest >> solution is probably to set g.my_storage to a dictionary and use the >> dictionary methods to access it. >> >> Best, >> Gergely >> >> >> Gergely Polonkai >> [image: https://]about.me/gergely.polonkai >> >> >> >> >> f?s., 26. j?l. 2019 kl. 13:16 skrifa?i Ben Duncan : >> >>> Ok, I'm coming form web2py and adopting Flask >>> However, one of the things I had under web2py is a module called Storage. >>> It worked much like a memcach database. >>> >>> See: https://web2py.readthedocs.io/en/latest/storage.html >>> >>> Is there anything like that in Flask? >>> I've adapted the storage module for my use in Flask, but I'd rather use >>> anything native >>> to Flask. >>> >>> Thanks .. >>> >>> *Ben Duncan* >>> DBA / Chief Software Architect >>> Mississippi State Supreme Court >>> Electronic Filing Division >>> _______________________________________________ >>> Flask mailing list >>> Flask at python.org >>> https://mail.python.org/mailman/listinfo/flask >>> >> -------------- next part -------------- An HTML attachment was scrubbed... URL: From linux4ms at gmail.com Fri Jul 26 11:07:39 2019 From: linux4ms at gmail.com (Ben Duncan) Date: Fri, 26 Jul 2019 10:07:39 -0500 Subject: [Flask] Storage Context In-Reply-To: References: Message-ID: Ok, looks like Flask-Cache maybe what I am looking for. I will RTFM some more ... Thanks .. *Ben Duncan* DBA / Chief Software Architect Mississippi State Supreme Court Electronic Filing Division On Fri, Jul 26, 2019 at 9:49 AM Gergely Polonkai wrote: > That?s exactly what i found. That callable list thing is nothing i have > heard before and can?t really see a use case. > > The persistent dict thing is what I?d use a cache for, Flask-Caching or > not. > > Best, > Gergely > > On Fri, 26 Jul 2019, 16:45 Ben Duncan, wrote: > >> Kinda sorta, more like a persistence dict / list >> >> Best documentation I could find describing it: >> >> Module storagesource code >> >> >> This file is part of the web2py Web Framework >> Copyrighted by Massimo Di Pierro >> License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html) >> >> Provides: >> >> - List; like list but returns None instead of IndexOutOfBounds >> - Storage; like dictionary allowing also for `obj.foo` for `obj['foo']` >> >> >> >> >> Classes [hide private >> >> ] >> List >> >> Like a regular python list but a[i] if i is out of bounds return None >> instead of IndexOutOfBounds >> Storage >> >> A Storage object is like a dictionary except `obj.foo` can be used in >> addition to `obj['foo']`. >> StorageList >> >> like Storage but missing elements default to [] instead of None >> Settings >> >> Messages >> >> Functions [hide private >> >> ] >> >> load_storage(filename) source code >> >> >> save_storage(storage, filename) source code >> >> Home >> >> Trees >> >> Indices >> >> Help >> >> >> >> *Ben Duncan* >> DBA / Chief Software Architect >> Mississippi State Supreme Court >> Electronic Filing Division >> >> >> On Fri, Jul 26, 2019 at 8:26 AM Gergely Polonkai >> wrote: >> >>> I never used web2py, but from the documentation it looks like some basic >>> caching functionality. If this is the case, you should check Flask-Caching >>> (a fork of the unmaintained Flask-Cache). It can store the cache in memory >>> or in a file, or connect to memcached, Redis, and a bunch of other storage >>> backends. >>> >>> (Disclaimer: i?m one of the maintainers of that package). >>> >>> If, however, you don?t need a persistent(ish) cache, the simplest >>> solution is probably to set g.my_storage to a dictionary and use the >>> dictionary methods to access it. >>> >>> Best, >>> Gergely >>> >>> >>> Gergely Polonkai >>> [image: https://]about.me/gergely.polonkai >>> >>> >>> >>> >>> f?s., 26. j?l. 2019 kl. 13:16 skrifa?i Ben Duncan : >>> >>>> Ok, I'm coming form web2py and adopting Flask >>>> However, one of the things I had under web2py is a module called >>>> Storage. >>>> It worked much like a memcach database. >>>> >>>> See: https://web2py.readthedocs.io/en/latest/storage.html >>>> >>>> Is there anything like that in Flask? >>>> I've adapted the storage module for my use in Flask, but I'd rather use >>>> anything native >>>> to Flask. >>>> >>>> Thanks .. >>>> >>>> *Ben Duncan* >>>> DBA / Chief Software Architect >>>> Mississippi State Supreme Court >>>> Electronic Filing Division >>>> _______________________________________________ >>>> Flask mailing list >>>> Flask at python.org >>>> https://mail.python.org/mailman/listinfo/flask >>>> >>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From gergely at polonkai.eu Fri Jul 26 11:11:36 2019 From: gergely at polonkai.eu (Gergely Polonkai) Date: Fri, 26 Jul 2019 17:11:36 +0200 Subject: [Flask] Storage Context In-Reply-To: References: Message-ID: If you are talking about https://github.com/thadeusb/Flask-cache, please be aware that that module is unmaintained for 5 years now. Flask-Caching ( https://flask-caching.readthedocs.io/en/latest/) is a maintained fork of that project. On Fri, 26 Jul 2019, 17:07 Ben Duncan, wrote: > Ok, looks like Flask-Cache maybe what I am looking for. > I will RTFM some more ... > > Thanks .. > > *Ben Duncan* > DBA / Chief Software Architect > Mississippi State Supreme Court > Electronic Filing Division > > > On Fri, Jul 26, 2019 at 9:49 AM Gergely Polonkai > wrote: > >> That?s exactly what i found. That callable list thing is nothing i have >> heard before and can?t really see a use case. >> >> The persistent dict thing is what I?d use a cache for, Flask-Caching or >> not. >> >> Best, >> Gergely >> >> On Fri, 26 Jul 2019, 16:45 Ben Duncan, wrote: >> >>> Kinda sorta, more like a persistence dict / list >>> >>> Best documentation I could find describing it: >>> >>> Module storagesource code >>> >>> >>> This file is part of the web2py Web Framework >>> Copyrighted by Massimo Di Pierro >>> License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html) >>> >>> Provides: >>> >>> - List; like list but returns None instead of IndexOutOfBounds >>> - Storage; like dictionary allowing also for `obj.foo` for `obj['foo']` >>> >>> >>> >>> >>> Classes [hide private >>> >>> ] >>> List >>> >>> Like a regular python list but a[i] if i is out of bounds return None >>> instead of IndexOutOfBounds >>> Storage >>> >>> A Storage object is like a dictionary except `obj.foo` can be used in >>> addition to `obj['foo']`. >>> StorageList >>> >>> like Storage but missing elements default to [] instead of None >>> Settings >>> >>> Messages >>> >>> Functions [hide private >>> >>> ] >>> >>> load_storage(filename) source code >>> >>> >>> save_storage(storage, filename) source code >>> >>> Home >>> >>> Trees >>> >>> Indices >>> >>> Help >>> >>> >>> >>> *Ben Duncan* >>> DBA / Chief Software Architect >>> Mississippi State Supreme Court >>> Electronic Filing Division >>> >>> >>> On Fri, Jul 26, 2019 at 8:26 AM Gergely Polonkai >>> wrote: >>> >>>> I never used web2py, but from the documentation it looks like some >>>> basic caching functionality. If this is the case, you should check >>>> Flask-Caching (a fork of the unmaintained Flask-Cache). It can store the >>>> cache in memory or in a file, or connect to memcached, Redis, and a bunch >>>> of other storage backends. >>>> >>>> (Disclaimer: i?m one of the maintainers of that package). >>>> >>>> If, however, you don?t need a persistent(ish) cache, the simplest >>>> solution is probably to set g.my_storage to a dictionary and use the >>>> dictionary methods to access it. >>>> >>>> Best, >>>> Gergely >>>> >>>> >>>> Gergely Polonkai >>>> [image: https://]about.me/gergely.polonkai >>>> >>>> >>>> >>>> >>>> f?s., 26. j?l. 2019 kl. 13:16 skrifa?i Ben Duncan : >>>> >>>>> Ok, I'm coming form web2py and adopting Flask >>>>> However, one of the things I had under web2py is a module called >>>>> Storage. >>>>> It worked much like a memcach database. >>>>> >>>>> See: https://web2py.readthedocs.io/en/latest/storage.html >>>>> >>>>> Is there anything like that in Flask? >>>>> I've adapted the storage module for my use in Flask, but I'd rather >>>>> use anything native >>>>> to Flask. >>>>> >>>>> Thanks .. >>>>> >>>>> *Ben Duncan* >>>>> DBA / Chief Software Architect >>>>> Mississippi State Supreme Court >>>>> Electronic Filing Division >>>>> _______________________________________________ >>>>> Flask mailing list >>>>> Flask at python.org >>>>> https://mail.python.org/mailman/listinfo/flask >>>>> >>>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From skip.montanaro at gmail.com Fri Jul 26 11:27:28 2019 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Fri, 26 Jul 2019 10:27:28 -0500 Subject: [Flask] Logging always ASCII? Message-ID: I have a Flask app (Python 3.6.8, Flask 1.0.2) running behind uwsgi (should that make a difference) which seems constitutionally incapable of logging UTF-8 strings. I'm not fussing with the app logger Flask creates other than to set PROD_LOG_FORMAT and DEBUG_LOG_FORMAT attributes ahead of app creation. I am running with PYTHONIOENCODING="utf-8" and log that fact: [2019-07-26 10:11:54,537] INFO in server: IO encoding: utf-8 Standard output and standard error are redirected to a file (logging should be to stderr I think). This suggests that sys.stderr should accept UTF-8: % PYTHONIOENCODING=utf-8 python Python 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:22:34) [GCC 7.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> sys.stderr <_io.TextIOWrapper name='' mode='w' encoding='utf-8'> Still, if I attempt to log a message which incorporates some UTF-8 values, it raises UnicodeEncodeError: UnicodeEncodeError: 'ascii' codec can't encode characters in position 65-85: ordinal not in range(128). I could understand if I perhaps was mistaken about the problematic value not being UTF-8, but why is the ascii codec involved here? Thanks, Skip Montanaro From linux4ms at gmail.com Fri Jul 26 11:34:13 2019 From: linux4ms at gmail.com (Ben Duncan) Date: Fri, 26 Jul 2019 10:34:13 -0500 Subject: [Flask] Storage Context In-Reply-To: References: Message-ID: Thansk for the info - I used : pip install flask-caching , is that the right one? *Ben Duncan* DBA / Chief Software Architect Mississippi State Supreme Court Electronic Filing Division On Fri, Jul 26, 2019 at 10:11 AM Gergely Polonkai wrote: > If you are talking about https://github.com/thadeusb/Flask-cache, please > be aware that that module is unmaintained for 5 years now. Flask-Caching ( > https://flask-caching.readthedocs.io/en/latest/) is a maintained fork of > that project. > > On Fri, 26 Jul 2019, 17:07 Ben Duncan, wrote: > >> Ok, looks like Flask-Cache maybe what I am looking for. >> I will RTFM some more ... >> >> Thanks .. >> >> *Ben Duncan* >> DBA / Chief Software Architect >> Mississippi State Supreme Court >> Electronic Filing Division >> >> >> On Fri, Jul 26, 2019 at 9:49 AM Gergely Polonkai >> wrote: >> >>> That?s exactly what i found. That callable list thing is nothing i have >>> heard before and can?t really see a use case. >>> >>> The persistent dict thing is what I?d use a cache for, Flask-Caching or >>> not. >>> >>> Best, >>> Gergely >>> >>> On Fri, 26 Jul 2019, 16:45 Ben Duncan, wrote: >>> >>>> Kinda sorta, more like a persistence dict / list >>>> >>>> Best documentation I could find describing it: >>>> >>>> Module storagesource code >>>> >>>> >>>> This file is part of the web2py Web Framework >>>> Copyrighted by Massimo Di Pierro >>>> License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html) >>>> >>>> Provides: >>>> >>>> - List; like list but returns None instead of IndexOutOfBounds >>>> - Storage; like dictionary allowing also for `obj.foo` for `obj['foo']` >>>> >>>> >>>> >>>> >>>> Classes [hide private >>>> >>>> ] >>>> List >>>> >>>> Like a regular python list but a[i] if i is out of bounds return None >>>> instead of IndexOutOfBounds >>>> Storage >>>> >>>> A Storage object is like a dictionary except `obj.foo` can be used in >>>> addition to `obj['foo']`. >>>> StorageList >>>> >>>> like Storage but missing elements default to [] instead of None >>>> Settings >>>> >>>> Messages >>>> >>>> Functions [hide private >>>> >>>> ] >>>> >>>> load_storage(filename) source code >>>> >>>> >>>> save_storage(storage, filename) source code >>>> >>>> Home >>>> >>>> Trees >>>> >>>> Indices >>>> >>>> Help >>>> >>>> >>>> >>>> *Ben Duncan* >>>> DBA / Chief Software Architect >>>> Mississippi State Supreme Court >>>> Electronic Filing Division >>>> >>>> >>>> On Fri, Jul 26, 2019 at 8:26 AM Gergely Polonkai >>>> wrote: >>>> >>>>> I never used web2py, but from the documentation it looks like some >>>>> basic caching functionality. If this is the case, you should check >>>>> Flask-Caching (a fork of the unmaintained Flask-Cache). It can store the >>>>> cache in memory or in a file, or connect to memcached, Redis, and a bunch >>>>> of other storage backends. >>>>> >>>>> (Disclaimer: i?m one of the maintainers of that package). >>>>> >>>>> If, however, you don?t need a persistent(ish) cache, the simplest >>>>> solution is probably to set g.my_storage to a dictionary and use the >>>>> dictionary methods to access it. >>>>> >>>>> Best, >>>>> Gergely >>>>> >>>>> >>>>> Gergely Polonkai >>>>> [image: https://]about.me/gergely.polonkai >>>>> >>>>> >>>>> >>>>> >>>>> f?s., 26. j?l. 2019 kl. 13:16 skrifa?i Ben Duncan >>>> >: >>>>> >>>>>> Ok, I'm coming form web2py and adopting Flask >>>>>> However, one of the things I had under web2py is a module called >>>>>> Storage. >>>>>> It worked much like a memcach database. >>>>>> >>>>>> See: https://web2py.readthedocs.io/en/latest/storage.html >>>>>> >>>>>> Is there anything like that in Flask? >>>>>> I've adapted the storage module for my use in Flask, but I'd rather >>>>>> use anything native >>>>>> to Flask. >>>>>> >>>>>> Thanks .. >>>>>> >>>>>> *Ben Duncan* >>>>>> DBA / Chief Software Architect >>>>>> Mississippi State Supreme Court >>>>>> Electronic Filing Division >>>>>> _______________________________________________ >>>>>> Flask mailing list >>>>>> Flask at python.org >>>>>> https://mail.python.org/mailman/listinfo/flask >>>>>> >>>>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From gergely at polonkai.eu Fri Jul 26 11:35:23 2019 From: gergely at polonkai.eu (Gergely Polonkai) Date: Fri, 26 Jul 2019 17:35:23 +0200 Subject: [Flask] Storage Context In-Reply-To: References: Message-ID: Should be, yes. Have fun using it ? On Fri, 26 Jul 2019, 17:34 Ben Duncan, wrote: > Thansk for the info - I used : > pip install flask-caching , is that the right one? > > *Ben Duncan* > DBA / Chief Software Architect > Mississippi State Supreme Court > Electronic Filing Division > > > On Fri, Jul 26, 2019 at 10:11 AM Gergely Polonkai > wrote: > >> If you are talking about https://github.com/thadeusb/Flask-cache, please >> be aware that that module is unmaintained for 5 years now. Flask-Caching ( >> https://flask-caching.readthedocs.io/en/latest/) is a maintained fork of >> that project. >> >> On Fri, 26 Jul 2019, 17:07 Ben Duncan, wrote: >> >>> Ok, looks like Flask-Cache maybe what I am looking for. >>> I will RTFM some more ... >>> >>> Thanks .. >>> >>> *Ben Duncan* >>> DBA / Chief Software Architect >>> Mississippi State Supreme Court >>> Electronic Filing Division >>> >>> >>> On Fri, Jul 26, 2019 at 9:49 AM Gergely Polonkai >>> wrote: >>> >>>> That?s exactly what i found. That callable list thing is nothing i have >>>> heard before and can?t really see a use case. >>>> >>>> The persistent dict thing is what I?d use a cache for, Flask-Caching or >>>> not. >>>> >>>> Best, >>>> Gergely >>>> >>>> On Fri, 26 Jul 2019, 16:45 Ben Duncan, wrote: >>>> >>>>> Kinda sorta, more like a persistence dict / list >>>>> >>>>> Best documentation I could find describing it: >>>>> >>>>> Module storagesource code >>>>> >>>>> >>>>> This file is part of the web2py Web Framework >>>>> Copyrighted by Massimo Di Pierro >>>>> License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html) >>>>> >>>>> Provides: >>>>> >>>>> - List; like list but returns None instead of IndexOutOfBounds >>>>> - Storage; like dictionary allowing also for `obj.foo` for `obj['foo']` >>>>> >>>>> >>>>> >>>>> >>>>> Classes [hide private >>>>> >>>>> ] >>>>> List >>>>> >>>>> Like a regular python list but a[i] if i is out of bounds return None >>>>> instead of IndexOutOfBounds >>>>> Storage >>>>> >>>>> A Storage object is like a dictionary except `obj.foo` can be used in >>>>> addition to `obj['foo']`. >>>>> StorageList >>>>> >>>>> like Storage but missing elements default to [] instead of None >>>>> Settings >>>>> >>>>> Messages >>>>> >>>>> Functions [hide private >>>>> >>>>> ] >>>>> >>>>> load_storage(filename) source code >>>>> >>>>> >>>>> save_storage(storage, filename) source code >>>>> >>>>> Home >>>>> >>>>> Trees >>>>> >>>>> Indices >>>>> >>>>> Help >>>>> >>>>> >>>>> >>>>> *Ben Duncan* >>>>> DBA / Chief Software Architect >>>>> Mississippi State Supreme Court >>>>> Electronic Filing Division >>>>> >>>>> >>>>> On Fri, Jul 26, 2019 at 8:26 AM Gergely Polonkai >>>>> wrote: >>>>> >>>>>> I never used web2py, but from the documentation it looks like some >>>>>> basic caching functionality. If this is the case, you should check >>>>>> Flask-Caching (a fork of the unmaintained Flask-Cache). It can store the >>>>>> cache in memory or in a file, or connect to memcached, Redis, and a bunch >>>>>> of other storage backends. >>>>>> >>>>>> (Disclaimer: i?m one of the maintainers of that package). >>>>>> >>>>>> If, however, you don?t need a persistent(ish) cache, the simplest >>>>>> solution is probably to set g.my_storage to a dictionary and use the >>>>>> dictionary methods to access it. >>>>>> >>>>>> Best, >>>>>> Gergely >>>>>> >>>>>> >>>>>> Gergely Polonkai >>>>>> [image: https://]about.me/gergely.polonkai >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> f?s., 26. j?l. 2019 kl. 13:16 skrifa?i Ben Duncan >>>>> >: >>>>>> >>>>>>> Ok, I'm coming form web2py and adopting Flask >>>>>>> However, one of the things I had under web2py is a module called >>>>>>> Storage. >>>>>>> It worked much like a memcach database. >>>>>>> >>>>>>> See: https://web2py.readthedocs.io/en/latest/storage.html >>>>>>> >>>>>>> Is there anything like that in Flask? >>>>>>> I've adapted the storage module for my use in Flask, but I'd rather >>>>>>> use anything native >>>>>>> to Flask. >>>>>>> >>>>>>> Thanks .. >>>>>>> >>>>>>> *Ben Duncan* >>>>>>> DBA / Chief Software Architect >>>>>>> Mississippi State Supreme Court >>>>>>> Electronic Filing Division >>>>>>> _______________________________________________ >>>>>>> Flask mailing list >>>>>>> Flask at python.org >>>>>>> https://mail.python.org/mailman/listinfo/flask >>>>>>> >>>>>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From linux4ms at gmail.com Fri Jul 26 11:46:24 2019 From: linux4ms at gmail.com (Ben Duncan) Date: Fri, 26 Jul 2019 10:46:24 -0500 Subject: [Flask] Storage Context In-Reply-To: References: Message-ID: Thanks, I will! *Ben Duncan* DBA / Chief Software Architect Mississippi State Supreme Court Electronic Filing Division On Fri, Jul 26, 2019 at 10:35 AM Gergely Polonkai wrote: > Should be, yes. Have fun using it ? > > On Fri, 26 Jul 2019, 17:34 Ben Duncan, wrote: > >> Thansk for the info - I used : >> pip install flask-caching , is that the right one? >> >> *Ben Duncan* >> DBA / Chief Software Architect >> Mississippi State Supreme Court >> Electronic Filing Division >> >> >> On Fri, Jul 26, 2019 at 10:11 AM Gergely Polonkai >> wrote: >> >>> If you are talking about https://github.com/thadeusb/Flask-cache, >>> please be aware that that module is unmaintained for 5 years now. >>> Flask-Caching (https://flask-caching.readthedocs.io/en/latest/) is a >>> maintained fork of that project. >>> >>> On Fri, 26 Jul 2019, 17:07 Ben Duncan, wrote: >>> >>>> Ok, looks like Flask-Cache maybe what I am looking for. >>>> I will RTFM some more ... >>>> >>>> Thanks .. >>>> >>>> *Ben Duncan* >>>> DBA / Chief Software Architect >>>> Mississippi State Supreme Court >>>> Electronic Filing Division >>>> >>>> >>>> On Fri, Jul 26, 2019 at 9:49 AM Gergely Polonkai >>>> wrote: >>>> >>>>> That?s exactly what i found. That callable list thing is nothing i >>>>> have heard before and can?t really see a use case. >>>>> >>>>> The persistent dict thing is what I?d use a cache for, Flask-Caching >>>>> or not. >>>>> >>>>> Best, >>>>> Gergely >>>>> >>>>> On Fri, 26 Jul 2019, 16:45 Ben Duncan, wrote: >>>>> >>>>>> Kinda sorta, more like a persistence dict / list >>>>>> >>>>>> Best documentation I could find describing it: >>>>>> >>>>>> Module storagesource code >>>>>> >>>>>> >>>>>> This file is part of the web2py Web Framework >>>>>> Copyrighted by Massimo Di Pierro >>>>>> License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html) >>>>>> >>>>>> Provides: >>>>>> >>>>>> - List; like list but returns None instead of IndexOutOfBounds >>>>>> - Storage; like dictionary allowing also for `obj.foo` for `obj['foo']` >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> Classes [hide private >>>>>> >>>>>> ] >>>>>> List >>>>>> >>>>>> Like a regular python list but a[i] if i is out of bounds return None >>>>>> instead of IndexOutOfBounds >>>>>> Storage >>>>>> >>>>>> A Storage object is like a dictionary except `obj.foo` can be used in >>>>>> addition to `obj['foo']`. >>>>>> StorageList >>>>>> >>>>>> like Storage but missing elements default to [] instead of None >>>>>> Settings >>>>>> >>>>>> Messages >>>>>> >>>>>> Functions [hide private >>>>>> >>>>>> ] >>>>>> >>>>>> load_storage(filename) source code >>>>>> >>>>>> >>>>>> save_storage(storage, filename) source code >>>>>> >>>>>> Home >>>>>> >>>>>> Trees >>>>>> >>>>>> Indices >>>>>> >>>>>> Help >>>>>> >>>>>> >>>>>> >>>>>> *Ben Duncan* >>>>>> DBA / Chief Software Architect >>>>>> Mississippi State Supreme Court >>>>>> Electronic Filing Division >>>>>> >>>>>> >>>>>> On Fri, Jul 26, 2019 at 8:26 AM Gergely Polonkai >>>>>> wrote: >>>>>> >>>>>>> I never used web2py, but from the documentation it looks like some >>>>>>> basic caching functionality. If this is the case, you should check >>>>>>> Flask-Caching (a fork of the unmaintained Flask-Cache). It can store the >>>>>>> cache in memory or in a file, or connect to memcached, Redis, and a bunch >>>>>>> of other storage backends. >>>>>>> >>>>>>> (Disclaimer: i?m one of the maintainers of that package). >>>>>>> >>>>>>> If, however, you don?t need a persistent(ish) cache, the simplest >>>>>>> solution is probably to set g.my_storage to a dictionary and use the >>>>>>> dictionary methods to access it. >>>>>>> >>>>>>> Best, >>>>>>> Gergely >>>>>>> >>>>>>> >>>>>>> Gergely Polonkai >>>>>>> [image: https://]about.me/gergely.polonkai >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> f?s., 26. j?l. 2019 kl. 13:16 skrifa?i Ben Duncan < >>>>>>> linux4ms at gmail.com>: >>>>>>> >>>>>>>> Ok, I'm coming form web2py and adopting Flask >>>>>>>> However, one of the things I had under web2py is a module called >>>>>>>> Storage. >>>>>>>> It worked much like a memcach database. >>>>>>>> >>>>>>>> See: https://web2py.readthedocs.io/en/latest/storage.html >>>>>>>> >>>>>>>> Is there anything like that in Flask? >>>>>>>> I've adapted the storage module for my use in Flask, but I'd rather >>>>>>>> use anything native >>>>>>>> to Flask. >>>>>>>> >>>>>>>> Thanks .. >>>>>>>> >>>>>>>> *Ben Duncan* >>>>>>>> DBA / Chief Software Architect >>>>>>>> Mississippi State Supreme Court >>>>>>>> Electronic Filing Division >>>>>>>> _______________________________________________ >>>>>>>> Flask mailing list >>>>>>>> Flask at python.org >>>>>>>> https://mail.python.org/mailman/listinfo/flask >>>>>>>> >>>>>>> -------------- next part -------------- An HTML attachment was scrubbed... URL: From linux4ms at gmail.com Fri Jul 26 13:56:32 2019 From: linux4ms at gmail.com (Ben Duncan) Date: Fri, 26 Jul 2019 12:56:32 -0500 Subject: [Flask] Menus and Sub Menus Message-ID: Can a flask macro in the template be reenterent ? Something along these lines: {% macro render_menu(menu_item, sep=False) %} {% endmacro %} Thanks .. *Ben Duncan* DBA / Chief Software Architect Mississippi State Supreme Court Electronic Filing Division -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at cskk.id.au Fri Jul 26 20:33:05 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 27 Jul 2019 10:33:05 +1000 Subject: [Flask] Logging always ASCII? In-Reply-To: References: Message-ID: <20190727003305.GA16079@cskk.homeip.net> On 26Jul2019 10:27, Skip Montanaro wrote: >I have a Flask app (Python 3.6.8, Flask 1.0.2) running behind uwsgi >(should that make a difference) which seems constitutionally incapable >of logging UTF-8 strings. I'm not fussing with the app logger Flask >creates other than to set PROD_LOG_FORMAT and DEBUG_LOG_FORMAT >attributes ahead of app creation. I am running with >PYTHONIOENCODING="utf-8" and log that fact: > >[2019-07-26 10:11:54,537] INFO in server: IO encoding: utf-8 How is that established? By querying some attribute of sys.stderr? >Standard output and standard error are redirected to a file (logging >should be to stderr I think). This suggests that sys.stderr should >accept UTF-8: > >% PYTHONIOENCODING=utf-8 python >Python 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:22:34) >[GCC 7.3.0] on linux >Type "help", "copyright", "credits" or "license" for more information. >>>> sys.stderr ><_io.TextIOWrapper name='' mode='w' encoding='utf-8'> What about this invocation? % PYTHONIOENCODING=utf-8 python 2>some_filename i.e. not inheriting the terminal stderr. >Still, if I attempt to log a message which incorporates some UTF-8 >values, it raises UnicodeEncodeError: > >UnicodeEncodeError: 'ascii' codec can't encode characters in position >65-85: ordinal not in range(128). > >I could understand if I perhaps was mistaken about the problematic >value not being UTF-8, but why is the ascii codec involved here? Do you know if this is happening at write-out time or deeper inside the logging module when it is assembling the message string? Cheers, Cameron Simpson