예제 #1
0
    def confirm_user(self, r, confirmation_code, timezone):
        confirm = r.session.query(ConfirmationCode).filter_by(code=confirmation_code.lower()).first()
        if confirm:
            ud = self._deserialize(confirm.data)

            user = User(ud['email'], ud['mobile'])
            user.password = util.encrypt_password(ud['password'])
            user.created = datetime.utcnow()
            user.plan = 'free' 
            user.sms_credits_plan = limits.get_plan_credits('free')
            user.sms_credits_purchased = 0
            user.billing_type = 0
            user.timezone = timezone
            user.utc_offset = util.get_utc_offset(pytz.timezone(timezone))
            user.billing_start = datetime.utcnow()
            user.billing_next = user.billing_start + relativedelta(months=+1)
            
            # create two default destinations
            default_sms_destination = Destination(user, Destination.TYPE_SMS, 'Default SMS', user.mobile)
            default_email_destination = Destination(user, Destination.TYPE_EMAIL, 'Default Email', user.email)
            r.session.delete(confirm)
            r.session.save(user)
            r.session.save(default_sms_destination)
            r.session.save(default_email_destination)
            r.session.flush()
            r.hub.sendWelcome(user.email, user.password)
            r.environ['paste.auth_tkt.set_user'](userid=user.email)
        else:
            raise ValidationFailedException(dict(confirmation_code='Confirmation code is invalid'))
예제 #2
0
def daily_billing(session):
    q = select([t_user.c.user_id, t_user.c.billing_next, t_user.c.plan], t_user.c.billing_type == 0)
    today = date.today()
    for user_id, billing_next, plan in q.execute():
        if billing_next == today:
            new_credits = get_plan_credits(plan)
            new_billing_next = billing_next + relativedelta(months=+1)
            log.info("User %d doing billing cycle: new credits %s, next billing date: %s", user_id, new_credits, new_billing_next)
            u = t_user.update().where(t_user.c.user_id==user_id).values(billing_next=new_billing_next,
                                                                        sms_credits_plan=new_credits)
            session.execute(u)