示例#1
0
def processRegistration(email):
    'Process an SMS address registration'
    # Get userID and code
    match = pattern_registration.match(email.subject)
    if not match:
        return False
    userID, userCode = match.groups()
    userID = int(userID)
    fromWhom = parseaddr(email.fromWhom)[1]
    # Make sure we have a proper email address
    try:
        fromWhom = validators.Email(not_empty=True).to_python(fromWhom)
    except Invalid:
        return False
    # If userID is zero, then the sender wants to unregister his or her address
    if userID == 0:
        db.query(SMSAddress).filter_by(email=fromWhom).delete()
        return True
    # Load
    user = db.query(User).filter_by(id=userID, code=userCode).options(
        joinedload(User.sms_addresses)).first()
    # If the user doesn't exist,
    if not user:
        return False
    # If we have registered the address already,
    if fromWhom in (x.email for x in user.sms_addresses):
        return True
    # Add
    db.add(SMSAddress(email=fromWhom, user_id=userID))
    return True
示例#2
0
def processRegistration(email):
    'Process an SMS address registration'
    # Get userID and code
    match = pattern_registration.match(email.subject)
    if not match:
        return False
    userID, userCode = match.groups()
    userID = int(userID)
    fromWhom = parseaddr(email.fromWhom)[1]
    # Make sure we have a proper email address
    try:
        fromWhom = validators.Email(not_empty=True).to_python(fromWhom)
    except Invalid:
        return False
    # If userID is zero, then the sender wants to unregister his or her address
    if userID == 0:
        db.query(SMSAddress).filter_by(email=fromWhom).delete()
        return True
    # Load
    user = db.query(User).filter_by(id=userID, code=userCode).options(joinedload(User.sms_addresses)).first()
    # If the user doesn't exist,
    if not user:
        return False
    # If we have registered the address already,
    if fromWhom in (x.email for x in user.sms_addresses):
        return True
    # Add
    db.add(SMSAddress(email=fromWhom, user_id=userID))
    return True
示例#3
0
    except RuntimeError:
        return dict(isOk=0,
                    errorByID={
                        'status':
                        'Could not generate ticket; please try again later'
                    })
    # Prepare user_
    user_ = User_(username=form['username'],
                  password=form['password'],
                  nickname=form['nickname'],
                  email=form['email'],
                  user_id=user.id if user else None,
                  ticket=ticket,
                  when_expired=datetime.datetime.utcnow() +
                  datetime.timedelta(hours=TICKET_HOURS))
    db.add(user_)
    # Send message
    get_mailer(request).send_to_queue(
        Message(recipients=[formataddr((user_.nickname, user_.email))],
                subject='Confirm {}'.format(action),
                body=render(
                    'users/confirm.mak', {
                        'form': form,
                        'ticket': ticket,
                        'action': action,
                        'TICKET_HOURS': TICKET_HOURS,
                    }, request)))
    # Return
    return dict(isOk=1)

示例#4
0
    # Prepare ticket
    try:
        ticket = make_random_unique_string(TICKET_LEN, 
            lambda x: db.query(User_).filter_by(ticket=x).first() == None)
    except RuntimeError:
        return dict(isOk=0, errorByID={'status': 'Could not generate ticket; please try again later'})
    # Prepare user_
    user_ = User_(
        username=form['username'],
        password=form['password'], 
        nickname=form['nickname'], 
        email=form['email'],
        user_id=user.id if user else None,
        ticket=ticket,
        when_expired=datetime.datetime.utcnow() + datetime.timedelta(hours=TICKET_HOURS))
    db.add(user_)
    # Send message
    get_mailer(request).send_to_queue(Message(
        recipients=[formataddr((user_.nickname, user_.email))],
        subject='Confirm {}'.format(action),
        body=render('users/confirm.mak', {
            'form': form,
            'ticket': ticket,
            'action': action,
            'TICKET_HOURS': TICKET_HOURS,
        }, request)))
    # Return
    return dict(isOk=1)


def apply_user_(ticket):