Exemplo n.º 1
0
    def create(self, validated_data):
        params = validated_data

        site = Site.objects.get(pk=settings.SITE_ID)
        new_user = RegistrationProfile.objects.create_inactive_user(
            username=params.get('username'),
            password=params.get('password1'),
            email=params.get('email'),
            site=site,
            send_email=settings.SEND_EMAIL_ACTIVATION_API)
        new_user.is_active = True
        new_user.first_name = params.get('first_name')
        new_user.last_name = params.get('last_name')
        new_user.save()

        created_by = self.context['request'].user
        created_by = None if created_by.is_anonymous() else created_by
        profile = UserProfile(user=new_user,
                              name=params.get('first_name'),
                              created_by=created_by,
                              city=params.get('city', u''),
                              country=params.get('country', u''),
                              organization=params.get('organization', u''),
                              home_page=params.get('home_page', u''),
                              twitter=params.get('twitter', u''))
        profile.save()

        return profile
Exemplo n.º 2
0
    def create(self, validated_data):
        params = validated_data
        request = self.context.get('request')

        site = Site.objects.get(pk=settings.SITE_ID)
        new_user = RegistrationProfile.objects.create_inactive_user(
            username=params.get('username'),
            password=params.get('password1'),
            email=params.get('email'),
            site=site,
            send_email=settings.SEND_EMAIL_ACTIVATION_API)
        new_user.is_active = True
        new_user.first_name = params.get('first_name')
        new_user.last_name = params.get('last_name')
        new_user.save()

        if getattr(settings, 'ENABLE_EMAIL_VERIFICATION', False):
            redirect_url = params.get('redirect_url')
            _send_verification_email(redirect_url, new_user, request)

        created_by = request.user
        created_by = None if created_by.is_anonymous() else created_by
        profile = UserProfile(user=new_user,
                              name=params.get('first_name'),
                              created_by=created_by,
                              city=params.get('city', u''),
                              country=params.get('country', u''),
                              organization=params.get('organization', u''),
                              home_page=params.get('home_page', u''),
                              twitter=params.get('twitter', u''),
                              metadata=params.get('metadata', dict))
        profile.save()

        return profile
Exemplo n.º 3
0
 def save(self, new_user):
     new_profile = \
         UserProfile(user=new_user, name=self.cleaned_data['name'],
                     city=self.cleaned_data['city'],
                     country=self.cleaned_data['country'],
                     organization=self.cleaned_data['organization'],
                     home_page=self.cleaned_data['home_page'],
                     twitter=self.cleaned_data['twitter'])
     new_profile.save()
     return new_profile
Exemplo n.º 4
0
 def save(self, new_user):
     new_profile = \
         UserProfile(user=new_user, name=self.cleaned_data['name'],
                     city=self.cleaned_data['city'],
                     country=self.cleaned_data['country'],
                     organization=self.cleaned_data['organization'],
                     home_page=self.cleaned_data['home_page'],
                     twitter=self.cleaned_data['twitter'])
     new_profile.save()
     return new_profile
Exemplo n.º 5
0
 def register(self, request, **cleaned_data):
     new_user = \
         super(FHRegistrationView, self).register(request, **cleaned_data)
     new_profile = \
         UserProfile(user=new_user, name=cleaned_data['name'],
                     city=cleaned_data['city'],
                     country=cleaned_data['country'],
                     organization=cleaned_data['organization'],
                     home_page=cleaned_data['home_page'],
                     twitter=cleaned_data['twitter'])
     new_profile.save()
     return new_user
Exemplo n.º 6
0
 def save(self, new_user):
     new_profile = UserProfile(
         user=new_user,
         name=self.cleaned_data["first_name"],
         city=self.cleaned_data["city"],
         country=self.cleaned_data["country"],
         organization=self.cleaned_data["organization"],
         home_page=self.cleaned_data["home_page"],
         twitter=self.cleaned_data["twitter"],
     )
     new_profile.save()
     return new_profile
Exemplo n.º 7
0
 def register(self, request, **cleaned_data):
     new_user = \
         super(FHRegistrationView, self).register(request, **cleaned_data)
     new_profile = \
         UserProfile(user=new_user, name=cleaned_data['first_name'],
                     city=cleaned_data['city'],
                     country=cleaned_data['country'],
                     organization=cleaned_data['organization'],
                     home_page=cleaned_data['home_page'],
                     twitter=cleaned_data['twitter'])
     new_profile.save()
     return new_user
Exemplo n.º 8
0
 def save_user_profile(self, new_user):
     """
     Creates and returns a new_user profile.
     """
     new_profile = \
         UserProfile(user=new_user, name=self.cleaned_data['first_name'],
                     city=self.cleaned_data['city'],
                     country=self.cleaned_data['country'],
                     organization=self.cleaned_data['organization'],
                     home_page=self.cleaned_data['home_page'],
                     twitter=self.cleaned_data['twitter'])
     new_profile.save()
     return new_profile
