Beispiel #1
0
def send_invitation_mail(mail):
    print 'Mail sent to ' + mail['to_address']
    sendgrid_user = get_config_value('SENDGRID_USER')
    sendgrid_password = get_config_value('SENDGRID_PASSWORD')
    s = sendgrid.Sendgrid(sendgrid_user, sendgrid_password, secure=True)
    message = sendgrid.Message((mail['from'], mail['from_name']), mail['subject'], mail['txt_body'], mail['html_body'])
    message.add_to(mail['to_address'], mail['to_name'])
    s.web.send(message)
Beispiel #2
0
def is_oi_user(email):
    conn = Connection(get_config_value('MONGO_URL'))
    db = conn['oime']
    objects = db['users']
    u = objects.find_one({'$or': [{'sub_email': email.strip()}, {'username': email.strip()}]})
    if u is not None:
        return u
    return False
Beispiel #3
0
 def __init__(self, eventName=None):
     self._db = 'logging'
     self._collection = 'events'
     self._conn = Connection(get_config_value('MONGO_URL'))
     self._db = self._conn[self._db]
     self._objects = self._db[self._collection]
     self._log = []
     if eventName is not None:
         self._name = eventName
     self._start = datetime.utcnow()
Beispiel #4
0
def upload_image_as_png_to_s3(filename, user):
    c = connect_s3()
    bucket_name = get_config_value('BUCKET')
    bucket = c.create_bucket(bucket_name)
    k = Key(bucket)
    k.key = user + '/' + filename
    k.set_metadata('owner', user)
    k.content_type = 'image/png'
    k.set_contents_from_filename(filename)
    k.make_public()
    return 'http://%s/%s' % (bucket_name, k.key)
Beispiel #5
0
 def __init__(self, db, collection):
     self._db = db
     self._collection = collection
     self._conn = Connection(get_config_value('MONGO_URL'))
     self._db = self._conn[self._db]
     self._objects = self._db[self._collection]
     self._id = None
     self._owner = None
     self._created = datetime.utcnow()
     self._tags = []
     self._doc = None
     self._cursor = None
Beispiel #6
0
def upload():
    current_app.logger.info('Upload Image')
    login_key = request.form.get('login_key', False)
    # app_token = request.form.get('app_token', False)
    app_user = request.form.get('u', False)

    if login_key:
        user = get_user_name(login_key)
    else:
        user = app_user

    if 'file' in request.files:
        file = request.files['file']
        if is_image(file.filename):
            object_id = Picture.create(user, {}, file.filename)
        elif is_attachment(file.filename):
            object_id = Attachment.create(user, {}, file.filename)

        filename = secure_filename(object_id + '-' + file.filename)
        c = connect_s3()
        bucket_name = get_config_value('BUCKET')
        bucket = c.create_bucket(bucket_name)
        k = Key(bucket)
        k.key = user + '/' + filename
        k.set_metadata('owner', user)
        extension = os.path.splitext(filename)[1]
        k.content_type = file.content_type
        current_app.logger.info('Extension: ' + str(extension))
        current_app.logger.info('file.content_type: ' + str(file.content_type))
        if extension.lower() == '.jpg':
            k.content_type = 'image/jpeg'
        if extension.lower() == '.png':
            k.content_type = 'image/png'
        if extension.lower() == '.gif':
            k.content_type = 'image/gif'
        current_app.logger.info('Extension: ' + str(extension))
        current_app.logger.info('file.content_type: ' + str(k.content_type))
        k.set_contents_from_string(file.read())
        k.make_public()
        url = 'http://%s/%s' % (bucket_name, k.key)
        current_app.logger.info(
            '########## url: ' + str(url) + ' ' + str(bucket)
        )
        if is_image(file.filename):
            Picture.add_url(object_id, url)
        elif is_attachment(file.filename):
            object_id = Attachment.add_url(object_id, file.filename)

        return jsonify({'upload': url})
    return jsonify({'upload': 'error'})
Beispiel #7
0
def send_message():
    blitem_id = request.form['id']
    transaction = request.form['transaction']
    app_token = request.form['app_token']

    if is_valid_id(blitem_id):
        blitem = Blitem.get({'_id': ObjectId(blitem_id), 'i.v': transaction})
        if blitem:
            flat = Blitem.flat_object(blitem)
            current_app.logger.info(flat)
            template = read_file('/bsm/templates/mysecretvalentine.html')
            html_mail = template.decode('utf-8')
            html_mail = html_mail.replace("*|IMAGE|*", flat['url'])
            # html_mail = html_mail.replace("*|URL|*", 'http://blibb.net/go/' + flat['url_id'])
            html_mail = html_mail.replace("*|MESSAGE|*", flat['message'])

            mail = {
                'to_address': flat['to'],
                'from_name': 'Your Secret Valentine',
                'from': '*****@*****.**',
                'subject': 'Your Secret Valentine',
                'txt_body': flat['message'],
                'html_body': html_mail
            }

            print 'Mail sent to ' + mail['to_address']
            sendgrid_user = get_config_value('SENDGRID_USER')
            sendgrid_password = get_config_value('SENDGRID_PASSWORD')
            s = sendgrid.Sendgrid(sendgrid_user, sendgrid_password, secure=True)
            message = sendgrid.Message((mail['from'], mail['from_name']), mail['subject'], mail['txt_body'], mail['html_body'])
            message.add_to(mail['to_address'], '')
            s.web.send(message)
            # return jsonify({'return': 'success'})
            return html_mail
        abort(401)
    abort(400)
