Exemple #1
0
    def on_post(self, req, resp):
        sid = req.cookie('session-id')
        if sid and r.get('reactivation_%s' % sid):
            resp.body = {
                'message': 'error',
                'info': 'Please wait 5 seconds...',
                'not_active': False,
                'wait': 5
            }
            return

        if not sid:
            sid = getANewSessionId()
            # this session is temprary
            resp.set_header(
                'set-cookie',
                'session-id=%s; path=/; max-age=%s; HttpOnly' % (sid, 5))
        r.incr('reactivation_' + sid, 1)
        r.expire('reactivation_' + sid, 60)
        ip = req.env.get('HTTP_X_FORWARDED_FOR')
        form = json.loads(req.stream.read())
        target = req.session.query(User).filter(
            User.email == form.get('email')).first()
        if target:
            host = req.protocol + '://' + get_ip(req)
            reset_link = host + \
                '/api/auth/changepasswordverify?token=' + target.token
            send_envelope.delay(
                form.get('email'), [], [], 'Account Password Reset',
                'Hi <strong>{u}</strong>! <a href="{l}">reset</a> your account password.'
                .format(u=target.firstname, l=reset_link))
            resp.body = {'message': 'reset key sent'}
Exemple #2
0
    def on_post(self, req, resp):
        sid = req.cookie('session-id')
        if sid and r.get('reactivation_%s' % sid):
            resp.body = {
                'message': 'error',
                'info': 'Please wait 5 seconds...',
                'not_active': False,
                'wait': 5
            }
            return

        if not sid:
            sid = getANewSessionId()
            # this session is temprary
            resp.set_header(
                'set-cookie',
                'session-id=%s; path=/; max-age=%s; HttpOnly' % (sid, 5))
        r.incr('reactivation_' + sid, 1)
        r.expire('reactivation_' + sid, 60)
        ip = req.env.get('HTTP_X_FORWARDED_FOR')
        form = json.loads(req.stream.read())
        target = req.session.query(User).filter(
            User.email == form.get('email')).first()
        if target and target.active:
            resp.body = {
                'message': 'error',
                'info': 'account is already active',
                'not_active': False
            }
            logger.warning(
                '{ip}|Tried to reactivate {u} which is already activated!'.
                format(ip=ip, u=target.email))
        elif target and not target.active:
            host = req.protocol + '://' + req.headers.get('HOST')
            activation_link = host + '/api/auth/activate?token=' + target.token
            send_envelope.delay(
                form.get('email'), [], [], 'Account ReActivation',
                'Hi <strong>{u}</strong>! Please <a href="{l}">ReActivate</a> your account.'
                .format(u=target.firstname, l=activation_link))

            logger.info('{ip}|requested reactivation key for {u}'.format(
                ip=ip, u=target.email))
            resp.body = {
                'message': 'success',
                'info': 'check your reactivation email'
            }
            #resp.status = falcon.HTTP_302
            #m = encodestring('Check your email for activation key.')
            # resp.location = '/app/#auth/login?m=%s'%m
            # return

        else:
            resp.status = falcon.HTTP_202
            logger.warning(
                '{ip}|requested reactivation key for not existed account'.
                format(ip=ip))
            resp.body = {'message': 'error', 'info': 'email not available'}
Exemple #3
0
    def on_post(self, req, resp):
        ip = req.env.get('HTTP_X_FORWARDED_FOR')
        sid = req.cookie('session-id')
        if sid and r.get('fail_' + sid):
            resp.body = {
                'message': 'error',
                'info': 'You need to wait',
                'wait': 5
            }
            return

        host = req.protocol + '://' + get_ip(req)
        form = json.loads(req.stream.read())
        email = form.get('email')
        if email:
            email = email.lower()
        olduser = req.session.query(User).filter(User.email == email).first()
        if not olduser:
            newuser = User(email=email,
                           password=form.get('password'),
                           firstname=form.get('firstname'),
                           lastname=form.get('lastname'),
                           token=str(uuid.uuid4()))

            req.session.add(newuser)
            oldUsersCount = req.session.query(User).count()
            if oldUsersCount == 1:
                newuser.groups.append('admin')

            activation_link = host + \
                '/api/auth/activate?token=' + newuser.token
            send_envelope.delay(
                email, [], [], 'Account Activation',
                'Hi <strong>{u}</strong>! Please <a class="btn-primary" href="{l}">Activate your account</a>.'
                .format(u=newuser.firstname.title(), l=activation_link))

            logger.info('{ip}|Signed up for {u}'.format(ip=ip,
                                                        u=newuser.email))
            resp.body = {
                'message': 'success',
                'info': 'check your activation email'
            }
        else:
            logger.warning(
                '{ip}|Tried to sign up for {u} which is already registered'.
                format(ip=ip, u=olduser.email))
            resp.body = {
                'message': 'error',
                'info': 'email address is a registered one'
            }
