Esempio n. 1
0
    def create_user(username,
                    email,
                    password,
                    active=False,
                    send_email=True,
                    **kwargs):
        uname = username.encode('utf-8') if isinstance(username,
                                                       unicode) else username
        salt, activation_key = generate_sha1(uname)

        #org_key = Organization._meta.verbose_name
        #org = Organization.get_current()
        #print 'create user:', username, email, password, kwargs
        new_user = User.create_user(username, email, password, **kwargs)
        new_user.is_active = active
        new_user.signup = UserRegistration(activation_key=activation_key)

        session = orm.sessionmaker()
        session.add(new_user)
        session.commit()

        if auth_settings.BAPH_ACTIVATION_REQUIRED:
            new_user.signup.send_activation_email()

        return new_user
Esempio n. 2
0
    def reissue_activation(activation_key):
        """
        Creates a new ``activation_key`` resetting activation timeframe when
        users let the previous key expire.

        :param activation_key:
            String containing the secret SHA1 activation key.

        """
        session = orm.sessionmaker()
        signup = session.query(UserRegistration) \
            .options(joinedload('user')) \
            .filter_by(activation_key=activation_key) \
            .first()
        if not signup:
            return False
        try:
            salt, new_activation_key = generate_sha1(signup.user.username)
            signup.activation_key = new_activation_key
            signup.user.date_joined = datetime.now()
            session.commit()
            signup.send_activation_email()
            return True
        except Exception as e:
            raise
            return False
Esempio n. 3
0
    def reissue_activation(activation_key):
        """
        Creates a new ``activation_key`` resetting activation timeframe when
        users let the previous key expire.

        :param activation_key:
            String containing the secret SHA1 activation key.

        """
        session = orm.sessionmaker()
        signup = session.query(UserRegistration) \
            .options(joinedload('user')) \
            .filter_by(activation_key=activation_key) \
            .first()
        if not signup:
            return False
        try:
            salt, new_activation_key = generate_sha1(signup.user.username)
            signup.activation_key = new_activation_key
            signup.user.date_joined = datetime.now()
            session.commit()
            signup.send_activation_email()
            return True
        except Exception as e:
            raise
            return False
Esempio n. 4
0
    def create_user(username, email, password, active=False, send_email=True,
                     **kwargs):
        uname = username.encode('utf-8') if isinstance(username, unicode) else username
        salt, activation_key = generate_sha1(uname)

        #org_key = Organization._meta.verbose_name
        #org = Organization.get_current()
        #print 'create user:', username, email, password, kwargs
        new_user = User.create_user(username, email, password, **kwargs)
        new_user.is_active = active
        new_user.signup = UserRegistration(activation_key=activation_key)

        session = orm.sessionmaker()
        session.add(new_user)
        session.commit()

        if auth_settings.BAPH_ACTIVATION_REQUIRED:
            new_user.signup.send_activation_email()
        
        return new_user
Esempio n. 5
0
    def change_email(self, email):
        """
        Changes the email address for a user.

        A user needs to verify this new email address before it becomes
        active. By storing the new email address in a temporary field --
        ``temporary_email`` -- we are able to set this email address after the
        user has verified it by clicking on the verification URI in the email.
        This email gets send out by ``send_verification_email``.

        :param email:
            The new email address that the user wants to use.

        """
        self.email_unconfirmed = email

        salt, hash = generate_sha1(self.user.username)
        self.email_confirmation_key = hash
        self.email_confirmation_key_created = datetime.datetime.now()
        self.save()

        # Send email for activation
        self.send_confirmation_email()