<div dir="ltr"><div>Oh yes Scott I am using flask_login...or at least trying to use it.<br><br></div>Regards<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jul 2, 2019 at 4:34 PM Abdul Mohammed <<a href="mailto:imonikemohammed@gmail.com">imonikemohammed@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><div><div><div>Hello<br></div>Thanks Leni, Scott for replying. I had tried that previously.<br></div>user.is_authenticated cannot be set. It throws an error.<br></div>I had stumbled upon a tutorial where user.authenticated had been set and so thought that was the proper way to modify the value <br></div>of user.is_authenticated. When I set user.authenticated in the code, the app didn't throw any errors which further bolstered my<br></div><div>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 <br></div><div>the next view. Just after setting user.authenticated to True, I issue a print statement to check the the value user.is_authenticated<br></div><div>and it shows True. By the time login_user(user) logs me in, I issue another print statement and user.is_authenticated has reverted <br></div><div>to False.<br> </div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jul 1, 2019 at 11:15 PM <<a href="mailto:flask-request@python.org" target="_blank">flask-request@python.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Send Flask mailing list submissions to<br>
        <a href="mailto:flask@python.org" target="_blank">flask@python.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="https://mail.python.org/mailman/listinfo/flask" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/flask</a><br>
or, via email, send a message with subject or body 'help' to<br>
        <a href="mailto:flask-request@python.org" target="_blank">flask-request@python.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:flask-owner@python.org" target="_blank">flask-owner@python.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of Flask digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
   1. Re: Unable to set current_user.authenticated to True<br>
      (Leni Kadali Mutungi)<br>
   2. Re: Flask Digest, Vol 49, Issue 1 (Unable to set<br>
      current_user.authenticated to True) (sidwoodstock .)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Mon, 1 Jul 2019 20:03:04 +0300<br>