Exemplo n.º 9
0
 def save_user_profile(self, new_user):
     """
     Creates and returns a new_user profile.
     """
     new_profile = \
         UserProfile(user=new_user, name=self.cleaned_data['first_name'],
                     city=self.cleaned_data['city'],
                     country=self.cleaned_data['country'],
                     organization=self.cleaned_data['organization'],
                     home_page=self.cleaned_data['home_page'],
                     twitter=self.cleaned_data['twitter'])
     new_profile.save()
     return new_profile
Exemplo n.º 10
0
 def register(self, request, **cleaned_data):
     new_user = super(FHRegistrationView, self).register(request, **cleaned_data)
     new_profile = UserProfile(
         user=new_user,
         name=cleaned_data["name"],
         city=cleaned_data["city"],
         country=cleaned_data["country"],
         organization=cleaned_data["organization"],
         home_page=cleaned_data["home_page"],
         twitter=cleaned_data["twitter"],
     )
     new_profile.save()
     return new_user
Exemplo n.º 11
0
 def restore_object(self, attrs, instance=None):
     def _get_first_last_names(name):
         name_split = name.split()
         first_name = name_split[0]
         last_name = u''
         if len(name_split) > 1:
             last_name = u' '.join(name_split[1:])
         return first_name, last_name
     params = copy.deepcopy(attrs)
     username = attrs.get('user.username', None)
     password = attrs.get('user.password', None)
     name = attrs.get('name', None)
     email = attrs.get('user.email', None)
     if username:
         params['username'] = username
     if email:
         params['email'] = email
     if password:
         params.update({'password1': password, 'password2': password})
     if instance:
         form = UserProfileForm(params, instance=instance)
         # form.is_valid affects instance object for partial updates [PATCH]
         # so only use it for full updates [PUT], i.e shallow copy effect
         if not self.partial and form.is_valid():
             instance = form.save()
         # get user
         if email:
             instance.user.email = form.cleaned_data['email']
         if name:
             first_name, last_name = _get_first_last_names(name)
             instance.user.first_name = first_name
             instance.user.last_name = last_name
         if email or name:
             instance.user.save()
         return super(
             UserProfileSerializer, self).restore_object(attrs, instance)
         #return instance  # TODO: updates
     form = RegistrationFormUserProfile(params)
     # does not require captcha
     form.REGISTRATION_REQUIRE_CAPTCHA = False
     if form.is_valid():
         first_name, last_name = _get_first_last_names(name)
         new_user = User(username=username, first_name=first_name,
                         last_name=last_name, email=email)
         new_user.set_password(password)
         new_user.save()
         created_by = self.context['request'].user
         profile = UserProfile(
             user=new_user, name=attrs.get('name', u''),
             created_by=created_by,
             city=attrs.get('city', u''),
             country=attrs.get('country', u''),
             organization=attrs.get('organization', u''),
             home_page=attrs.get('home_page', u''),
             twitter=attrs.get('twitter', u''))
         return profile
     else:
         self.errors.update(form.errors)
     return attrs
Exemplo n.º 12
0
    def register(self, request, form):
        new_user = \
            super(FHRegistrationView, self).register(request, form)
        new_profile = UserProfile(
            user=new_user,
            name=form.cleaned_data['name'],
            city=form.cleaned_data['city'],
            country=form.cleaned_data['country'],
            organization=form.cleaned_data['organization'],

            #home_page=form.cleaned_data['home_page'],
            #twitter=form.cleaned_data['twitter'],
            #inclusion
            group=form.cleaned_data['group'],
        )
        new_profile.save()
        return new_user
Exemplo n.º 13
0
    def create(self, validated_data):
        params = validated_data
        request = self.context.get('request')
        metadata = {}

        site = Site.objects.get(pk=settings.SITE_ID)
        try:
            new_user = RegistrationProfile.objects.create_inactive_user(
                username=params.get('username'),
                password=params.get('password1'),
                email=params.get('email'),
                site=site,
                send_email=settings.SEND_EMAIL_ACTIVATION_API)
        except IntegrityError:
            raise serializers.ValidationError(
                _(u"User account {} already exists".format(
                    params.get('username'))))
        new_user.is_active = True
        new_user.first_name = params.get('first_name')
        new_user.last_name = params.get('last_name')
        new_user.save()

        if getattr(settings, 'ENABLE_EMAIL_VERIFICATION', False):
            redirect_url = params.get('redirect_url')
            _send_verification_email(redirect_url, new_user, request)

        created_by = request.user
        created_by = None if created_by.is_anonymous else created_by
        metadata['last_password_edit'] = timezone.now().isoformat()
        profile = UserProfile(user=new_user,
                              name=params.get('first_name'),
                              created_by=created_by,
                              city=params.get('city', u''),
                              country=params.get('country', u''),
                              organization=params.get('organization', u''),
                              home_page=params.get('home_page', u''),
                              twitter=params.get('twitter', u''),
                              metadata=metadata)
        profile.save()

        # cache user profile object
        cache.set(f'{USER_PROFILE_PREFIX}{new_user.username}', profile)

        return profile
