<commit_before>import json
import random
import string

from flask import Flask, request, jsonify
from flask.ext.pymongo import PyMongo
from pymongo.errors import DuplicateKeyError

from crossdomain import crossdomain

app = Flask(__name__)
app.config['MONGO_DBNAME'] = 'kasm'
mongo = PyMongo(app)

@app.route('/alias/test')
def hello_world():
    return "API is a go"


@app.route('/alias/create', methods=['POST'])
@crossdomain(origin='http://openkasm.com:8000')
def create_alias():
    def id_generator(size, chars=string.ascii_lowercase + string.digits):
        return ''.join(random.choice(chars) for _ in xrange(size))
    email = request.form['email']
    inserted = False
    while not inserted:
        try:
            alias = id_generator(8)
            mongo.db.redirects.insert({'email': email, 'alias': alias})
        except DuplicateKeyError:
            pass
        else:
            inserted = True

    to_return = {'email': email,
                 'encrypt': 'lolwut',
                 'original': email,
                 'response': 'success',
                 'username': alias,
                 }
    return jsonify(to_return)


@app.route('/alias/deactivate', methods=['POST'])
@crossdomain(origin='http://openkasm.com:8000')
def deactivate_alias():
    alias = request.form['alias']
    print 'Received request to deactivate alias "%s".' % alias
    result = mongo.db.redirects.update({'alias': alias},
                                       {'$set': {'deactivated': True}})
    print 'Result:'
    print json.dumps(result, sort_keys=True, indent=3)
    to_return = {'alias': alias}
    to_return['response'] = 'success' if result['n'] > 0 else 'fail'
    return jsonify(to_return)


if __name__ == '__main__':
    app.run(host="0.0.0.0", debug=True)
<commit_msg>Remove CORS on alias methods<commit_after>import json
import random
import string

from flask import Flask, request, jsonify
from flask.ext.pymongo import PyMongo
from pymongo.errors import DuplicateKeyError

from crossdomain import crossdomain

app = Flask(__name__)
app.config['MONGO_DBNAME'] = 'kasm'
mongo = PyMongo(app)

@app.route('/alias/test')
def hello_world():
    return "API is a go"


@app.route('/alias/create', methods=['POST'])
def create_alias():
    def id_generator(size, chars=string.ascii_lowercase + string.digits):
        return ''.join(random.choice(chars) for _ in xrange(size))
    email = request.form['email']
    inserted = False
    while not inserted:
        try:
            alias = id_generator(8)
            mongo.db.redirects.insert({'email': email, 'alias': alias})
        except DuplicateKeyError:
            pass
        else:
            inserted = True

    to_return = {'email': email,
                 'encrypt': 'lolwut',
                 'original': email,
                 'response': 'success',
                 'username': alias,
                 }
    return jsonify(to_return)


@app.route('/alias/deactivate', methods=['POST'])
def deactivate_alias():
    alias = request.form['alias']
    print 'Received request to deactivate alias "%s".' % alias
    result = mongo.db.redirects.update({'alias': alias},
                                       {'$set': {'deactivated': True}})
    print 'Result:'
    print json.dumps(result, sort_keys=True, indent=3)
    to_return = {'alias': alias}
    to_return['response'] = 'success' if result['n'] > 0 else 'fail'
    return jsonify(to_return)


if __name__ == '__main__':
    app.run(host="0.0.0.0", debug=True)

{'fraction_non_alphanumeric': 0.1371820520148614, 'fraction_numerical': 0.006287510717347814, 'mean_word_length': 2.791982665222102, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6396621', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1061, 'n_words': 260}