Exemplo n.º 1
0
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:
        # If the person exists,
        if candidate.person_id:
            # Update person
            person = Session.query(model.Person).get(candidate.person_id)
            person.username = candidate.username
            person.password_hash = candidate.password_hash
            person.nickname = candidate.nickname
            person.email = candidate.email
            person.email_sms = candidate.email_sms
            # Reset rejection_count
            person.rejection_count = 0
        # If the person does not exist,
        else:
            # Add person
            Session.add(
                model.Person(
                    candidate.username,
                    candidate.password_hash,
                    candidate.nickname,
                    candidate.email,
                    candidate.email_sms,
                )
            )
        # Delete ticket
        Session.delete(candidate)
        # Commit
        Session.commit()
    # Return
    return candidate
Exemplo n.º 2
0
        return render('/jobs/show.mako')


# Helpers

def changeJob(valueByName, ownerID, job=None):
    'Validate values and send confirmation email if values are okay'
    try:
        # Validate form
        form = JobForm().to_python(valueByName, job)
    except formencode.Invalid, error:
        return dict(isOk=0, errorByID=error.unpack_errors())
    # If the job does not exist, add it
    if not job:
        job = model.Job()
        Session.add(job)
    # Set fields
    job.title = form['title'].strip()
    job.budget = form['budget']
    job.description = form['description'].strip()
    job.when_updated = datetime.datetime.utcnow()
    job.owner_id = ownerID
    # Commit
    Session.commit()
    # Return
    return dict(isOk=1, jobID=job.id)


# Validators

class Unique(formencode.validators.FancyValidator):
Exemplo n.º 3
0
 try:
     # Validate form
     form = PersonForm().to_python(valueByName, person)
 except formencode.Invalid, error:
     return dict(isOk=0, errorByID=error.unpack_errors())
 else:
     # Purge expired candidates
     purgeExpiredPersonCandidates()
     # Prepare candidate
     candidate = model.PersonCandidate(
         form["username"], model.hashString(form["password"]), form["nickname"], form["email"], form["email_sms"]
     )
     candidate.person_id = person.id if person else None
     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(
             dict(
                 email=config["error_email_from"],