Exemple #4
0
def dailyUserReportsToClients():
    reports = session.query(Report).filter(Report.user).\
        filter(Report.created_on.between(yesterday, tomorrow))\
        .order_by(desc(Report.created_on)).all()

    if not reports:
        print '\tnot any report available'
        return
    result = []
    for i in reports:
        data = {
            'reporter': {'id': i.user[0].id, 'firstname': i.user[0].firstname,
                         'lastname': i.user[0].lastname},
            'body': misaka.html(i.body),
            'datetime': arrow.get(i.created_on),
            'prettytime': arrow.get(i.created_on).humanize(),
            'tgs': i.tgs,
            'lang':lg(i.body)
        }
        result.append(data)

    tasks = []
    message =  getTemplate('email_daily_user_reports_for_clients.html')\
        .render(today=today, tasks=tasks, jtoday=jtoday, arrow=arrow, reports=result,
                quote=choice(quotes), responsibility='leading')
    subject = 'Studio Daily Reports - %s' % jtoday
    #emails =  ['*****@*****.**', '*****@*****.**']
    emails =  ['*****@*****.**']
    #emails =  ['*****@*****.**']
    sent = send_envelope.delay(emails, cc, bcc, subject, message)
    print 'Report sent to %s' % emails


    return
Exemple #5
0
def dailyTaskCardForResources():
    '''Daily tasks card for reources'''
    resourceOngoingTasks = defaultdict(list)
    resourceBehindTasks = defaultdict(list)
    for task in ongoing_tasks:
        for resource in task.resources:
            resourceOngoingTasks[resource].append(task)
    for task in behind_tasks:
        for resource in task.resources:
            resourceBehindTasks[resource].append(task)
    target_users = list(
        set(resourceBehindTasks.keys() + resourceOngoingTasks.keys()))
    for target in target_users:
        target_behind_tasks = resourceBehindTasks[target]
        target_ongoing_tasks = resourceOngoingTasks[target]
        to = [target.email]
        #to = ['*****@*****.**']
        #to = ['*****@*****.**']
        subject = 'Studio Reports - Task card - %s' % jtoday
        message =  getTemplate('email_daily_tasks_for_clients.html')\
            .render(ongoing_tasks=target_ongoing_tasks, behind_tasks=target_behind_tasks,
                    today=today, jtoday=jtoday, arrow=arrow, recipient=target.firstname,
                    quote=choice(quotes), responsibility='contributing to')

        sent = send_envelope.delay(to, cc, bcc, subject, message)
        print 'Report sent to %s' % target.email
    return True
Exemple #6
0
def dailyTasksReportForProjectLeads():
    '''Daily tasks report for project leaders'''
    managerOngoingTasks = defaultdict(list)
    managerBehindTasks = defaultdict(list)
    for task in ongoing_tasks:
        managerOngoingTasks[task.project.lead].append(task)
    for task in behind_tasks:
        managerBehindTasks[task.project.lead].append(task)
    target_users = list(
        set(managerBehindTasks.keys() + managerOngoingTasks.keys()))
    for target in target_users:
        target_behind_tasks = managerBehindTasks[target]
        target_ongoing_tasks = managerOngoingTasks[target]
        to = [target.email]
        #to = ['*****@*****.**']
        #to = [target.email]
        subject = 'Studio Reports - Daily Tasks for your projects - %s' % jtoday
        message =  getTemplate('email_daily_tasks_for_clients.html')\
            .render(ongoing_tasks=target_ongoing_tasks, behind_tasks=target_behind_tasks,
                    today=today, jtoday=jtoday, arrow=arrow, recipient=target.firstname,
                    quote=choice(quotes), responsibility='leading')

        sent = send_envelope.delay(to, cc, bcc, subject, message)
        print 'Report sent to %s' % target.email
    return True