Beispiel #8
0
def loader_excel():
    event = Event('web.content.loader_excel')
    key = request.form['login_key']
    bid = request.form['blibb_id']
    user = get_user_name(key)
    res = dict()
    file = request.files['file']
    if file and allowed_file(file.filename):
        try:
            filename = secure_filename(file.filename)
            excel_file = os.path.join(
                get_config_value('UPLOAD_FOLDER'), filename
            )
            file.save(excel_file)
            if is_valid_id(bid):
                fields = Blibb.get_fields(bid)
                excel_data = loader.excel_to_dict(excel_file, fields)
                current_app.logger.debug(excel_data)
                if len(excel_data):
                    a = Blitem.bulk_insert(bid, user, excel_data)
                    current_app.logger.debug(a)
                    res['result'] = 'ok'
                else:
                    res['error'] = 'No data found in file'
            else:
                if bid == '-1':
                    res['error'] = 'create new blibb from file'

                res['error'] = 'Object Id is not valid'
        # except Exception, e:
            # current_app.logger.error(e)
            # res['error'] = 'Error processing spreadsheet'

        finally:
            if os.path.isfile(filename):
                os.unlink(filename)

    else:
        res['error'] = 'File was not uploaded'

    event.save()
    return jsonify(res)
Beispiel #9
0


from API.utils import get_config_value
from twilio.rest import TwilioRestClient
import re


TWILIO_ACCOUNT = get_config_value('TWILIO_ACCOUNT')
TWILIO_TOKEN = get_config_value('TWILIO_TOKEN')
TWILIO_NUMBER = get_config_value('TWILIO_NUMBER')


def send_sms(msg, number):
    client = TwilioRestClient(TWILIO_ACCOUNT, TWILIO_TOKEN)
    message = client.sms.messages.create(to=number, from_=TWILIO_NUMBER, body=msg)


def is_phone_number(number):
    p = r'^7(?:[1-4]\d\d|5(?:0[0-8]|[13-9]\d|2[0-35-9])|624|7(?:0[1-9]|[1-7]\d|8[02-9]|9[0-689])|8(?:[014-9]\d|[23][0-8])|9(?:[04-9]\d|1[02-9]|2[0-35-9]|3[0-689]))\d{6}$'
    mobile = number[-10:]
    pattern = re.compile(p)
    res = pattern.search(mobile)
    print "is_phone_number? " + number
    if res:
        return True
    return False
Beispiel #10
0
#
#   event.py
#
#

from datetime import datetime
from API.base import BaseObject
import json
from bson import json_util
from pymongo import Connection
from bson.objectid import ObjectId

from API.utils import get_config_value


conn = Connection(get_config_value('MONGO_URL'))
db = conn['blibb']
objects = db['attachments']


class Attachment(object):

    @classmethod
    def create(cls, owner, items={}, blibb_id=None):
        now = datetime.utcnow()
        doc = {"u": owner, "c": now, "i": items}
        if blibb_id:
            doc["b"] = blibb_id
        newId = objects.insert(doc)
        return str(newId)
Beispiel #11
0
from flask import jsonify, current_app
from datetime import datetime
from string import digits, ascii_letters
from random import sample

from bson.objectid import ObjectId
from pymongo import Connection
from API.contenttypes.picture import Picture
from API.template.ctrl_template import ControlTemplate
from API.om.acl import ACL
from API.error import Message
import hashlib
from API.utils import is_valid_id, date_to_str, get_config_value


conn = Connection(get_config_value('MONGO_URL'))
db = conn['blibb']
objects = db['blibbs']
NUM_CHARS = get_config_value('NUM_CHARS')


class Blibb(object):

    '''
        Updates view generated from template
    '''
    @classmethod
    def update_view(cls, objectid, user, view, html):
        field = 't.v.%s.rb' % (view)
        objects.update({'_id': ObjectId(objectid)},
                       {'$set': {field: html, 'lm': user}})
Beispiel #12
0
#
#   User.py
#
#


from datetime import datetime
from flask import current_app
from pymongo import Connection
import hashlib
import redis
import json
from API.utils import get_config_value


conn = Connection(get_config_value("MONGO_URL"))
db = conn["blibb"]
objects = db["users"]


class User(object):
    @classmethod
    def get_redis(self):
        return redis.StrictRedis(host="127.0.0.1", port=6379, db=0)

    @classmethod
    def create(cls, name, email, password, code):
        if cls.is_available(name, email):
            now = datetime.utcnow()
            salt = hashlib.sha1(email + str(datetime.utcnow())).hexdigest()
            pub_salt = hashlib.sha1(email + str(datetime.utcnow())).hexdigest()
Beispiel #13
0
#
#
#
#

import httplib
import json
from API.utils import get_config_value
from flask import current_app


APPLICATION_ID = get_config_value('PARSE_APPLICATION_ID')
REST_API_KEY = get_config_value('PARSE_REST_API_KEY')


def do_push(name=None, channel=None, user=None, oiid=None):

    data = dict()

    data['data'] = {'alert': user + ': ' + name, 'badge': 'Increment', 'action': 'me.oioi.simple.OPENAPP', 'title': 'Oi!', 'oiid': oiid}
    data["channels"] = [channel]

    head = dict()
    head['Content-Type'] = "application/json"
    head['X-Parse-Application-Id'] = APPLICATION_ID
    head['X-Parse-REST-API-Key'] = REST_API_KEY

    connection = httplib.HTTPSConnection('api.parse.com', 443)
    connection.connect()
    connection.request('POST', '/1/push', json.dumps(data), head)