Exemplo n.º 1
0
    def setUp(self):
        user_fixture = json.loads(
            open('projects/test_fixtures/user.json').read())
        self.test_user = get_user_model().objects.create_user(
            user_fixture['username'], user_fixture['email'], 'password')
        project_terms = TermsAndConditions.objects.get(slug='project-terms')
        user_terms = UserTermsAndConditions(user=self.test_user,
                                            terms=project_terms)
        user_terms.save()

        self.test_user.backend = 'tas.auth.TASBackend'
Exemplo n.º 2
0
    def setUp(self):
        user_fixture = json.loads(open('projects/test_fixtures/user.json').read())
        self.test_user = get_user_model().objects.create_user(
                user_fixture['username'],
                user_fixture['email'],
                'password')
        project_terms = TermsAndConditions.objects.get(slug='project-terms')
        user_terms = UserTermsAndConditions(user=self.test_user, terms=project_terms)
        user_terms.save()

        self.test_user.backend = 'tas.auth.TASBackend'
Exemplo n.º 3
0
    def save(self, source='DesignSafe', pi_eligibility=INELIGIBLE):
        data = self.cleaned_data
        data['source'] = source
        data['piEligibility'] = pi_eligibility

        safe_data = data.copy()
        safe_data['password'] = safe_data['confirmPassword'] = '******'

        logger.info('Attempting new user registration: %s' % safe_data)
        tas_user = TASClient().save_user(None, data)

        # create local user
        UserModel = get_user_model()
        try:
            # the user should not exist
            user = UserModel.objects.get(username=data['username'])
            logger.warning('On TAS registration, local user already existed? '
                           'user=%s' % user)
        except UserModel.DoesNotExist:
            user = UserModel.objects.create_user(
                username=data['username'],
                first_name=tas_user['firstName'],
                last_name=tas_user['lastName'],
                email=tas_user['email'],
                agree_to_account_limit=data['agree_to_account_limit'])

        # extended profile information
        try:
            # again, this should not exist
            ds_profile = DesignSafeProfile.objects.get(user=user)
            ds_profile.ethnicity = data['ethnicity']
            ds_profile.gender = data['gender']
        except DesignSafeProfile.DoesNotExist:
            ds_profile = DesignSafeProfile(user=user,
                                           ethnicity=data['ethnicity'],
                                           gender=data['gender'])
        ds_profile.save()

        # terms of use
        logger.info(
            'Prior to Registration, %s %s <%s> agreed to Terms of Use' %
            (data['firstName'], data['lastName'], data['email']))
        try:
            terms = TermsAndConditions.get_active()
            user_terms = UserTermsAndConditions(user=user, terms=terms)
            user_terms.save()
        except:
            logger.exception('Error saving UserTermsAndConditions for user=%s',
                             user)

        return tas_user
Exemplo n.º 4
0
    def save(self, source='DesignSafe', pi_eligibility=INELIGIBLE):
        data = self.cleaned_data
        data['source'] = source
        data['piEligibility'] = pi_eligibility

        safe_data = data.copy()
        safe_data['password'] = safe_data['confirmPassword'] = '******'

        logger.info('Attempting new user registration: %s' % safe_data)
        tas_user = TASClient().save_user(None, data)

        # create local user
        UserModel = get_user_model()
        try:
            # the user should not exist
            user = UserModel.objects.get(username=data['username'])
            logger.warning('On TAS registration, local user already existed? '
                           'user=%s' % user)
        except UserModel.DoesNotExist:
            user = UserModel.objects.create_user(
                username=data['username'],
                first_name=tas_user['firstName'],
                last_name=tas_user['lastName'],
                email=tas_user['email'],
                )

        # extended profile information
        try:
            # again, this should not exist
            ds_profile = DesignSafeProfile.objects.get(user=user)
            ds_profile.ethnicity = data['ethnicity']
            ds_profile.gender = data['gender']
        except DesignSafeProfile.DoesNotExist:
            ds_profile = DesignSafeProfile(
                user=user,
                ethnicity=data['ethnicity'],
                gender=data['gender']
                )
        ds_profile.save()

        # terms of use
        logger.info('Prior to Registration, %s %s <%s> agreed to Terms of Use' % (
            data['firstName'], data['lastName'], data['email']))
        try:
            terms = TermsAndConditions.get_active()
            user_terms = UserTermsAndConditions(user=user, terms=terms)
            user_terms.save()
        except:
            logger.exception('Error saving UserTermsAndConditions for user=%s', user)

        return tas_user
Exemplo n.º 5
0
    def save(self, source='DesignSafe', pi_eligibility=INELIGIBLE):
        data = self.cleaned_data
        data['source'] = source
        data['piEligibility'] = pi_eligibility

        #pull out specific fields from data for tas and pro profile
        tas_keys = [
            'firstName', 'lastName', 'email', 'confirmEmail', 'phone',
            'institutionId', 'departmentId', 'institution', 'title',
            'countryId', 'citizenshipId', 'ethnicity', 'gender', 'source',
            'piEligibility', 'username', 'password', 'confirmPassword',
            'agree_to_terms', 'agree_to_account_limit'
        ]
        pro_profile_fields = [
            'nh_interests', 'nh_interests_primary', 'nh_technical_domains',
            'bio', 'website', 'orcid_id', 'professional_level',
            'research_activities'
        ]
        pro_profile_data = {}
        tas_data = {}
        for key in data:
            if key in tas_keys:
                tas_data[key] = data[key]
            if key in pro_profile_fields:
                pro_profile_data[key] = data[key]

        safe_data = tas_data.copy()
        safe_data['password'] = safe_data['confirmPassword'] = '******'

        LOGGER.info('Attempting new user registration: %s' % safe_data)
        tas_user = TASClient().save_user(None, tas_data)

        # create local user
        UserModel = get_user_model()
        try:
            # the user should not exist
            user = UserModel.objects.get(username=data['username'])
            LOGGER.warning('On TAS registration, local user already existed? '
                           'user=%s' % user)
        except UserModel.DoesNotExist:
            user = UserModel.objects.create_user(
                username=data['username'],
                first_name=tas_user['firstName'],
                last_name=tas_user['lastName'],
                email=tas_user['email'])

        # extended profile information
        try:
            # again, this should not exist
            ds_profile = DesignSafeProfile.objects.get(user=user)
            ds_profile.ethnicity = data['ethnicity']
            ds_profile.gender = data['gender']
            ds_profile.bio = data['bio']
            ds_profile.website = data['website']
            ds_profile.orcid_id = data['orcid_id']
            ds_profile.professional_level = data['professional_level']
            ds_profile.update_required = False
        except DesignSafeProfile.DoesNotExist:
            ds_profile = DesignSafeProfile(
                user=user,
                ethnicity=data['ethnicity'],
                gender=data['gender'],
                bio=data['bio'],
                website=data['website'],
                orcid_id=data['orcid_id'],
                professional_level=data['professional_level'],
                update_required=False)
        ds_profile.save()

        #save professional profile information
        pro_profile = ProfessionalProfileForm(instance=ds_profile)
        pro_profile.cleaned_data = pro_profile_data
        pro_profile.save()

        # terms of use
        LOGGER.info(
            'Prior to Registration, %s %s <%s> agreed to Terms of Use' %
            (data['firstName'], data['lastName'], data['email']))
        try:
            terms = TermsAndConditions.get_active()
            user_terms = UserTermsAndConditions(user=user, terms=terms)
            user_terms.save()
        except:
            LOGGER.exception('Error saving UserTermsAndConditions for user=%s',
                             user)

        return tas_user