Beispiel #1
0
    def load_organization_data(self):
        data = self.data

        # User / Profile
        username1 = 'testuser'
        username2 = 'testuser2'

        data['password1'] = 'testuser13475'
        data['password2'] = 'testuser23475'

        data['user1'] = User(username=username1,
                             first_name='Test',
                             last_name='Client',
                             email='*****@*****.**',
                             is_superuser=True)
        data['user1'].set_password(data['password1'])
        data['user1'].save()

        data['user1'].profile = Profile()
        data['user1'].profile.save()

        data['authenticationdata1'] = AuthenticationData(
            backend=RADIUS_BACKEND_NAME,
            username=username1,
            user=data['user1'])
        data['authenticationdata1'].save()

        data['user2'] = User(username=username2,
                             first_name='Test2',
                             last_name='Client',
                             email='*****@*****.**')
        data['user2'].set_password(data['password2'])
        data['user2'].save()

        data['user2'].profile = Profile()
        data['user2'].profile.save()

        data['authenticationdata2'] = AuthenticationData(
            backend=RADIUS_BACKEND_NAME,
            username=username2,
            user=data['user2'])
        data['authenticationdata2'].save()

        # Organization
        data['organization1'] = Organization(name='Organization 1')
        data['organization1'].save()

        data['organization2'] = Organization(name='Organization 2')
        data['organization2'].save()

        # Location
        data['location1'] = Location(name='Location 1',
                                     is_public=True,
                                     prevent_conflicting_events=True)
        data['location1'].save()

        data['location2'] = Location(name='Location 2',
                                     is_public=True,
                                     prevent_conflicting_events=False)
        data['location2'].save()
    def update(self, instance: User, validated_data):
        # retrieve key parameters
        following_ids = validated_data.pop('following_ids', None)
        interest_ids = validated_data.pop('interest_ids', None)
        profile = validated_data.pop('profile', None)

        # update profile, if desired
        if isinstance(following_ids, list) or isinstance(interest_ids,
                                                         list) or profile:
            current_profile = instance.profile

            # following
            if isinstance(following_ids, list):
                following = User.objects.filter(id__in=following_ids)
                current_profile.following.set(following)

            # interests
            if isinstance(interest_ids, list):
                interests = Collection.objects.filter(id__in=interest_ids)
                current_profile.interests.set(interests)

            # rest
            if profile:
                for key in profile:
                    setattr(current_profile, key, profile[key])
            instance.profile = current_profile

        return super().update(instance, validated_data)
Beispiel #3
0
    def create(first_name,
               last_name,
               email,
               phone='',
               password=None,
               company=None,
               photo=None):
        u = User(username=str(uuid.uuid4()),
                 first_name=first_name,
                 last_name=last_name,
                 email=email)
        p = Profile()
        u.profile = p
        p.first_name = first_name
        p.last_name = last_name
        p.phone = phone

        if password is not None:
            u.set_password(password)
        u.save()
        p.user = u
        #p.user_id = u.id
        p.save()
        if photo:
            p.avatar = photo
        else:
            a = Avatar()
            a.save()
            p.avatar = a
        p.save()
        return p
Beispiel #4
0
    def load_organization_data(self):
        data = self.data

        # User / Profile
        username1 = 'testuser'
        username2 = 'testuser2'

        data['password1'] = 'testuser13475'
        data['password2'] = 'testuser23475'

        data['user1'] = User(username=username1, first_name='Test', last_name='Client', email='*****@*****.**',
                             is_superuser=True)
        data['user1'].set_password(data['password1'])
        data['user1'].save()

        data['user1'].profile = Profile()
        data['user1'].profile.save()

        data['authenticationdata1'] = AuthenticationData(backend=RADIUS_BACKEND_NAME, username=username1,
                                                         user=data['user1'])
        data['authenticationdata1'].save()

        data['user2'] = User(username=username2, first_name='Test2', last_name='Client', email='*****@*****.**')
        data['user2'].set_password(data['password2'])
        data['user2'].save()

        data['user2'].profile = Profile()
        data['user2'].profile.save()

        data['authenticationdata2'] = AuthenticationData(backend=RADIUS_BACKEND_NAME, username=username2,
                                                         user=data['user2'])
        data['authenticationdata2'].save()

        # Organization
        data['organization1'] = Organization(name='Organization 1')
        data['organization1'].save()

        data['organization2'] = Organization(name='Organization 2')
        data['organization2'].save()

        # Location
        data['location1'] = Location(name='Location 1', is_public=True, prevent_conflicting_events=True)
        data['location1'].save()

        data['location2'] = Location(name='Location 2', is_public=True, prevent_conflicting_events=False)
        data['location2'].save()
    def get_real_user(self, _):
        """
        Return a dummy user with a Mock profile.

        Expected by the LTI Consumer XBlock.
        """
        u = User()
        u.profile = Mock()
        u.profile.name = 'John Doe'
        return u
Beispiel #6
0
 def signup(self, request, user: User):
     p, _ = Profile.objects.get_or_create(user=user)
     user.first_name = self.cleaned_data['first_name']
     user.last_name = self.cleaned_data['last_name']
     p.preferred_name = self.cleaned_data['preferred_name']
     p.phone_number = self.cleaned_data['phone_number']
     p.perm_address = self.cleaned_data['perm_address']
     p.full_clean()
     p.save()
     user.profile = p
     user.save()
     return user