From: Leni Kadali Mutungi <<a href="mailto:lenikmutungi@gmail.com" target="_blank">lenikmutungi@gmail.com</a>><br>
To: <a href="mailto:flask@python.org" target="_blank">flask@python.org</a><br>
Subject: Re: [Flask] Unable to set current_user.authenticated to True<br>
Message-ID: <<a href="mailto:177572e2-a71d-a250-e6ec-defcce5b5161@gmail.com" target="_blank">177572e2-a71d-a250-e6ec-defcce5b5161@gmail.com</a>><br>
Content-Type: text/plain; charset=utf-8; format=flowed<br>
<br>
I think you mean to set it as `current_user.is_authenticated = True`.<br>
<br>
On 7/1/19 6:14 PM, Abdul Mohammed wrote:<br>
> Hello everyone,<br>
> ????????????????? I am trying to toggle between "Sign in" and "Sign <br>
> out" links using the current_user.is_authenticated variable such that <br>
> when it returns False, the "Sign in" is displayed and when True the <br>
> "Sign out" link is displayed. At some point in the login code I set <br>
> current_user.authenticated = True. The thing is that by the I am <br>
> successfully logged?in and presented with the next view, it is the <br>
> "Sign in" link that is still displayed. When I check <br>
> current_user.is_authenticated, it returns False, even though I had <br>
> explicitly set it to True. Please can anyone point out what I am might <br>
> be doing?wrong? Here is my code:<br>
><br>
> I have a base.html file that contains the "Sign in" and "Sign out" <br>
> links that is extended by the other templates:<br>
><br>
> <ul class="nav navbar-nav navbar-right"><br>
> ?? {% if (current_user.is_authenticated) %}<br>
> ?? <li><a href="{{ url_for('logout') }}">Sign Out</a></li><br>
> ?? {% else %}<br>
> ?? <li><a href="{{ url_for('index') }}">Sign In</a></li><br>
> ?? {% endif %}<br>
> </ul><br>
><br>
> <body><br>
> {% block page_content %}{% endblock %}<br>
> </body><br>
><br>
><br>
> ?When the app first loads in the browser it displays a login form, <br>
> login.html:<br>
><br>
> ?{% extends "base.html" %}<br>
><br>
> {% block content %}<br>
> ??? {% import "bootstrap/wtf.html" as wtf %}<br>
> ??? {% block title %}Flasky - Login{% endblock %}<br>
> ??? {% block page_content %}<br>
> ??? <div class="page-header"><br>
> ??? ??? <h1>Login</h1><br>
> ??? </div><br>
> ??? <div class="col-md-4"><br>
> ??? ??? {{ wtf.quick_form(form) }}<br>
> ??? </div><br>
> ??? {% endblock %}<br>
> {% endblock %}<br>
><br>
> When a user logs in, it loads a template dashboard.html that displays <br>
> a map. The top part looks like this:<br>
><br>
> {% extends "base.html" %}<br>
><br>
> {% block page_content %}<br>
> <html><br>
> ?<head><br>
> ?? <title>Lagos Map</title><br>
> ?? <link rel="stylesheet" <br>
> href="<a href="https://unpkg.com/leaflet@1.1.0/dist/leaflet.css" rel="noreferrer" target="_blank">https://unpkg.com/leaflet@1.1.0/dist/leaflet.css</a>"<br>
> integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw=="<br>
> ?? crossorigin=""/><br>
> ?? <script src="<a href="https://unpkg.com/leaflet@1.1.0/dist/leaflet.js" rel="noreferrer" target="_blank">https://unpkg.com/leaflet@1.1.0/dist/leaflet.js</a>"<br>
> integrity="sha512-mNqn2Wg7tSToJhvHcqfzLMU6J4mkOImSPTxVZAdo+lcPlk+GhZmYgACEe0x35K7YzW1zJ7XyJV/TT1MrdXvMcA=="<br>
> ?? crossorigin=""></script><br>
> ?? <script <br>
> src="<a href="https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.js" rel="noreferrer" target="_blank">https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.js</a>"></script><br>
> ?? <link rel="stylesheet" <br>
> href="<a href="https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css" rel="noreferrer" target="_blank">https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css</a>" <br>
> /><br>
> ?? <link rel="stylesheet" <br>
> href="<a href="https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css" rel="noreferrer" target="_blank">https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css</a>" <br>
> /><br>
> ?? <script <br>
> src="<a href="https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.js" rel="noreferrer" target="_blank">https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.js</a>"></script><br>
> ?? <script <br>
> src="<a href="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js" rel="noreferrer" target="_blank">https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js</a>"></script><br>
> ? ...<br>
> ? ...<br>
><br>
> And these are the relevant routes:<br>
><br>
> @app.route('/',methods=['GET','POST'])<br>
> def index():<br>
> ?? ?? form = LoginForm()<br>
> ????? if form.validate_on_submit():<br>
> ??? ????? user = User.query.filter_by(email=form.email.data).first()<br>
> ??? ????? if user is not None and user.check_password(form.password.data):<br>
> ??? ??? ????? user.authenticated = True<br>
> ??? ??? ????? current_user = user<br>
> ??? ??? ????? db.session.add(current_user)<br>
> ??? ??? ????? db.session.commit()<br>
> ??? ??? ????? login_user(current_user, form.remember_me.data)<br>
> ??? ??? ?? ?? return redirect(request.args.get('next') or <br>
> url_for('dashboard'))<br>
> ??? ????? flash('Invalid username or password.')<br>
> ?????? return render_template('auth/login.html', form=form)<br>
><br>
> @app.route('/dashboard')<br>
> def dashboard():<br>
> ????? return render_template("dashboard.html")<br>
><br>
> Thank you for your time.<br>
><br>
> _______________________________________________<br>
> Flask mailing list<br>
> <a href="mailto:Flask@python.org" target="_blank">Flask@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/flask" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/flask</a><br>
<br>
-- <br>
-- Kind regards,<br>
Leni Kadali Mutungi<br>
<br>
<br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Mon, 1 Jul 2019 15:14:24 -0700<br>
From: "sidwoodstock ." <<a href="mailto:sidwoodstock@gmail.com" target="_blank">sidwoodstock@gmail.com</a>><br>
To: <a href="mailto:flask@python.org" target="_blank">flask@python.org</a><br>
Subject: Re: [Flask] Flask Digest, Vol 49, Issue 1 (Unable to set<br>
        current_user.authenticated to True)<br>
Message-ID:<br>
        <<a href="mailto:CALovGGPvjb8Zh%2BBKOx6kj7%2BZQ71fj1BJv5WRYbrxxijyFnMKgQ@mail.gmail.com" target="_blank">CALovGGPvjb8Zh+BKOx6kj7+ZQ71fj1BJv5WRYbrxxijyFnMKgQ@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
