#NEWLINE# def post( self ) : #NEWLINE# #INDENT# username = self . request . data . get ( 'username' ) #NEWLINE# password = self . request . data . get ( 'password' ) #NEWLINE# if ( ( not username ) or ( not password ) ) : #NEWLINE# #INDENT# raise HTTP_400 ( 'Please specify username and password' ) #NEWLINE# #UNINDENT# user = db . query ( User ) . filter ( ( User . username == username ) , ( User . password == password ) ) . first ( ) #NEWLINE# if ( not user ) : #NEWLINE# #INDENT# raise HTTP_401 ( 'Invalid username or password' ) #NEWLINE# #UNINDENT# sess = UserSession ( user_id = user . id ) #NEWLINE# db . add ( sess ) #NEWLINE# self . response . set_cookie ( 'session_id' , sess . session_id ) #NEWLINE# return { #NEWLINE# #INDENT# 'message' : 'Logged in' , #NEWLINE# 'session_id' : sess . session_id , #NEWLINE# #UNINDENT# }