def create(request):
	if request.method=='GET':
		return render_to_response('Account/create.html', RequestContext(request))
	elif request.method=='POST':
		try:
			maxid = User.objects.aggregate(Max('id'))
			newUser = User(id=maxid['id__max']+1,first_name=request.POST['firstname'],last_name=request.POST['lastname'],email=request.POST['email'],password=request.POST['password'],username=request.POST['username'])
			newUser.profile=Profile(activated=False,interests=request.POST['interests'], user=newUser,major=request.POST['major'],email_subscribed='wantemails' in request.POST.keys(), gradmonth=request.POST['gradmonth'], gradyear=request.POST['gradyear']);
			newUser.save();
			newUser.profile.save();

			mail(request.POST['email'],"Account Confirmation",genMessage(request.POST,newUser.id));

			return render(request,'Account/create_success.html', {'firstname':request.POST['firstname'],'email':request.POST['email']});
		except IntegrityError:
			return render(request,'Account/create_error.html', {'message':"Username '{0}' is already taken.".format(request.POST['username'])});
		except Exception:
			return render(request,'Account/create_error.html', {'message':'An unexpected exception has occurred. Please try again later. If the problem persists, please contact [email protected].'});
Beispiel #8
0
def update_user_profile(sender, instance, created, **kwargs):
    if created:
        current_site = 'http://127.0.0.1:8000'
        subject = "Account Activation"
        user = User(username=instance.username,
                    email=instance.email,
                    is_active=False)
        user.set_password(str(instance.password))
        user.profile = instance
        user.save()
        subject = 'Activate Your {} Account'.format(current_site)
        message_txt = render_to_string(
            'registration/account_activation_email.txt', {
                'user': user,
                'Subject': subject,
                'password': instance.password,
                'email': instance.email,
                'domain': current_site,
                'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                'token': account_activation_token.make_token(user),
            })
        message_html = render_to_string(
            'registration/account_activation_email.html', {
                'user': user,
                'Subject': subject,
                'password': instance.password,
                'email': instance.email,
                'domain': current_site,
                'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                'token': account_activation_token.make_token(user),
            })
        user.email_user(subject,
                        message_txt,
                        '*****@*****.**',
                        html_message=message_html)
        instance.user = user
        instance.save()
    instance.user.save()
Beispiel #9
0
def user_add(request, radius_username, first_name, last_name, email):
    """
    Add a new user to Alexia.

    An user must have an unique radius_username and a valid email address.

    Returns the user information on success.

    radius_username  -- Unique RADIUS username
    first_name       -- First name
    last_name        -- Last name
    email            -- Valid email address

    Example result value:
    {
        "first_name": "John",
        "last_name": "Doe",
        "radius_username": "******"
    }

    Raises error -32602 (Invalid params) if the radius_username already exists.
    """
    if User.objects.filter(username=radius_username).exists() or \
            AuthenticationData.objects.filter(backend=RADIUS_BACKEND_NAME, username__iexact=radius_username).exists():
        raise InvalidParametersError('User with provided radius_username already exists')

    user = User(username=radius_username, first_name=first_name, last_name=last_name, email=email)
    user.save()

    data = AuthenticationData(user=user, backend=RADIUS_BACKEND_NAME, username=radius_username.lower())
    data.save()

    user.profile = Profile()
    user.profile.save()

    return format_user(user)
def post_save_user_signal_handler(sender, instance: User, created, **kwargs):
    try:
        instance.profile
    except User.profile.RelatedObjectDoesNotExist:
        instance.profile = Profile.objects.create(user=instance)
    def handle(self, *args, **options):
        """

        """

        tree = ET.parse("/home/vokal/vokalforening_d.xml")

        for item in tree.findall("Brugere"):

            try:

                User.objects.get(username=item.find("email").text)

            except User.DoesNotExist:

                u = User(
                    email=item.find("email").text,
                    first_name=item.find("fornavn").text,
                    last_name=item.find("efternavn").text,
                    is_active=item.find("aktiv").text == "1",
                )

                username = uuid.uuid4().hex[:30]
                try:
                    while True:
                        User.objects.get(username=username)
                        username = uuid.uuid4().hex[:30]
                except User.DoesNotExist:
                    pass

                u.username = username

                u.set_password(item.find("password").text)
                u.save()

                p = u.profile()
                try:
                    p.url = item.find("hjemmeside").text
                except AttributeError:
                    pass

                try:
                    p.address = item.find("adresse").text
                except AttributeError:
                    pass

                try:
                    p.postal_code = item.find("postnr").text
                except AttributeError:
                    pass

                try:
                    p.municipality = item.find("kommune").text
                except AttributeError:
                    pass

                try:
                    p.phone_number = item.find("tlf").text
                except AttributeError:
                    pass

                try:
                    p.mobile_phone_numer = item.find("mobil").text
                except AttributeError:
                    pass

                try:
                    p.receive_email = item.find("modtagmail").text == "1"
                except AttributeError:
                    pass

                try:
                    p.birthdate = datetime.date(int(item.find("fodselsaar").text), 1, 1)
                except AttributeError:
                    pass

                try:
                    p.education = item.find("uddannelse").text
                except AttributeError:
                    pass

                try:
                    p.position = item.find("stilling").text
                except AttributeError:
                    pass

                try:
                    p.experience = item.find("brancheerfaring").text
                except AttributeError:
                    pass

                p.save()