At a cursory glance I would say that user.is_authenticated is not the same<br>
as user.authenticated..<br>
<br>
Are you using Flask-Login?<br>
<br>
-Scott Woodstock<br>
<br>
On Mon, Jul 1, 2019 at 9:01 AM <<a href="mailto:flask-request@python.org" target="_blank">flask-request@python.org</a>> wrote:<br>
<br>
> Send Flask mailing list submissions to<br>
>         <a href="mailto:flask@python.org" target="_blank">flask@python.org</a><br>
><br>
> To subscribe or unsubscribe via the World Wide Web, visit<br>
>         <a href="https://mail.python.org/mailman/listinfo/flask" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/flask</a><br>
> or, via email, send a message with subject or body 'help' to<br>
>         <a href="mailto:flask-request@python.org" target="_blank">flask-request@python.org</a><br>
><br>
> You can reach the person managing the list at<br>
>         <a href="mailto:flask-owner@python.org" target="_blank">flask-owner@python.org</a><br>
><br>
> When replying, please edit your Subject line so it is more specific<br>
> than "Re: Contents of Flask digest..."<br>
><br>
><br>
> Today's Topics:<br>
><br>
>    1. Unable to set current_user.authenticated to True (Abdul Mohammed)<br>
><br>
><br>
> ----------------------------------------------------------------------<br>
><br>
> Message: 1<br>
> Date: Mon, 1 Jul 2019 16:14:33 +0100<br>
> From: Abdul Mohammed <<a href="mailto:imonikemohammed@gmail.com" target="_blank">imonikemohammed@gmail.com</a>><br>
> To: <a href="mailto:flask@python.org" target="_blank">flask@python.org</a><br>
> Subject: [Flask] Unable to set current_user.authenticated to True<br>
> Message-ID:<br>
>         <CAEKkz86wtwLtPni2LML6iM6WW46sHQxq3P=<br>
> <a href="mailto:8j1pq2hW1ZdAVHA@mail.gmail.com" target="_blank">8j1pq2hW1ZdAVHA@mail.gmail.com</a>><br>
> Content-Type: text/plain; charset="utf-8"<br>
><br>
> Hello everyone,<br>
>                   I am trying to toggle between "Sign in" and "Sign out"<br>
> links using the current_user.is_authenticated variable such that when it<br>
> returns False, the "Sign in" is displayed and when True the "Sign out" link<br>
> is displayed. At some point in the login code I set<br>
> current_user.authenticated = True. The thing is that by the I am<br>
> successfully logged in and presented with the next view, it is the "Sign<br>
> in" link that is still displayed. When I check<br>
> current_user.is_authenticated, it returns False, even though I had<br>
> explicitly set it to True. Please can anyone point out what I am might be<br>
> doing wrong? Here is my code:<br>
><br>
> I have a base.html file that contains the "Sign in" and "Sign out" links<br>
> that is extended by the other templates:<br>
><br>
> <ul class="nav navbar-nav navbar-right"><br>
>    {% if (current_user.is_authenticated) %}<br>
>    <li><a href="{{ url_for('logout') }}">Sign Out</a></li><br>
>    {% else %}<br>
>    <li><a href="{{ url_for('index') }}">Sign In</a></li><br>
>    {% endif %}<br>
> </ul><br>
><br>
> <body><br>
> {% block page_content %}{% endblock %}<br>
> </body><br>
><br>
><br>
>  When the app first loads in the browser it displays a login form,<br>
> login.html:<br>
><br>
>  {% extends "base.html" %}<br>
><br>
> {% block content %}<br>
>     {% import "bootstrap/wtf.html" as wtf %}<br>
>     {% block title %}Flasky - Login{% endblock %}<br>
>     {% block page_content %}<br>
>     <div class="page-header"><br>
>         <h1>Login</h1><br>
>     </div><br>
>     <div class="col-md-4"><br>
>         {{ wtf.quick_form(form) }}<br>
>     </div><br>
>     {% endblock %}<br>
> {% endblock %}<br>
><br>
> When a user logs in, it loads a template dashboard.html that displays a<br>
> map. The top part looks like this:<br>
><br>
> {% extends "base.html" %}<br>
><br>
> {% block page_content %}<br>
> <html><br>
>  <head><br>
>    <title>Lagos Map</title><br>
>    <link rel="stylesheet" href="<br>
> <a href="https://unpkg.com/leaflet@1.1.0/dist/leaflet.css" rel="noreferrer" target="_blank">https://unpkg.com/leaflet@1.1.0/dist/leaflet.css</a>"<br>
><br>
><br>
> integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw=="<br>
>    crossorigin=""/><br>
>    <script src="<a href="https://unpkg.com/leaflet@1.1.0/dist/leaflet.js" rel="noreferrer" target="_blank">https://unpkg.com/leaflet@1.1.0/dist/leaflet.js</a>"<br>
><br>
><br>
> integrity="sha512-mNqn2Wg7tSToJhvHcqfzLMU6J4mkOImSPTxVZAdo+lcPlk+GhZmYgACEe0x35K7YzW1zJ7XyJV/TT1MrdXvMcA=="<br>
>    crossorigin=""></script><br>
>    <script src="<br>
><br>
> <a href="https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.js" rel="noreferrer" target="_blank">https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.js</a><br>
> "></script><br>
>    <link rel="stylesheet" href="<br>
><br>
> <a href="https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css" rel="noreferrer" target="_blank">https://rawgit.com/k4r573n/leaflet-control-osm-geocoder/master/Control.OSMGeocoder.css</a><br>
> "<br>
> /><br>
>    <link rel="stylesheet" href="<br>
><br>
> <a href="https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css" rel="noreferrer" target="_blank">https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.css</a><br>
> "<br>
> /><br>
>    <script src="<br>
><br>
> <a href="https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.js" rel="noreferrer" target="_blank">https://cdnjs.cloudflare.com/ajax/libs/leaflet-routing-machine/3.2.5/leaflet-routing-machine.js</a><br>
> "></script><br>
>    <script src="<br>
> <a href="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js" rel="noreferrer" target="_blank">https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js</a>"></script><br>
>   ...<br>
>   ...<br>
><br>
> And these are the relevant routes:<br>
><br>
> @app.route('/',methods=['GET','POST'])<br>
> def index():<br>
>       form = LoginForm()<br>
>       if form.validate_on_submit():<br>
>           user = User.query.filter_by(email=form.email.data).first()<br>
>           if user is not None and user.check_password(form.password.data):<br>
>               user.authenticated = True<br>
>               current_user = user<br>
>               db.session.add(current_user)<br>
>               db.session.commit()<br>
>               login_user(current_user, form.remember_me.data)<br>
>               return redirect(request.args.get('next') or<br>
> url_for('dashboard'))<br>
>           flash('Invalid username or password.')<br>
>        return render_template('auth/login.html', form=form)<br>
><br>
> @app.route('/dashboard')<br>
> def dashboard():<br>
>       return render_template("dashboard.html")<br>
><br>
> Thank you for your time.<br>
> -------------- next part --------------<br>
> An HTML attachment was scrubbed...<br>
> URL: <<br>
> <a href="http://mail.python.org/pipermail/flask/attachments/20190701/9674ee57/attachment-0001.html" rel="noreferrer" target="_blank">http://mail.python.org/pipermail/flask/attachments/20190701/9674ee57/attachment-0001.html</a><br>
> ><br>
><br>
> ------------------------------<br>
><br>
> Subject: Digest Footer<br>
><br>
> _______________________________________________<br>
> Flask mailing list<br>
> <a href="mailto:Flask@python.org" target="_blank">Flask@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/flask" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/flask</a><br>
><br>
><br>
> ------------------------------<br>
><br>
> End of Flask Digest, Vol 49, Issue 1<br>
> ************************************<br>
><br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://mail.python.org/pipermail/flask/attachments/20190701/9252979c/attachment.html" rel="noreferrer" target="_blank">http://mail.python.org/pipermail/flask/attachments/20190701/9252979c/attachment.html</a>><br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
_______________________________________________<br>
Flask mailing list<br>
<a href="mailto:Flask@python.org" target="_blank">Flask@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/flask" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/flask</a><br>
<br>
<br>
------------------------------<br>
<br>
End of Flask Digest, Vol 49, Issue 2<br>
************************************<br>
</blockquote></div>
</blockquote></div>