Exemplo n.º 14
0
 def register(self, request, form):
     new_user = \
         super(FHRegistrationView, self).register(request, form)    
     new_profile = UserProfile(
         user=new_user,
         name=form.cleaned_data['name'],
         city=form.cleaned_data['city'],
         country=form.cleaned_data['country'],
         
         organization=form.cleaned_data['organization'],
         
         #home_page=form.cleaned_data['home_page'],
         #twitter=form.cleaned_data['twitter'],
         #inclusion
         group=form.cleaned_data['group'],
         
     )
     new_profile.save()
     return new_user
Exemplo n.º 15
0
    def create(self, validated_data):
        params = validated_data
        request = self.context.get('request')
        metadata = {}

        site = Site.objects.get(pk=settings.SITE_ID)
        new_user = RegistrationProfile.objects.create_inactive_user(
            username=params.get('username'),
            password=params.get('password1'),
            email=params.get('email'),
            site=site,
            send_email=settings.SEND_EMAIL_ACTIVATION_API)
        new_user.is_active = True
        new_user.first_name = params.get('first_name')
        new_user.last_name = params.get('last_name')
        new_user.save()

        if getattr(
            settings, 'ENABLE_EMAIL_VERIFICATION', False
        ):
            redirect_url = params.get('redirect_url')
            _send_verification_email(redirect_url, new_user, request)

        created_by = request.user
        created_by = None if created_by.is_anonymous else created_by
        metadata['last_password_edit'] = timezone.now().isoformat()
        profile = UserProfile(
            user=new_user, name=params.get('first_name'),
            created_by=created_by,
            city=params.get('city', u''),
            country=params.get('country', u''),
            organization=params.get('organization', u''),
            home_page=params.get('home_page', u''),
            twitter=params.get('twitter', u''),
            metadata=metadata
        )
        profile.save()

        return profile
Exemplo n.º 16
0
 def register(self, request, **cleaned_data):
     def _get_first_last_names(name):
         name_split = name.split()
         first_name = name_split[0]
         last_name = u''
         if len(name_split) > 1:
             last_name = u' '.join(name_split[1:])
         return first_name, last_name
     new_user = \
         super(FHRegistrationView, self).register(request, **cleaned_data)
     new_profile = \
         UserProfile(user=new_user, name=cleaned_data['name'],
                     city=cleaned_data['city'],
                     country=cleaned_data['country'],
                     organization=cleaned_data['organization'],
                     home_page=cleaned_data['home_page'],
                     twitter=cleaned_data['twitter'])
     new_profile.save()
     if cleaned_data['name']:
         fn, ln = _get_first_last_names(cleaned_data['name'])
         new_user.first_name = fn
         new_user.last_name = ln
         new_user.save()
     return new_user
Exemplo n.º 17
0
    def restore_object(self, attrs, instance=None):
        params = copy.deepcopy(attrs)
        username = attrs.get('user.username', None)
        password = attrs.get('user.password', None)
        name = attrs.get('name', None)
        email = attrs.get('user.email', None)

        if username:
            params['username'] = username

        if email:
            params['email'] = email

        if password:
            params.update({'password1': password, 'password2': password})

        if instance:
            form = UserProfileForm(params, instance=instance)

            # form.is_valid affects instance object for partial updates [PATCH]
            # so only use it for full updates [PUT], i.e shallow copy effect
            if not self.partial and form.is_valid():
                instance = form.save()

            # get user
            if email:
                instance.user.email = form.cleaned_data['email']

            if name:
                first_name, last_name = _get_first_last_names(name)
                instance.user.first_name = first_name
                instance.user.last_name = last_name

            if email or name:
                instance.user.save()

            return super(
                UserProfileSerializer, self).restore_object(attrs, instance)

        form = RegistrationFormUserProfile(params)
        # does not require captcha
        form.REGISTRATION_REQUIRE_CAPTCHA = False

        if form.is_valid():
            site = Site.objects.get(pk=settings.SITE_ID)
            new_user = RegistrationProfile.objects.create_inactive_user(
                username=username,
                password=password,
                email=email,
                site=site,
                send_email=True)
            new_user.is_active = True
            new_user.save()

            created_by = self.context['request'].user
            created_by = None if created_by.is_anonymous() else created_by
            profile = UserProfile(
                user=new_user, name=attrs.get('name', u''),
                created_by=created_by,
                city=attrs.get('city', u''),
                country=attrs.get('country', u''),
                organization=attrs.get('organization', u''),
                home_page=attrs.get('home_page', u''),
                twitter=attrs.get('twitter', u''))

            return profile

        else:
            self.errors.update(form.errors)

        return attrs