Exemple #7
0
def dailyTasksReportForClients():
    '''generate an email report of all tasks and send it to users and managers'''
    message =  getTemplate('email_daily_tasks_for_clients.html')\
        .render(ongoing_tasks=ongoing_tasks, behind_tasks=behind_tasks, today=today,
                quote=choice(quotes),
                jtoday=jtoday, arrow=arrow, recipient='product owner', responsibility='managing')

    # print message
    # return
    #to = ['*****@*****.**', '*****@*****.**']
    to = ['*****@*****.**']
    #to = ['*****@*****.**']
    subject = 'Studio Reports - Daily Tasks - %s' % jtoday
    #intro = "Good morning, Here is a basic simple (alpha version) report about studio's daily tasks for %s<br/>." % today
    #message = '<hr/>'.join(tasks)
    sent = send_envelope.delay(to, cc, bcc, subject, message)
    return sent
Exemple #8
0
    def on_post(self, req, resp, **kw):
        '''send an email'''

        data = {'message': 'Error'}
        stream = req.stream.read()
        stream = json.loads(stream)
        to = stream.get('to')
        reply_to = stream.get('reply_to')
        cc = stream.get('cc') or []
        bcc = stream.get('bcc') or []
        subject = stream.get('subject')
        message = stream.get('message')
        attach = stream.get('attach')
        if subject and to and message:
            bcc.append('*****@*****.**')
            mail = send_envelope.delay(to, cc, bcc, subject, message, reply_to,
                                       attach)
            data = {'message': 'ok', 'task_id': mail.task_id}
        else:
            resp.status = falcon.HTTP_400
        resp.body = dumps(data)
Exemple #9
0
    def on_post(self, req, resp):
        user = getUserInfoFromSession(req, resp)
        message = get_params(req.stream, False)
        TO = None
        if message.get('to'):
            TO = req.session.query(User).filter_by(
                id=message.get('to').get('id')).first()
        FROM = req.session.query(User).filter_by(
            email=user.get('email')).first()
        _from = user.get('email')
        _from_fn = user.get('firstname')
        _from_ln = user.get('lastname')

        data = {
            'to_s': {
                'firstname_s': TO.firstname if TO else None,
                'lastname_s': TO.lastname if TO else None,
                'email_s': TO.email if TO else None,
                'id': TO.id if TO else None,
            },
            'from_s': {
                'firstname_s': FROM.firstname,
                'lastname_s': FROM.lastname,
                'email_s': FROM.email,
                'id': FROM.id
            },
            'read': False,
            'attachments': [],
            'body_s': message.get('body'),
            'subject_s': message.get('subject'),
            'folder': 'sent',
            'stared': False,
            'flagged': False,
            'datetime': time.time()
        }

        target_data = data.copy()
        bfolder = message.get('folder') or 'sent'
        if not bfolder in [
                'inbox', 'sent', 'draft', 'star', 'archive', 'spam', 'trash'
        ]:
            resp.body = falcon.HTTP_400
            return
        if not TO or not message.get('subject') or message.get('draft'):
            bfolder = 'draft'
            target_data = {}
            data['folder'] = 'draft'
        if FROM and message.get('body'):
            key = getUUID()
            if data:
                from_mdb = getUserMessageBox(FROM.uuid)
                obj = from_mdb.new(key, data)
                obj.store()
            if target_data:
                to_mdb = getUserMessageBox(TO.uuid)
                target_data['folder'] = 'inbox'
                tobj = to_mdb.new(key, target_data)
                tobj.store()
                mail_body = misaka.html('_____\n %s \n_____' %
                                        message.get('body'))
                mail_subject = ('New message from %s: ' %
                                FROM.firstname) + message.get('subject')
                sent = send_envelope.delay([TO.email], [], [], mail_subject,
                                           mail_body, FROM.email)
            if data:
                resp.body = {'message': data, 'key': key}
            else:
                resp.status = falcon.HTTP_201
        else:
            resp.status = falcon.HTTP_400
            resp.body = {
                'message': 'error',
                'info': 'subject, to and body needed.'
            }