コード例 #1
0
ファイル: utils.py プロジェクト: pjsier/muckrock
def miniregister(full_name, email, password):
    """
    Create a new user from just their full name and email and return the user.
    - compress first and last name to create username
        - username must be unique
        - if the username already exists, add a number to the end
    - given the username, email, and password, create a new User
    - split the full name string to get the first and last names
    - create a Profile for the user
    - send the user a welcome email with a link to reset their password
    """
    full_name = full_name.strip()
    username = unique_username(full_name)
    first_name, last_name = split_name(full_name)
    # create a new User
    user = User.objects.create_user(username,
                                    email,
                                    password,
                                    first_name=first_name,
                                    last_name=last_name)
    # create a new Profile
    Profile.objects.create(user=user,
                           acct_type='basic',
                           monthly_requests=settings.MONTHLY_REQUESTS.get(
                               'basic', 0),
                           date_update=date.today())
    # send the new user a welcome email
    welcome_miniregister.delay(user)
    return user
コード例 #2
0
ファイル: mixins.py プロジェクト: clytwynec/muckrock
    def miniregister(self, full_name, email, newsletter=False):
        """Create a new user from their full name and email and login"""
        password = generate_key(12)
        full_name = full_name.strip()
        username = unique_username(full_name)
        first_name, last_name = split_name(full_name)
        # create a new User
        user = User.objects.create_user(username,
                                        email,
                                        password,
                                        first_name=first_name,
                                        last_name=last_name)
        # create a new Profile
        Profile.objects.create(user=user,
                               acct_type='basic',
                               monthly_requests=settings.MONTHLY_REQUESTS.get(
                                   'basic', 0),
                               date_update=date.today())
        # send the new user a welcome email
        welcome_miniregister.delay(user)
        user = authenticate(
            username=user.username,
            password=password,
        )
        login(self.request, user)
        if newsletter:
            mailchimp_subscribe(
                self.request,
                user.email,
                source='Mini-Register: {}'.format(self.minireg_source),
                url='https://{}{}'.format(settings.MUCKROCK_URL,
                                          self.request.path),
            )

        mixpanel_event(
            self.request,
            'Sign Up',
            {
                'Source': 'Mini-Register: {}'.format(self.minireg_source),
                'Newsletter': newsletter,
            },
            signup=True,
        )
        return user