Beispiel #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'))
Beispiel #2
0
 def change_password(self, r, old_password, new_password, confirm_password):
     if r.user.password == encrypt_password(old_password):
         r.user.password = encrypt_password(new_password)
         r.session.flush()
     else:
         raise ValidationFailedException(dict(old_password='******'))