Flask - User Login

Flask - User Login

Postby pyguy » Mon Jun 09, 2014 8:35 am

Hi,

I am new to python. I read and followed many tutorial on user login. Flaskr, Minitwit, etc. The thing is, after I login to browser, i see my secured page. Without closing my browser, I shutdown the python program and restarted. After restart of the python program, the existing browser session somehow is still there and I am able to access secured pages. Why didn't it break the sessions like other JAVA or .NET standard login ?

Regards,
pyguy
Last edited by metulburr on Mon Jun 09, 2014 11:01 am, edited 1 time in total.
Reason: First post lock.
pyguy
 
Posts: 1
Joined: Mon Jun 09, 2014 8:30 am

Re: Flask - User Login

Postby Crimson King » Tue Jun 10, 2014 3:14 am

Hi pyguy, welcome to the forum, be sure to read this thread .

Regarding your problem, i don't know how .Net or Java handles sessions but i believe Flask handles that client-side, meaning your session is stored in your browser (it's an implementation on top of cookies i think -could be wrong-)

I've never used Flask before so i just grabbed the code from the quickstart and tested what you said and in fact the session didn't expire. I checked the API docs and found this:

before_first_request(*args, **kwargs)

Registers a function to be run before the first request to this instance of the application.


I just used that decorator on my logout view, so that if it's the first request to the server from my client it'll try to log me out.

Code: Select all
@app.before_first_request
@app.route('/logout')
def logout():
    # remove the username from the session if it's there
    session.pop('username', None)
    return redirect(url_for('index'))


Hope that helps, let us know if that worked out for you.
User avatar
Crimson King
 
Posts: 122
Joined: Fri Mar 08, 2013 2:42 pm
Location: Buenos Aires, Argentina


Return to Web Development

Who is online

Users browsing this forum: No registered users and 2 guests