예제 #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
                to_address = to_address,
                message = body
            )
            db.save(invitation)
        db.commit()
        return { "success" : Messages.messageWasSent() }

    @rest.restrict("POST")
    @jsonify
    def send_feedback(self):
        from_address = request.params.get('from_address')
        subject = _("Feedback about %s ") % h.site_name()
        body = request.params.get('body')

        if not from_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'] = from_address
        message['To'] = config['email_to']
        try:
            from fivecents.lib.mail import EmailSender
            ms = EmailSender(to_addresses = message['To'])
            ms.send_mime(message)
        except Exception, e:
            return { "failure" : Messages.failedToSendEmail(exception=e) } 

        return { "success" : Messages.messageWasSent() }