RafaelMiquelino / dash-flask-login

Implementation of Flask-login on top of Dash.
MIT License
247 stars 81 forks source link

File contains no section headers. #3

Closed krzyszsz86 closed 4 years ago

krzyszsz86 commented 5 years ago

Hello,

I found some posts about dash authentication here:

https://community.plot.ly/t/get-username-for-authenticated-user-for-basic-auth/13613

and it’s almost working. I keep getting this error:

File “c:\users\User\appdata\local\programs\python\python37\lib\configparser.py”, line 696, in read self._read(fp, filename) File “c:\users\User\appdata\local\programs\python\python37\lib\configparser.py”, line 1079, in _read raise MissingSectionHeaderError(fpname, lineno, line) configparser.MissingSectionHeaderError: File contains no section headers. file: ‘config.txt’, line: 1 ‘[database]\n’

I decided to start leraning Python/Dash. I am trying to replicate stuff that I did in Excel/Vba using Dash. However I am a beginner without programming backrgoud (I worked on Excel, SAS, SAP…) so many definitions don’t say anything to me.

Also, how can I connect my main app (lets say it’s Dash.py) with your part and retrive user name?

I would very much appreciate if you could get back to me and maybe help me run your code.

BR Krzyszsz

DrMaphuse commented 5 years ago

I'm not the author, and haven't encountered this error yet, but have you initiated the user database yet? If not, open the included add_remove_users.ipynb in jupyter notebooks or lab and run the first two cells to generate the table. Maybe run the rest as well to get an idea of how to add and remove users.

As for connecting the app - the best way to understand how this implementation of flask-login interacts with dash is to look at multi-page apps first and try to understand how app routes and urls work in dash.

Once you have this down, all you need to know is that the Flask-login functions and methods, (start here for the most important ones) can be called anywhere within your app, either to determine if a user is logged in, or to retrieve some other attribute from the user table. This is as simple as calling if current_user.is_authenticated:, which will return True or False, before any content that is password protected. For example, if the user is not authenticated, you can route them back to the login page or show an error message.