Пример #1
0
    def send_invitation(self):
        model = self.get_sa_model()
        db = self.get_sa_session()

        if not authorized(ValidAuthKitUser()):
            return { "failure" : Messages.invalidSession() }

        to_address = request.params.get('to_address')
        body = request.params.get('body')

        if not to_address or not body:
            return { "failure" : Messages.invalidArguments() }

        invitation = db.query(model.Invitation).filter_by(to_address = to_address).filter_by(sender_uid=h.authenticated_user().uid).first()
        if invitation:
            invitation.message = body
            invitation.sent = False
            invitation.sent_on = datetime.today()
        else:
            invitation = model.Invitation(
                sender_uid = h.authenticated_user().uid, 
                to_address = to_address,
                message = body
            )
            db.save(invitation)
        db.commit()
        return { "success" : Messages.messageWasSent() }
Пример #2
0
    def send_email(self):
        """
        Will send an e-mail with to a given address.
        Only authenticated users can use it.
        """

        if not authorized(ValidAuthKitUser()):
            return { "failure" : Messages.invalidSession() }

        to_address = request.params.get('to_address')
        subject = request.params.get('subject')
        body = request.params.get('body')

        if not to_address or not subject or not body:
            return { "failure" : Messages.invalidArguments() }

        from email.MIMEText import MIMEText
        message = MIMEText(body.encode('utf-8'), 'plain', 'utf-8')
        message['Subject'] = subject
        message['From'] = config['from_address']
        message['To'] = to_address
        try:
            self.emailSender().send_mime(to_address, config['from_address'], message)
        except Exception, e:
            return { "failure" : Messages.failedToSendEmail(exception=e) } 
Пример #3
0
    def send_email(self):
        if not authorized(ValidAuthKitUser()):
            return { "failure" : Messages.invalidSession() }

        try:
            to_address = request.params['to_address']
            subject = request.params['subject']
            body = request.params['body']
        except:
            return { "failure" : Messages.invalidArguments() }

        if to_address == "" or subject == "" or body == "":
            return { "failure" : Messages.invalidArguments() }

        from email.MIMEText import MIMEText

        message = MIMEText(body.encode('utf-8'), 'plain', 'utf-8')
        message['Subject'] = subject
        message['From'] = config['from_address']
        message['To'] = to_address
        try:
            from fivecents.lib.mail import EmailSender
            ms = EmailSender(to_addresses = to_address)
            ms.send_mime(message)
        except Exception, e:
            return { "failure" : Messages.failedToSendEmail(exception=e) } 
Пример #4
0
    def send_invitation(self):
        model = request.environ["sqlalchemy.model"]
        db = request.environ["sqlalchemy.session"]

        if not authorized(ValidAuthKitUser()):
            return { "failure" : Messages.invalidSession() }

        try:
            to_address = request.params['to_address']
            subject = _("You have been invited to %s " % h.site_name())
            body = request.params['body']
        except:
            return { "failure" : Messages.invalidArguments() }

        if to_address == "" or subject == "" or body == "":
            return { "failure" : Messages.invalidArguments() }

        invitation = model.Invitation(
            sender_uid = h.authenticated_user().uid, 
            to_address = to_address,
        )

        db.save(invitation)
        db.commit()

        c.invitation_link = h.site_url() + h.url_for(controller='signup', action='invitation', id=invitation.token)

        from email.MIMEText import MIMEText
        body = body + render_jinja('messages/invitation_footer.jinja')
        message = MIMEText(body.encode('utf-8'), 'plain', 'utf-8') 
        message['Subject'] = subject
        message['From'] = config['from_address']
        message['To'] = to_address
        try:
            from fivecents.lib.mail import EmailSender
            ms = EmailSender(to_addresses = to_address)
            ms.send_mime(message)
        except Exception, e:
            return { "failure" : Messages.failedToSendEmail(exception=e) }