Example #1
0
def test_activation_has_asciinumeric_code(db_session):
    act = Activation()

    db_session.add(act)
    db_session.flush()

    assert re.match(r"[A-Za-z0-9]{12}", act.code)
Example #2
0
    def _require_activation(self, user):
        activation = Activation()
        self.session.add(activation)
        user.activation = activation

        # Flush the session to ensure that the user can be created and the
        # activation is successfully wired up.
        self.session.flush()

        # Send the activation email
        mail_params = self.signup_email(id=user.id,
                                        email=user.email,
                                        activation_code=user.activation.code)
        self.mailer.send.delay(*mail_params)
Example #3
0
    def signup(self, **kwargs):
        """
        Create a new user.

        All keyword arguments are passed to the :py:class:`h.models.User`
        constructor.
        """
        kwargs.setdefault('authority', self.default_authority)
        user = User(**kwargs)
        self.session.add(user)

        # Create a new activation for the user
        activation = Activation()
        self.session.add(activation)
        user.activation = activation

        # Flush the session to ensure that the user can be created and the
        # activation is successfully wired up.
        self.session.flush()

        # Send the activation email
        mail_params = self.signup_email(id=user.id,
                                        email=user.email,
                                        activation_code=user.activation.code)
        self.mailer.send.delay(*mail_params)

        # FIXME: this is horrible, but is needed until the
        # notification/subscription system is made opt-out rather than opt-in
        # (at least from the perspective of the database).
        sub = Subscriptions(uri=user.userid, type='reply', active=True)
        self.session.add(sub)

        # Record a registration with the stats service
        if self.stats is not None:
            self.stats.incr('auth.local.register')

        return user