Esempio n. 1
0
    def create_inactive_user(self, site, new_user=None, send_email=True, request=None, **user_info):
        """
        Create a new, inactive ``User``, generate a
        ``RegistrationProfile`` and email its activation key to the
        ``User``, returning the new ``User``.

        By default, an activation email will be sent to the new
        user. To disable this, pass ``send_email=False``.
        Additionally, if email is sent and ``request`` is supplied,
        it will be passed to the email template.

        """
        if new_user == None:
            password = user_info.pop('password')
            new_user = UserModel()(**user_info)
            new_user.set_password( password )
        new_user.is_active = True
        new_user.save()
        
        #user_for_choice = Student(student_text = new_user.username)
        #user_for_choice.save()

        registration_profile = self.create_profile(new_user)

        if send_email:
            registration_profile.send_activation_email(site, request)

        return new_user
Esempio n. 2
0
    def create_inactive_user(self,
                             site,
                             new_user=None,
                             send_email=True,
                             request=None,
                             **user_info):
        """
        Create a new, inactive ``User``, generate a
        ``RegistrationProfile`` and email its activation key to the
        ``User``, returning the new ``User``.

        By default, an activation email will be sent to the new
        user. To disable this, pass ``send_email=False``.
        Additionally, if email is sent and ``request`` is supplied,
        it will be passed to the email template.

        """
        if new_user == None:
            password = user_info.pop('password')
            new_user = UserModel()(**user_info)
            new_user.set_password(password)
        new_user.is_active = False
        new_user.save()

        registration_profile = self.create_profile(new_user)

        if send_email:
            registration_profile.send_activation_email(site, request)

        return new_user
Esempio n. 3
0
    def create_inactive_user(self,
                             username,
                             email,
                             password,
                             site=None,
                             send_email=True,
                             request=None,
                             **kwargs):
        """
        Create a new, inactive ``User``, generate a
        ``RegistrationProfile`` and email its activation key to the
        ``User``, returning the new ``User``.

        By default, an activation email will be sent to the new
        user. To disable this, pass ``send_email=False``.
        Additionally, if email is sent and ``request`` is supplied,
        it will be passed to the email template.
        """
        new_user = UserModel().objects.create_user(username, email, password,
                                                   **kwargs)
        new_user.is_active = False
        new_user.save()

        registration_profile = self.create_profile(new_user)

        if send_email:
            registration_profile.send_activation_email(site, request)

        return new_user
    def create_inactive_user(self, username, email, password,
                             site, send_email=True, request=None):

        """
        Create a new, inactive ``User``, generate a
        ``RegistrationProfile`` and email its activation key to the
        ``User``, returning the new ``User``.

        By default, an activation email will be sent to the new
        user. To disable this, pass ``send_email=False``.
        Additionally, if email is sent and ``request`` is supplied,
        it will be passed to the email template.

        """

        new_user = UserModel().objects.create_user(username, email, password)
        new_user.is_active = False
        new_user.save()

        registration_profile = self.create_profile(new_user)
        #send_email = False
        if send_email:
            registration_profile.send_activation_email(site, request)

        return new_user
    def test_users_can_fill_out_registration_form_and_create_profile(self):
        # Tired of Twitter, Facebook, and Instagram Brad has luckily heard
        # about the new social network on the block so he visits the website in
        # his browser
        self.browser.get(self.live_server_url + reverse('home'))

        # He notices that the title mentions TSN (so much cooler than Twitter
        # or Facebook) AND the page welcomes him to the site
        self.assertIn('TSN', self.browser.title)
        header_text = self.browser.find_element_by_tag_name('h1').text
        self.assertIn('Welcome', header_text)

        # He sees a link telling him to Register and he clicks it
        self.browser.find_element_by_id('register').click()

        # He winds up on a brand new page
        register_url = self.browser.current_url
        self.assertIn('/accounts/register', register_url)

        # Brad fills out the form on this page to create an account with TSN
        # and presses enter
        for name, value in [('first_name', 'Brad'), ('last_name', 'Pitt'),
                            ('username', 'brad'),
                            ('email', '*****@*****.**'),
                            ('password1', 'bradiscool'),
                            ('password2', 'bradiscool\t\n')]:
            self.browser.find_element_by_name(name).send_keys(value)

        # He finds himself on another page telling him to activate his account
        p_text = self.browser.find_element_by_tag_name('p').text
        self.assertEquals(
            'Please check your email to complete the registration process.',
            p_text)

        # After activating, he goes to the login page and logs in
        brad = UserModel().objects.get(username='******')
        brad.is_active = True
        brad.save()
        self.browser.get(self.live_server_url + reverse('auth_login'))
        self.browser.find_element_by_name('username').send_keys('brad')
        self.browser.find_element_by_name('password').send_keys(
            'bradiscool\t\n')

        # He is then immediately redirected to a page asking him to create a
        # profile
        self.browser.implicitly_wait(3)
        self.assertIn('profile/create', self.browser.current_url)

        # He provides his birthday and his gender
        self.browser.find_element_by_name('birthday').send_keys('12/18/1963')
        self.browser.find_element_by_name('gender').send_keys('M\t\n')

        # He is now on the homepage again, this time he sees a post box
        self.browser.implicitly_wait(3)
        self.assertEqual(self.live_server_url + reverse('home'),
                         self.browser.current_url)
        self.assertIn('new_post', self.browser.page_source)
    def test_users_can_fill_out_registration_form_and_create_profile(self):
        # Tired of Twitter, Facebook, and Instagram Brad has luckily heard
        # about the new social network on the block so he visits the website in
        # his browser
        self.browser.get(self.live_server_url + reverse('home'))

        # He notices that the title mentions TSN (so much cooler than Twitter
        # or Facebook) AND the page welcomes him to the site
        self.assertIn('TSN', self.browser.title)
        header_text = self.browser.find_element_by_tag_name('h1').text
        self.assertIn('Welcome', header_text)

        # He sees a link telling him to Register and he clicks it
        self.browser.find_element_by_id('register').click()

        # He winds up on a brand new page
        register_url = self.browser.current_url
        self.assertIn('/accounts/register', register_url)

        # Brad fills out the form on this page to create an account with TSN
        # and presses enter
        for name, value in [('first_name', 'Brad'),
                            ('last_name', 'Pitt'),
                            ('username', 'brad'),
                            ('email', '*****@*****.**'),
                            ('password1', 'bradiscool'),
                            ('password2', 'bradiscool\t\n')]:
            self.browser.find_element_by_name(name).send_keys(value)

        # He finds himself on another page telling him to activate his account
        p_text = self.browser.find_element_by_tag_name('p').text
        self.assertEquals('Please check your email to complete the registration process.', p_text)

        # After activating, he goes to the login page and logs in
        brad = UserModel().objects.get(username='******')
        brad.is_active = True
        brad.save()
        self.browser.get(self.live_server_url + reverse('auth_login'))
        self.browser.find_element_by_name('username').send_keys('brad')
        self.browser.find_element_by_name('password').send_keys('bradiscool\t\n')

        # He is then immediately redirected to a page asking him to create a
        # profile
        self.browser.implicitly_wait(3)
        self.assertIn('profile/create', self.browser.current_url)

        # He provides his birthday and his gender
        self.browser.find_element_by_name('birthday').send_keys('12/18/1963')
        self.browser.find_element_by_name('gender').send_keys('M\t\n')

        # He is now on the homepage again, this time he sees a post box
        self.browser.implicitly_wait(3)
        self.assertEqual(self.live_server_url + reverse('home'), self.browser.current_url)
        self.assertIn('new_post', self.browser.page_source)
