#NEWLINE# @ frontend . route ( '/login' , methods = [ 'GET' , 'POST' ] ) #NEWLINE# def login( ) : #NEWLINE# #INDENT# if current_user . is_authenticated ( ) : #NEWLINE# #INDENT# return redirect ( url_for ( 'user.index' ) ) #NEWLINE# #UNINDENT# form = LoginForm ( login = request . args . get ( 'login' , None ) , next = request . args . get ( 'next' , None ) ) #NEWLINE# if form . validate_on_submit ( ) : #NEWLINE# #INDENT# ( user , authenticated ) = User . authenticate ( form . login . data , form . password . data ) #NEWLINE# if ( user and authenticated ) : #NEWLINE# #INDENT# remember = ( request . form . get ( 'remember' ) == 'y' ) #NEWLINE# if login_user ( user , remember = remember ) : #NEWLINE# #INDENT# flash ( _ ( 'Logged in' ) , 'success' ) #NEWLINE# #UNINDENT# return redirect ( ( form . next . data or url_for ( 'user.index' ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# flash ( _ ( 'Sorry, invalid login' ) , 'error' ) #NEWLINE# #UNINDENT# #UNINDENT# return render_template ( 'frontend/login.html' , form = form )