<s> import simplejson as json <EOL> import time <EOL> import browserid <EOL> from httplib2 import Http <EOL> from urllib import urlencode <EOL> from flask import ( Flask , jsonify , redirect , <EOL> render_template , request , session , url_for ) <EOL> import settings <EOL> from helper import * <EOL> from lexicrypt import Lexicrypt <EOL> app = Flask ( __name__ ) <EOL> app . secret_key = settings . SESSION_SECRET <EOL> h = Http ( ) <EOL> lex = Lexicrypt ( ) <EOL> @ app . route ( '<STR_LIT:/>' , methods = [ '<STR_LIT:GET>' ] ) <EOL> def main ( ) : <EOL> """<STR_LIT>""" <EOL> messages = lex . get_messages ( ) <EOL> emessages = [ ] <EOL> for message in messages : <EOL> emessages . append ( is_decryptable ( lex , message , session ) ) <EOL> return render_template ( '<STR_LIT>' , messages = emessages ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' ] ) <EOL> def disclaimer ( ) : <EOL> """<STR_LIT>""" <EOL> messages = lex . get_messages ( ) <EOL> return render_template ( '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' ] ) <EOL> def message ( id ) : <EOL> """<STR_LIT>""" <EOL> message = lex . get_message ( id ) <EOL> if request . args . get ( '<STR_LIT>' ) : <EOL> embedded = True <EOL> else : <EOL> embedded = False <EOL> if message : <EOL> message = is_decryptable ( lex , message , session ) <EOL> return render_template ( '<STR_LIT>' , message = message , embedded = embedded ) <EOL> else : <EOL> return render_template ( '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' ] ) <EOL> @ authenticated <EOL> def your_messages ( ) : <EOL> """<STR_LIT>""" <EOL> messages = lex . get_messages ( session [ '<STR_LIT>' ] ) <EOL> messages_with_decrypted = [ ] <EOL> for message in messages : <EOL> emails = [ ] <EOL> dmessage = lex . decrypt_message ( message [ '<STR_LIT:message>' ] , <EOL> session . get ( '<STR_LIT>' ) ) <EOL> message [ '<STR_LIT>' ] = dmessage . decode ( '<STR_LIT:utf-8>' ) <EOL> for accessor in message [ '<STR_LIT>' ] : <EOL> if accessor != session [ '<STR_LIT>' ] : <EOL> user = lex . db . users . find_one ( { "<STR_LIT>" : accessor } ) <EOL> emails . append ( user [ '<STR_LIT:email>' ] ) <EOL> message [ '<STR_LIT>' ] = emails <EOL> message [ '<STR_LIT>' ] = '<STR_LIT>' % ( settings . SITE_URL , url_for ( '<STR_LIT:message>' , id = str ( message [ '<STR_LIT>' ] ) ) ) <EOL> messages_with_decrypted . append ( message ) <EOL> return render_template ( '<STR_LIT>' , <EOL> messages = messages_with_decrypted , <EOL> page = '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' ] ) <EOL> @ authenticated <EOL> def encrypt ( ) : <EOL> """<STR_LIT>""" <EOL> return render_template ( '<STR_LIT>' , page = '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> def set_email ( ) : <EOL> """<STR_LIT>""" <EOL> data = browserid . verify ( request . form [ '<STR_LIT>' ] , <EOL> settings . SITE_URL ) <EOL> email = data [ '<STR_LIT:email>' ] <EOL> lex . get_or_create_email ( email ) <EOL> session [ '<STR_LIT>' ] = lex . token <EOL> session [ '<STR_LIT>' ] = email <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> @ authenticated <EOL> def set_message ( ) : <EOL> """<STR_LIT>""" <EOL> lex . get_or_create_email ( session [ '<STR_LIT>' ] ) <EOL> image_filename = '<STR_LIT>' % str ( int ( time . time ( ) ) ) <EOL> lex . encrypt_message ( request . form [ '<STR_LIT:message>' ] , <EOL> '<STR_LIT>' , <EOL> image_filename , <EOL> session . get ( '<STR_LIT>' ) ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> @ authenticated <EOL> def get_message ( ) : <EOL> """<STR_LIT>""" <EOL> lex . get_or_create_email ( session [ '<STR_LIT>' ] ) <EOL> message = lex . decrypt_message ( request . form [ '<STR_LIT:message>' ] , <EOL> session . get ( '<STR_LIT>' ) ) <EOL> return jsonify ( { '<STR_LIT:message>' : message } ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> @ authenticated <EOL> def delete_message ( ) : <EOL> """<STR_LIT>""" <EOL> lex . delete_message ( request . form [ '<STR_LIT:message>' ] , <EOL> session [ '<STR_LIT>' ] ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> @ authenticated <EOL> def remove_email ( ) : <EOL> """<STR_LIT>""" <EOL> lex . remove_email_accessor ( request . form [ '<STR_LIT:message>' ] , <EOL> request . form [ '<STR_LIT:email>' ] , <EOL> session . get ( '<STR_LIT>' ) ) <EOL> return jsonify ( { '<STR_LIT:message>' : '<STR_LIT>' } ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> @ authenticated <EOL> def add_email ( ) : <EOL> """<STR_LIT>""" <EOL> lex . add_email_accessor ( request . form [ '<STR_LIT:message>' ] , <EOL> request . form [ '<STR_LIT:email>' ] , <EOL> session . get ( '<STR_LIT>' ) ) <EOL> return jsonify ( { '<STR_LIT:email>' : request . form [ '<STR_LIT:email>' ] } ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> def logout ( ) : <EOL> """<STR_LIT>""" <EOL> session . pop ( '<STR_LIT>' , None ) <EOL> session . pop ( '<STR_LIT>' , None ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> @ app . errorhandler ( <NUM_LIT> ) <EOL> def page_not_found ( error ) : <EOL> return render_template ( '<STR_LIT>' ) <EOL> @ app . errorhandler ( <NUM_LIT> ) <EOL> def something_broke ( error ) : <EOL> return render_template ( '<STR_LIT>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> app . debug = settings . DEBUG <EOL> app . run ( ) </s>
