<s> """<STR_LIT>""" <EOL> from google . appengine . ext . webapp import template <EOL> from session import RequestHandler <EOL> from users import User , UserSignup , salt_n_hash , signup_id <EOL> SIGNUP_VIEW = template . Template ( """<STR_LIT>""" ) <EOL> LOGIN_VIEW = template . Template ( """<STR_LIT>""" ) <EOL> class Signup ( RequestHandler ) : <EOL> def get ( self ) : <EOL> ctx = template . Context ( { "<STR_LIT>" : self . session } ) <EOL> self . response . out . write ( SIGNUP_VIEW . render ( ctx ) ) <EOL> def post ( self ) : <EOL> nickname = self . request . get ( '<STR_LIT>' ) <EOL> email = self . request . get ( '<STR_LIT:email>' ) <EOL> password = self . request . get ( '<STR_LIT:password>' ) <EOL> password2 = self . request . get ( '<STR_LIT>' ) <EOL> if password2 != password : <EOL> self . session . start ( None ) <EOL> self . session [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . redirect ( '<STR_LIT>' ) <EOL> return <EOL> user = User . get_or_insert ( nickname = nickname , <EOL> email = email , <EOL> pwd = salt_n_hash ( password ) , <EOL> key_name = nickname ) <EOL> self . session . start ( None ) <EOL> if not User . authenticate ( nickname , password ) : <EOL> self . session [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . redirect ( self . request . url ) <EOL> return <EOL> id = signup_id ( nickname ) <EOL> signup = UserSignup ( user = user , key_name = id ) <EOL> signup . put ( ) <EOL> confirm_url = self . request . relative_url ( '<STR_LIT>' + id ) <EOL> from google . appengine . api import mail <EOL> sender = '<STR_LIT>' <EOL> subject = '<STR_LIT>' <EOL> body = '<STR_LIT>' % nickname + '<STR_LIT>' + '<STR_LIT>' % confirm_url <EOL> mail . send_mail ( sender , email , subject , body ) <EOL> self . session [ '<STR_LIT>' ] = '<STR_LIT>' % nickname + '<STR_LIT>' + '<STR_LIT>' + '<STR_LIT>' <EOL> self . redirect ( '<STR_LIT:/>' ) <EOL> class ConfirmSignup ( RequestHandler ) : <EOL> def get ( self ) : <EOL> id = self . request . get ( '<STR_LIT:id>' ) <EOL> signup = UserSignup . get_by_key_name ( id ) <EOL> if not signup : <EOL> self . error ( <NUM_LIT> ) <EOL> return <EOL> user = signup . user <EOL> user . suspended = False <EOL> user . put ( ) <EOL> signup . delete ( ) <EOL> self . session . start ( user ) <EOL> self . session [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . redirect ( '<STR_LIT>' + user . nickname ) <EOL> class Login ( RequestHandler ) : <EOL> """<STR_LIT>""" <EOL> def get ( self ) : <EOL> ctx = template . Context ( { "<STR_LIT>" : self . session } ) <EOL> self . response . out . write ( LOGIN_VIEW . render ( ctx ) ) <EOL> def post ( self ) : <EOL> user = User . authenticate ( self . request . get ( '<STR_LIT>' ) , self . request . get ( '<STR_LIT:password>' ) ) <EOL> if user and not user . suspended : <EOL> self . session . start ( user ) <EOL> redirect = self . request . get ( '<STR_LIT>' ) <EOL> self . redirect ( redirect ) <EOL> else : <EOL> self . session . start ( None ) <EOL> self . session [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . redirect ( self . request . url ) <EOL> def login_required ( handler_method ) : <EOL> """<STR_LIT>""" <EOL> def check_login ( self , * args ) : <EOL> if not self . session . user : <EOL> self . redirect ( '<STR_LIT>' + '<STR_LIT>' + self . request . url ) <EOL> else : <EOL> handler_method ( self , * args ) <EOL> return check_login <EOL> class Logout ( RequestHandler ) : <EOL> def get ( self ) : <EOL> if not self . session . user : <EOL> self . error ( <NUM_LIT> ) <EOL> return <EOL> nickname = self . session . user . nickname <EOL> self . session . start ( None ) <EOL> self . session [ '<STR_LIT>' ] = '<STR_LIT>' % nickname <EOL> self . redirect ( '<STR_LIT>' ) <EOL> ROUTES = [ <EOL> ( '<STR_LIT>' , Signup ) , <EOL> ( '<STR_LIT>' , ConfirmSignup ) , <EOL> ( '<STR_LIT>' , Login ) , <EOL> ( '<STR_LIT>' , Logout ) <EOL> ] </s>