Esempio n. 7
0
    def register(self, request, **cleaned_data):
        username, email, password, first_name, last_name = cleaned_data['username'], cleaned_data['email'], cleaned_data['password1'], cleaned_data['first_name'], cleaned_data['last_name']
        theuser = UserModel().objects.create_user(username = username,
            password = password,
            email = email,
            first_name = first_name,
            last_name = last_name
        )
        theuser.save()
        
        profile = UserProfile(user = theuser, location = cleaned_data['location'], career = cleaned_data['career'])
        profile.save()
        #(username, email, password, first_name, last_name)

        new_user = authenticate(username=username, password=password)
        login(request, new_user)
        signals.user_registered.send(sender=self.__class__,
                                     user=new_user,
                                     request=request)
        return new_user
Esempio n. 8
0
    def create_inactive_user(self, username, email, password,
                             site, send_email=True):
        """
        Create a new, inactive ``User``, generate a
        ``RegistrationProfile`` and email its activation key to the
        ``User``, returning the new ``User``.

        By default, an activation email will be sent to the new
        user. To disable this, pass ``send_email=False``.

        """
        new_user = UserModel().objects.create_user(username, email, password)
        new_user.is_active = False
        new_user.save()

        registration_profile = self.create_profile(new_user)

        if send_email:
            registration_profile.send_activation_email(site)

        return new_user
Esempio n. 9
0
    def create_inactive_user(self, username, email, password,
                             site, send_email=True):
        """
        Create a new, inactive ``User``, generate a
        ``RegistrationProfile`` and email its activation key to the
        ``User``, returning the new ``User``.

        By default, an activation email will be sent to the new
        user. To disable this, pass ``send_email=False``.

        """
        new_user = UserModel().objects.create_user(username, email, password)
        new_user.is_active = False
        new_user.save()

        registration_profile = self.create_profile(new_user)

        if send_email:
            registration_profile.send_activation_email(site)

        return new_user