コード例 #1
0
ファイル: scenarios.py プロジェクト: fparaggio/networkplanner
 def feedback(self):
     'Send feedback'
     # Load
     text = request.POST.get('text', '').strip()
     # If there is text,
     if text:
         # Initialize
         personID = h.getPersonID()
         headerByValue = {}
         # If the person is logged in,
         if personID:
             # Load
             person = Session.query(model.Person).get(personID)
             nickname = person.nickname
             headerByValue['reply-to'] = email.utils.formataddr((nickname, person.email))
         # If th person is not logged in,
         else:
             nickname = 'Anonymous'
         # Send it
         subject = '[%s] Feedback from %s' % (parameter.SITE_NAME, nickname)
         try:
             smtp.sendMessage(
                 config['safe']['mail support'], 
                 config['safe']['mail support'], subject, text, headerByValue)
         except:
             return dict(isOk=0, message='Error sending message')
         # Return
         return dict(isOk=1)
     # Return
     return dict(isOk=0)
コード例 #2
0
ファイル: people.py プロジェクト: fparaggio/networkplanner
        candidate.ticket = store.makeRandomUniqueTicket(parameter.TICKET_LENGTH, Session.query(model.PersonCandidate))
        candidate.when_expired = datetime.datetime.utcnow() + datetime.timedelta(days=parameter.TICKET_LIFESPAN_IN_DAYS)
        Session.add(candidate)
        Session.commit()
        # Prepare recipient
        toByValue = dict(nickname=form["nickname"], email=form["email"])
        # Prepare subject
        subject = "[%s] Confirm %s" % (parameter.SITE_NAME, action)
        # Prepare body
        c.candidate = candidate
        c.username = form["username"]
        c.action = action
        body = render(templatePath)
        # Send
        try:
            smtp.sendMessage(config["safe"]["mail support"], toByValue, subject, body)
        except smtp.SMTPError:
            return dict(isOk=0, errorByID={"status": "Unable to send confirmation; please try again later."})
        # Return
        return dict(isOk=1)


def purgeExpiredPersonCandidates():
    "Delete candidates that have expired"
    Session.execute(
        model.person_candidates_table.delete().where(model.PersonCandidate.when_expired < datetime.datetime.utcnow())
    )


def confirmPersonCandidate(ticket):
    "Move changes from the PersonCandidate table into the Person table"
コード例 #3
0
ファイル: people.py プロジェクト: AlphaStaxLLC/networkplanner
        candidate.ticket = store.makeRandomUniqueTicket(parameter.TICKET_LENGTH, Session.query(model.PersonCandidate))
        candidate.when_expired = datetime.datetime.utcnow() + datetime.timedelta(days=parameter.TICKET_LIFESPAN_IN_DAYS)
        Session.add(candidate) 
        Session.commit()
        # Prepare recipient
        toByValue = dict(nickname=form['nickname'], email=form['email'])
        # Prepare subject
        subject = '[%s] Confirm %s' % (parameter.SITE_NAME, action)
        # Prepare body
        c.candidate = candidate
        c.username = form['username']
        c.action = action
        body = render(templatePath)
        # Send
        try:
            smtp.sendMessage(config['safe']['mail support'], toByValue, subject, body)
        except smtp.SMTPError:
            return dict(isOk=0, errorByID={'status': 'Unable to send confirmation; please try again later.'})
        # Return
        return dict(isOk=1)

def purgeExpiredPersonCandidates():
    'Delete candidates that have expired'
    Session.execute(model.person_candidates_table.delete().where(model.PersonCandidate.when_expired<datetime.datetime.utcnow()))

def confirmPersonCandidate(ticket):
    'Move changes from the PersonCandidate table into the Person table'
    # Query
    candidate = Session.query(model.PersonCandidate).filter(model.PersonCandidate.ticket==ticket).filter(model.PersonCandidate.when_expired>=datetime.datetime.utcnow()).first()
    # If the ticket exists,
    if candidate: