<s> from flask import render_template , flash , redirect , session , url_for , request , g <EOL> from flask . ext . login import login_user , logout_user , current_user , login_required <EOL> from app import app , db , lm <EOL> from forms import LoginForm <EOL> from models import User <EOL> import hashlib <EOL> from datetime import datetime <EOL> @ app . before_request <EOL> def before_request ( ) : <EOL> g . user = current_user <EOL> @ app . route ( '<STR_LIT:/>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> def index ( page = <NUM_LIT:1> ) : <EOL> return render_template ( "<STR_LIT>" , <EOL> title = '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> def login ( ) : <EOL> if g . user is not None and g . user . is_authenticated ( ) : <EOL> return redirect ( url_for ( '<STR_LIT:index>' ) ) <EOL> form = LoginForm ( ) <EOL> if form . validate_on_submit ( ) : <EOL> session [ '<STR_LIT>' ] = form . remember_me . data <EOL> q = User . query . filter_by ( username = form . username . data , <EOL> password = hashlib . sha1 ( form . password . data ) . hexdigest ( ) ) . first ( ) <EOL> if q is not None : <EOL> g . user = q <EOL> login_user ( q ) <EOL> flash ( "<STR_LIT>" ) <EOL> return redirect ( '<STR_LIT>' ) <EOL> return render_template ( "<STR_LIT>" , <EOL> title = "<STR_LIT>" , <EOL> form = form ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> @ login_required <EOL> def admin ( ) : <EOL> g . user = current_user <EOL> return render_template ( "<STR_LIT>" , <EOL> title = "<STR_LIT>" , <EOL> user = g . user ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> @ login_required <EOL> def logout ( ) : <EOL> logout_user ( ) <EOL> return redirect ( '<STR_LIT>' ) <EOL> @ lm . user_loader <EOL> def load_user ( id ) : <EOL> return User . query . get ( int ( id ) ) </s>
