Ejemplo n.º 1
0
    def post(self, request, pk=None):
        if not pk:
            return redirect(reverse("dashboard"))

        client = Usuario.objects.get(pk=pk)

        form = ExtraInfoForm(request.POST, instance=client)
        if form.is_valid():
            
            state = State.objects.get_or_create(uf=request.POST.get('state'), cod_ibge=request.POST.get('cod_ibge'))[0]
            city = City.objects.get_or_create(name=request.POST.get('city'), latitude=request.POST.get('latitude'),longitude=request.POST.get('longitude'), state=state, cod_ibge=state.cod_ibge)[0]
            neighborhood = Neighborhood.objects.get_or_create(description=request.POST.get('neighborhood'), city=city)[0]
            place = Place.objects.get_or_create(zip_code=request.POST.get('zip_code'), city=city, latitude=city.latitude, longitude=city.longitude, neighborhood=neighborhood)[0]
            
            address = Address()
            address.street = request.POST.get('street')
            address.number = request.POST.get('number')
            address.complement = request.POST.get('complement')
            address.reference_point = request.POST.get('reference_point')
            address.place = place
            address.neighborhood = neighborhood
            address.city = city
            address.state = state
            address.latitude = city.latitude
            address.longitude = city.longitude
            address.save()

            # UPDATING CLIENT
            client = form.save(commit=False)
            client.address = address
            client.save()

            # ACTIVATING USER
            user = client.user
            user.is_active = True
            user.save()

            # ALLAUTH EMAIL
            try:
                auth_email = EmailAddress.objects.get(user=client.user, email=client.email)
            except:
                auth_email = EmailAddress()
                
            auth_email.user = client.user
            auth_email.email = client.email
            auth_email.save()

            # SENDING EMAIL CONFIRMATION
            auth_email.send_confirmation()

            response = {
                'status': 'success', 
                'message':'Usuário criado com sucesso', 
                'redirect':reverse("account_login")
            }

            return JsonResponse(response, status=200)

        return JsonResponse({'status': 'form_error', 'message':'Favor preencher todos os campos'}, status=400)
Ejemplo n.º 2
0
    def _save_email_addresses(self, request):
        adapter = get_adapter()
        # user.email may not be listed as an EmailAddress ...
        user = self.account.user
        try:
            primary_email_address = EmailAddress.objects.get(user=user,
                                                             primary=True)
        except EmailAddress.DoesNotExist:
            primary_email_address = None

        if (user.email
                and (user.email.lower()
                     not in [e.email.lower() for e in self.email_addresses])):
            # ... so let's append it
            email_address \
                = EmailAddress(user=user,
                               email=user.email,
                               verified=adapter.is_email_verified(request,
                                                                  user.email),
                               primary=(not primary_email_address))
            if not primary_email_address:
                primary_email_address = email_address
            self.email_addresses.append(email_address)

        for email_address in self.email_addresses:
            # Pick up only valid ones...
            email = valid_email_or_none(email_address.email)
            if not email:
                continue
            # ... and non-conflicting ones...
            if (account_settings.UNIQUE_EMAIL and
                    EmailAddress.objects.filter(email__iexact=email).exists()):
                continue
            if email_address.primary:
                if not primary_email_address:
                    primary_email_address = email_address
                else:
                    email_address.primary = False
            email_address.user = user
            email_address.verified \
                = (email_address.verified
                   or adapter.is_email_verified(request,
                                                email_address.email))
            email_address.save()

        if primary_email_address and (
                not user.email
                or primary_email_address.email.lower() != user.email.lower()):
            user.email = primary_email_address.email
            user.save()
        adapter.stash_email_verified(request, None)
Ejemplo n.º 3
0
    def _save_email_addresses(self, request):
        adapter = get_adapter()
        # user.email may not be listed as an EmailAddress ...
        user = self.account.user
        try:
            primary_email_address = EmailAddress.objects.get(user=user,
                                                             primary=True)
        except EmailAddress.DoesNotExist:
            primary_email_address = None


        if (user.email 
            and (user.email.lower() not in [e.email.lower() 
                                            for e in self.email_addresses])):
            # ... so let's append it
            email_address \
                = EmailAddress(user=user,
                               email=user.email,
                               verified=adapter.is_email_verified(request, 
                                                                  user.email),
                               primary=(not primary_email_address))
            if not primary_email_address:
                primary_email_address = email_address
            self.email_addresses.append(email_address)

        for email_address in self.email_addresses:
            # Pick up only valid ones...
            email = valid_email_or_none(email_address.email)
            if not email:
                continue
            # ... and non-conflicting ones...
            if (account_settings.UNIQUE_EMAIL 
                and EmailAddress.objects.filter(email__iexact=email).exists()):
                continue
            if email_address.primary:
                if not primary_email_address:
                    primary_email_address = email_address
                else:
                    email_address.primary = False
            email_address.user = user
            email_address.verified \
                = (email_address.verified 
                   or adapter.is_email_verified(request, 
                                                email_address.email))
            email_address.save()

        if primary_email_address and (not user.email or primary_email_address.email.lower() != user.email.lower()):
            user.email = primary_email_address.email
            user.save()
        adapter.stash_email_verified(request, None)
Ejemplo n.º 4
0
 def save_model(self, request, obj, form, change):
     data = dict(email=obj.email)
     user = User.objects.filter(email=data['email'])
     if user.exists() is False:
         obj.save()
         serializer = CustomUserCreateSerializer(data=data)
         serializer.is_valid(raise_exception=True)
         serializer.save()
         email_address = EmailAddress()
         email_address.user = user[0]
         email_address.verified = True
         email_address.primary = True
         email_address.email = data['email']
         email_address.save()
     else:
         obj.save()
Ejemplo n.º 5
0
def post_user_signed_up_checkinvitation(request, user, *args, **kwargs):
    Invitation = get_invitation_model()
    try:
        invite = Invitation.objects.get(email=user.email)
    except:
        logger.info("User is not an invited user. Register as admin")
        """
        is_admin is true
        is_organisation_default is true
        userorganization is blank
        """
    else:
        """
        is_admin is true
        is_organisation_default is true
        userorganization is blank
        """
        try:
            inviter_user = User.objects.get(pk=invite.inviter_id)
        except:
            logger.critical(
                "Error setting up invited user - Inviter user not found")
        else:
            user.userorganization = inviter_user.userorganization
            user.is_admin = False
            user.is_team_member = True
            user.is_organisation_default = False
            try:
                user.save()
            except:
                logger.critical("Error updating invited users")
            else:
                try:
                    emailAddress = EmailAddress.objects.get(email=user.email)
                except:
                    emailAddress = EmailAddress()
                    emailAddress.user = user.pk
                    emailAddress.email = user.email
                    emailAddress.verified = True
                    emailAddress.primary = True
                    try:
                        emailAddress.save()
                    except:
                        logger.critical("Error setting up verified email")
                else:
                    logger.info("Invited users - email already verified.")
Ejemplo n.º 6
0
 def create_superuser(self, username, password, **extra_fields):
     email = '*****@*****.**'
     user = self.create_user(username, password=password, email=email, **extra_fields)
     user.is_admin = True
     user.is_active = True
     user.is_verified = True
     user.set_password(password)
     user.save(using=self._db)
     # Now add this user's email address to EmailAddress table
     # Otherwise, user won't be able to login.
     email_address = EmailAddress()
     email_address.user = user
     email_address.verified = True
     email_address.primary = True
     email_address.email = email
     email_address.save()
     return user
Ejemplo n.º 7
0
def new_user(email, username=''):
    User = get_user_model()
    if username:
        assert is_username_unique(username)
    else:
        basename = email.split('@')[0]
        username = make_unique_username(basename)
    if User.objects.filter(email=email):
        raise ValueError('Email "{}" not unique.'.format(email))
    user = User(username=username, email=email)
    user.save()

    # Set up email for allauth.
    ea = EmailAddress(user=user, email=email, primary=True, verified=False)
    ea.user = user
    ea.save()

    return user
Ejemplo n.º 8
0
    def create_superuser(self, email, password, **extra_fields):
        """
        Creates and saves a superuser with the given email and password.
        """
        user = self.create_user(
            email,
            password=password,
            **extra_fields,
        )
        user.is_superuser = True
        user.is_staff = True
        user.save(using=self._db)

        new_allauth_email = EmailAddress()
        new_allauth_email.user = user
        new_allauth_email.email = email
        new_allauth_email.verified = True
        new_allauth_email.primary = True
        new_allauth_email.save()

        return user
Ejemplo n.º 9
0
    def post(self, request):
        context = {}
        serializer = serializers.RegisterSerializer(data=request.data)
        message = {}
        if serializer.is_valid():
            if Usuario.objects.filter(email=serializer.data['email']).exists():
                message = {'status': 'error', 'message': 'Email já cadastrado.'}
                return Response(message,status=500)
            else:
                try:
                    user = Usuario.objects.create_user(serializer.data['email'], serializer.data['password'])
                    user.nome = serializer.data['nome_completo']
                    user.nomecomleto = serializer.data['nome_completo']
                    user.is_active = True
                    user.token = binascii.b2a_hex(os.urandom(15))
                    user.save()
                except Exception as e:
                    user.delete()
                    message = {'status': 'error', 'message': str(e)}
                    return Response(message,status=500)
                
                try:
                    email_address = EmailAddress()
                    email_address.verified = False
                    email_address.user = user
                    email_address.email = user.email
                    email_address.save()

                except Exception as e:
                    user.delete()
                    email_address.delete()
                    message = {'status': 'error', 'message': str(e)}
                    return Response(message,status=500)
                    
            message = {'status':'success'}
            return Response(message,status=200)
        else:

            message = {'status':'error'}
            return Response(message,status=400)
Ejemplo n.º 10
0
def import_data():
    # Initial Imports
    from django.contrib.auth.models import Group

    # Processing model: opencourse.courses.models.City

    from opencourse.courses.models import City

    courses_city_1 = City()
    courses_city_1.codepostal = None
    courses_city_1.name = "London"
    courses_city_1.name_en = "London"
    courses_city_1.name_fr = "Londres"
    courses_city_1.latitude_south = None
    courses_city_1.latitude_north = None
    courses_city_1.longitude_west = None
    courses_city_1.longitude_east = None
    courses_city_1.latitude_southa = None
    courses_city_1.latitude_northa = None
    courses_city_1.longitude_westa = None
    courses_city_1.longitude_easta = None
    courses_city_1.category_1 = None
    courses_city_1.category_2 = None
    courses_city_1 = importer.save_or_locate(courses_city_1)

    courses_city_2 = City()
    courses_city_2.codepostal = None
    courses_city_2.name = "Paris"
    courses_city_2.name_en = "Paris"
    courses_city_2.name_fr = "Paris"
    courses_city_2.latitude_south = None
    courses_city_2.latitude_north = None
    courses_city_2.longitude_west = None
    courses_city_2.longitude_east = None
    courses_city_2.latitude_southa = None
    courses_city_2.latitude_northa = None
    courses_city_2.longitude_westa = None
    courses_city_2.longitude_easta = None
    courses_city_2.category_1 = None
    courses_city_2.category_2 = None
    courses_city_2 = importer.save_or_locate(courses_city_2)

    courses_city_3 = City()
    courses_city_3.codepostal = None
    courses_city_3.name = "Washington"
    courses_city_3.name_en = "Washington"
    courses_city_3.name_fr = "Washington"
    courses_city_3.latitude_south = None
    courses_city_3.latitude_north = None
    courses_city_3.longitude_west = None
    courses_city_3.longitude_east = None
    courses_city_3.latitude_southa = None
    courses_city_3.latitude_northa = None
    courses_city_3.longitude_westa = None
    courses_city_3.longitude_easta = None
    courses_city_3.category_1 = None
    courses_city_3.category_2 = None
    courses_city_3 = importer.save_or_locate(courses_city_3)

    courses_city_4 = City()
    courses_city_4.codepostal = None
    courses_city_4.name = "Berlin"
    courses_city_4.name_en = "Berlin"
    courses_city_4.name_fr = "Berlin"
    courses_city_4.latitude_south = None
    courses_city_4.latitude_north = None
    courses_city_4.longitude_west = None
    courses_city_4.longitude_east = None
    courses_city_4.latitude_southa = None
    courses_city_4.latitude_northa = None
    courses_city_4.longitude_westa = None
    courses_city_4.longitude_easta = None
    courses_city_4.category_1 = None
    courses_city_4.category_2 = None
    courses_city_4 = importer.save_or_locate(courses_city_4)

    courses_city_5 = City()
    courses_city_5.codepostal = None
    courses_city_5.name = "Stockholm"
    courses_city_5.name_en = "Stockholm"
    courses_city_5.name_fr = "Stockholm"
    courses_city_5.latitude_south = None
    courses_city_5.latitude_north = None
    courses_city_5.longitude_west = None
    courses_city_5.longitude_east = None
    courses_city_5.latitude_southa = None
    courses_city_5.latitude_northa = None
    courses_city_5.longitude_westa = None
    courses_city_5.longitude_easta = None
    courses_city_5.category_1 = None
    courses_city_5.category_2 = None
    courses_city_5 = importer.save_or_locate(courses_city_5)

    # Processing model: opencourse.courses.models.CourseLevel

    from opencourse.courses.models import CourseLevel

    courses_courselevel_1 = CourseLevel()
    courses_courselevel_1.name = "Beginner"
    courses_courselevel_1.name_en = "Beginner"
    courses_courselevel_1.name_fr = "Débutant"
    courses_courselevel_1.description = None
    courses_courselevel_1 = importer.save_or_locate(courses_courselevel_1)

    courses_courselevel_2 = CourseLevel()
    courses_courselevel_2.name = "Intermediate"
    courses_courselevel_2.name_en = "Intermediate"
    courses_courselevel_2.name_fr = "Moyen"
    courses_courselevel_2.description = None
    courses_courselevel_2 = importer.save_or_locate(courses_courselevel_2)

    courses_courselevel_3 = CourseLevel()
    courses_courselevel_3.name = "Advanced"
    courses_courselevel_3.name_en = "Advanced"
    courses_courselevel_3.name_fr = "Avancé"
    courses_courselevel_3.description = None
    courses_courselevel_3 = importer.save_or_locate(courses_courselevel_3)

    # Processing model: opencourse.courses.models.CourseDuration

    from opencourse.courses.models import CourseDuration

    courses_courseduration_1 = CourseDuration()
    courses_courseduration_1.duration = 30
    courses_courseduration_1 = importer.save_or_locate(
        courses_courseduration_1)

    courses_courseduration_2 = CourseDuration()
    courses_courseduration_2.duration = 45
    courses_courseduration_2 = importer.save_or_locate(
        courses_courseduration_2)

    courses_courseduration_3 = CourseDuration()
    courses_courseduration_3.duration = 60
    courses_courseduration_3 = importer.save_or_locate(
        courses_courseduration_3)

    courses_courseduration_4 = CourseDuration()
    courses_courseduration_4.duration = 90
    courses_courseduration_4 = importer.save_or_locate(
        courses_courseduration_4)

    courses_courseduration_5 = CourseDuration()
    courses_courseduration_5.duration = 120
    courses_courseduration_5 = importer.save_or_locate(
        courses_courseduration_5)

    # Processing model: opencourse.courses.models.CourseAge

    from opencourse.courses.models import CourseAge

    courses_courseage_1 = CourseAge()
    courses_courseage_1.max = None
    courses_courseage_1.name = "Infants (0-3 years old)"
    courses_courseage_1.name_en = "Infants (0-3 years old)"
    courses_courseage_1.name_fr = "Nourrissons (0-3 ans)"
    courses_courseage_1 = importer.save_or_locate(courses_courseage_1)

    courses_courseage_2 = CourseAge()
    courses_courseage_2.max = None
    courses_courseage_2.name = "Preschool children (4-6 years old)"
    courses_courseage_2.name_en = "Preschool children (4-6 years old)"
    courses_courseage_2.name_fr = "Enfants d'âge préscolaire (4-6 ans)"
    courses_courseage_2 = importer.save_or_locate(courses_courseage_2)

    courses_courseage_3 = CourseAge()
    courses_courseage_3.max = None
    courses_courseage_3.name = "Children (7-12 years old)"
    courses_courseage_3.name_en = "Children (7-12 years old)"
    courses_courseage_3.name_fr = "Enfants (7-12 ans)"
    courses_courseage_3 = importer.save_or_locate(courses_courseage_3)

    courses_courseage_4 = CourseAge()
    courses_courseage_4.max = None
    courses_courseage_4.name = "Teenagers (13-17 years old)"
    courses_courseage_4.name_en = "Teenagers (13-17 years old)"
    courses_courseage_4.name_fr = "Adolescents (13-17 ans)"
    courses_courseage_4 = importer.save_or_locate(courses_courseage_4)

    courses_courseage_5 = CourseAge()
    courses_courseage_5.max = None
    courses_courseage_5.name = "Adults (18-64 years old)"
    courses_courseage_5.name_en = "Adults (18-64 years old)"
    courses_courseage_5.name_fr = "Adultes (18-64 ans)"
    courses_courseage_5 = importer.save_or_locate(courses_courseage_5)

    courses_courseage_6 = CourseAge()
    courses_courseage_6.max = None
    courses_courseage_6.name = "Seniors (65+ years old)"
    courses_courseage_6.name_en = "Seniors (65+ years old)"
    courses_courseage_6.name_fr = "Aînés (65 ans)"
    courses_courseage_6 = importer.save_or_locate(courses_courseage_6)

    # Processing model: opencourse.courses.models.CourseArea

    from opencourse.courses.models import CourseArea

    courses_coursearea_1 = CourseArea()
    courses_coursearea_1.name = "Math"
    courses_coursearea_1.name_en = "Math"
    courses_coursearea_1.name_fr = "Math"
    courses_coursearea_1.description = None
    courses_coursearea_1 = importer.save_or_locate(courses_coursearea_1)

    courses_coursearea_2 = CourseArea()
    courses_coursearea_2.name = "Physics"
    courses_coursearea_2.name_en = "Physics"
    courses_coursearea_2.name_fr = "La physique"
    courses_coursearea_2.description = None
    courses_coursearea_2 = importer.save_or_locate(courses_coursearea_2)

    courses_coursearea_3 = CourseArea()
    courses_coursearea_3.name = "Chemistry"
    courses_coursearea_3.name_en = "Chemistry"
    courses_coursearea_3.name_fr = "Chimie"
    courses_coursearea_3.description = None
    courses_coursearea_3 = importer.save_or_locate(courses_coursearea_3)

    courses_coursearea_4 = CourseArea()
    courses_coursearea_4.name = "Biology"
    courses_coursearea_4.name_en = "Biology"
    courses_coursearea_4.name_fr = "La biologie"
    courses_coursearea_4.description = None
    courses_coursearea_4 = importer.save_or_locate(courses_coursearea_4)

    # Processing model: opencourse.courses.models.CourseLanguage

    from opencourse.courses.models import CourseLanguage

    courses_courselanguage_1 = CourseLanguage()
    courses_courselanguage_1.name = "English"
    courses_courselanguage_1.name_en = "English"
    courses_courselanguage_1.name_fr = "Anglais"
    courses_courselanguage_1.tag = None
    courses_courselanguage_1 = importer.save_or_locate(
        courses_courselanguage_1)

    courses_courselanguage_2 = CourseLanguage()
    courses_courselanguage_2.name = "French"
    courses_courselanguage_2.name_en = "French"
    courses_courselanguage_2.name_fr = "Le français"
    courses_courselanguage_2.tag = None
    courses_courselanguage_2 = importer.save_or_locate(
        courses_courselanguage_2)

    courses_courselanguage_3 = CourseLanguage()
    courses_courselanguage_3.name = "Arabic"
    courses_courselanguage_3.name_en = "Arabic"
    courses_courselanguage_3.name_fr = "Arabe"
    courses_courselanguage_3.tag = None
    courses_courselanguage_3 = importer.save_or_locate(
        courses_courselanguage_3)

    courses_courselanguage_4 = CourseLanguage()
    courses_courselanguage_4.name = "Spanish"
    courses_courselanguage_4.name_en = "Spanish"
    courses_courselanguage_4.name_fr = "Espagnol"
    courses_courselanguage_4.tag = None
    courses_courselanguage_4 = importer.save_or_locate(
        courses_courselanguage_4)

    courses_courselanguage_5 = CourseLanguage()
    courses_courselanguage_5.name = "Chinese"
    courses_courselanguage_5.name_en = "Chinese"
    courses_courselanguage_5.name_fr = "Japonais"
    courses_courselanguage_5.tag = None
    courses_courselanguage_5 = importer.save_or_locate(
        courses_courselanguage_5)

    courses_courselanguage_6 = CourseLanguage()
    courses_courselanguage_6.name = "Hindi"
    courses_courselanguage_6.name_en = "Hindi"
    courses_courselanguage_6.name_fr = "Hindi"
    courses_courselanguage_6.tag = None
    courses_courselanguage_6 = importer.save_or_locate(
        courses_courselanguage_6)

    courses_courselanguage_7 = CourseLanguage()
    courses_courselanguage_7.name = "Russian"
    courses_courselanguage_7.name_en = "Russian"
    courses_courselanguage_7.name_fr = "Russe"
    courses_courselanguage_7.tag = None
    courses_courselanguage_7 = importer.save_or_locate(
        courses_courselanguage_7)

    # Processing model: opencourse.courses.models.CourseLocationType

    from opencourse.courses.models import CourseLocationType

    courses_courselocationtype_1 = CourseLocationType()
    courses_courselocationtype_1.name = "Teacher's"
    courses_courselocationtype_1.name_en = "Teacher's"
    courses_courselocationtype_1.name_fr = "Chez l'enseignant"
    courses_courselocationtype_1 = importer.save_or_locate(
        courses_courselocationtype_1)

    courses_courselocationtype_2 = CourseLocationType()
    courses_courselocationtype_2.name = "Students's"
    courses_courselocationtype_2.name_en = "Students's"
    courses_courselocationtype_2.name_fr = "Étudiant"
    courses_courselocationtype_2 = importer.save_or_locate(
        courses_courselocationtype_2)

    courses_courselocationtype_3 = CourseLocationType()
    courses_courselocationtype_3.name = "Via webcam"
    courses_courselocationtype_3.name_en = "Via webcam"
    courses_courselocationtype_3.name_fr = "Par webcam"
    courses_courselocationtype_3 = importer.save_or_locate(
        courses_courselocationtype_3)

    # Processing model: opencourse.courses.models.Currency

    from opencourse.courses.models import Currency

    courses_currency_1 = Currency()
    courses_currency_1.name = "Moroccan dirham"
    courses_currency_1.iso_code = "MAD"
    courses_currency_1.symbol = ".د.م"
    courses_currency_1 = importer.save_or_locate(courses_currency_1)

    courses_currency_2 = Currency()
    courses_currency_2.name = "US dollar"
    courses_currency_2.iso_code = "USD"
    courses_currency_2.symbol = "$"
    courses_currency_2 = importer.save_or_locate(courses_currency_2)

    courses_currency_3 = Currency()
    courses_currency_3.name = "Euro"
    courses_currency_3.iso_code = "EUR"
    courses_currency_3.symbol = "€"
    courses_currency_3 = importer.save_or_locate(courses_currency_3)

    # Processing model: opencourse.profiles.models.User

    from opencourse.profiles.models import User

    profiles_user_1 = User()
    profiles_user_1.password = (
        "pbkdf2_sha256$180000$cwXsrztq2kJE$S0uNCeGQ+FvIIi/LlodoNOIBkurUaDpFLoPpstMEetA="
    )
    profiles_user_1.last_login = dateutil.parser.parse(
        "2020-05-10T20:46:18.956512+00:00")
    profiles_user_1.is_superuser = False
    profiles_user_1.username = "******"
    profiles_user_1.first_name = ""
    profiles_user_1.last_name = ""
    profiles_user_1.email = "*****@*****.**"
    profiles_user_1.is_staff = False
    profiles_user_1.is_active = True
    profiles_user_1.date_joined = dateutil.parser.parse(
        "2020-05-10T20:19:13.787163+00:00")
    profiles_user_1 = importer.save_or_locate(profiles_user_1)

    profiles_user_2 = User()
    profiles_user_2.password = (
        "pbkdf2_sha256$180000$jQbED5mRC3FC$rGHmLPbEnbCrOGGHpIxdbpEjAWH76Dj4auzItGjxy3Y="
    )
    profiles_user_2.last_login = dateutil.parser.parse(
        "2020-05-10T20:20:06.664503+00:00")
    profiles_user_2.is_superuser = True
    profiles_user_2.username = "******"
    profiles_user_2.first_name = ""
    profiles_user_2.last_name = ""
    profiles_user_2.email = "*****@*****.**"
    profiles_user_2.is_staff = True
    profiles_user_2.is_active = True
    profiles_user_2.date_joined = dateutil.parser.parse(
        "2020-05-10T20:19:57.067332+00:00")
    profiles_user_2 = importer.save_or_locate(profiles_user_2)

    profiles_user_3 = User()
    profiles_user_3.password = (
        "pbkdf2_sha256$180000$GPo9wAK6xKK7$NERotmMpKK7hKesccmfbreFEjUBtlB+iMk1n1lR/mvc="
    )
    profiles_user_3.last_login = dateutil.parser.parse(
        "2020-05-10T20:31:45.395920+00:00")
    profiles_user_3.is_superuser = False
    profiles_user_3.username = "******"
    profiles_user_3.first_name = ""
    profiles_user_3.last_name = ""
    profiles_user_3.email = "*****@*****.**"
    profiles_user_3.is_staff = False
    profiles_user_3.is_active = True
    profiles_user_3.date_joined = dateutil.parser.parse(
        "2020-05-10T20:31:18.694372+00:00")
    profiles_user_3 = importer.save_or_locate(profiles_user_3)

    # Processing model: opencourse.profiles.models.Student

    from opencourse.profiles.models import Student

    profiles_student_1 = Student()
    profiles_student_1.slug = "studentgmailcom"
    profiles_student_1.user = profiles_user_3
    profiles_student_1.picture = ""
    profiles_student_1.email_verified = False
    profiles_student_1.first_name_ar = None
    profiles_student_1.last_name_ar = None
    profiles_student_1.address = None
    profiles_student_1.city = None
    profiles_student_1.dob = None
    profiles_student_1.edulevel = None
    profiles_student_1.tel = ""
    profiles_student_1.whatsapp = None
    profiles_student_1.email = None
    profiles_student_1.dateadd = None
    profiles_student_1.contacts_requests = 0
    profiles_student_1 = importer.save_or_locate(profiles_student_1)

    # Processing model: opencourse.profiles.models.Professor

    from opencourse.profiles.models import Professor

    profiles_professor_1 = Professor()
    profiles_professor_1.slug = "professorgmailcom"
    profiles_professor_1.user = profiles_user_1
    profiles_professor_1.picture = ""
    profiles_professor_1.email_verified = False
    profiles_professor_1.first_name_ar = None
    profiles_professor_1.last_name_ar = None
    profiles_professor_1.address = None
    profiles_professor_1.city = None
    profiles_professor_1.dob = None
    profiles_professor_1.edulevel = None
    profiles_professor_1.tel = ""
    profiles_professor_1.whatsapp = None
    profiles_professor_1.email = None
    profiles_professor_1.dateadd = None
    profiles_professor_1.contacts_requests = 0
    profiles_professor_1.bio = None
    profiles_professor_1.yearsexperience = None
    profiles_professor_1.act_position = None
    profiles_professor_1.dateexpir = None
    profiles_professor_1.listed = None
    profiles_professor_1.feespaid = None
    profiles_professor_1 = importer.save_or_locate(profiles_professor_1)

    # Processing model: opencourse.profiles.models.Review

    from opencourse.profiles.models import Review

    profiles_review_1 = Review()
    profiles_review_1.professor = profiles_professor_1
    profiles_review_1.score = 5
    profiles_review_1.text = "Крутой курс, нравится"
    profiles_review_1.content_type = ContentType.objects.get(
        app_label="profiles", model="professor")
    profiles_review_1.author_id = 1
    profiles_review_1 = importer.save_or_locate(profiles_review_1)

    profiles_review_2 = Review()
    profiles_review_2.professor = profiles_professor_1
    profiles_review_2.score = 5
    profiles_review_2.text = "Хороший курс"
    profiles_review_2.content_type = ContentType.objects.get(
        app_label="profiles", model="professor")
    profiles_review_2.author_id = 1
    profiles_review_2 = importer.save_or_locate(profiles_review_2)

    profiles_review_3 = Review()
    profiles_review_3.professor = profiles_professor_1
    profiles_review_3.score = 2
    profiles_review_3.text = "bad course!"
    profiles_review_3.content_type = ContentType.objects.get(
        app_label="profiles", model="professor")
    profiles_review_3.author_id = 1
    profiles_review_3 = importer.save_or_locate(profiles_review_3)

    # Processing model: allauth.account.models.EmailAddress

    from allauth.account.models import EmailAddress

    account_emailaddress_1 = EmailAddress()
    account_emailaddress_1.user = profiles_user_1
    account_emailaddress_1.email = "*****@*****.**"
    account_emailaddress_1.verified = True
    account_emailaddress_1.primary = True
    account_emailaddress_1 = importer.save_or_locate(account_emailaddress_1)

    account_emailaddress_2 = EmailAddress()
    account_emailaddress_2.user = profiles_user_3
    account_emailaddress_2.email = "*****@*****.**"
    account_emailaddress_2.verified = True
    account_emailaddress_2.primary = True
    account_emailaddress_2 = importer.save_or_locate(account_emailaddress_2)

    # Processing model: opencourse.courses.models.Course

    from opencourse.courses.models import Course

    courses_course_1 = Course()
    courses_course_1.slug = "algebra-for-beginners"
    courses_course_1.professor = profiles_professor_1
    courses_course_1.city = courses_city_1
    courses_course_1.title = "Algebra for beginners"
    courses_course_1.title_ar = None
    courses_course_1.descrip = "Good course"
    courses_course_1.extrainfo = None
    courses_course_1.payactive = None
    courses_course_1.active = None
    courses_course_1.dateexp = None
    courses_course_1.starthostdate = None
    courses_course_1.endhostdate = None
    courses_course_1.hosted = None
    courses_course_1.hostactive = None
    courses_course_1.level = courses_courselevel_1
    courses_course_1.duration = courses_courseduration_1
    courses_course_1 = importer.save_or_locate(courses_course_1)

    courses_course_1.age.add(courses_courseage_1)
    courses_course_1.area.add(courses_coursearea_1)
    courses_course_1.language.add(courses_courselanguage_1)

    courses_course_2 = Course()
    courses_course_2.slug = "course"
    courses_course_2.professor = profiles_professor_1
    courses_course_2.city = courses_city_2
    courses_course_2.title = "Термодинамика"
    courses_course_2.title_ar = None
    courses_course_2.descrip = "Лучший курс."
    courses_course_2.extrainfo = None
    courses_course_2.payactive = None
    courses_course_2.active = None
    courses_course_2.dateexp = None
    courses_course_2.starthostdate = None
    courses_course_2.endhostdate = None
    courses_course_2.hosted = None
    courses_course_2.hostactive = None
    courses_course_2.level = courses_courselevel_1
    courses_course_2.duration = courses_courseduration_1
    courses_course_2 = importer.save_or_locate(courses_course_2)

    courses_course_2.age.add(courses_courseage_1)
    courses_course_2.area.add(courses_coursearea_2)
    courses_course_2.language.add(courses_courselanguage_7)

    # Processing model: opencourse.courses.models.CourseLocation

    from opencourse.courses.models import CourseLocation

    courses_courselocation_1 = CourseLocation()
    courses_courselocation_1.location_type = courses_courselocationtype_1
    courses_courselocation_1.course = courses_course_1
    courses_courselocation_1.description = None
    courses_courselocation_1.price = 1
    courses_courselocation_1.currency = courses_currency_1
    courses_courselocation_1.number_sessions = None
    courses_courselocation_1.coursestartdate = None
    courses_courselocation_1.courseenddate = None
    courses_courselocation_1 = importer.save_or_locate(
        courses_courselocation_1)

    courses_courselocation_2 = CourseLocation()
    courses_courselocation_2.location_type = courses_courselocationtype_1
    courses_courselocation_2.course = courses_course_2
    courses_courselocation_2.description = None
    courses_courselocation_2.price = 1
    courses_courselocation_2.currency = courses_currency_2
    courses_courselocation_2.number_sessions = None
    courses_courselocation_2.coursestartdate = None
    courses_courselocation_2.courseenddate = None
    courses_courselocation_2 = importer.save_or_locate(
        courses_courselocation_2)

    # Processing model: django.contrib.auth.models.Group

    from django.contrib.auth.models import Group
    from django.contrib.auth.models import Permission

    professor_permission = Permission.objects.get(
        codename="access_professor_pages")
    students_permission = Permission.objects.get(
        codename="access_student_pages")

    auth_group_1 = Group()
    auth_group_1.name = "Students"
    auth_group_1 = importer.save_or_locate(auth_group_1)

    auth_group_1.permissions.add(students_permission)

    auth_group_2 = Group()
    auth_group_2.name = "Professors"
    auth_group_2 = importer.save_or_locate(auth_group_2)

    auth_group_2.permissions.add(professor_permission)
    auth_group_2.permissions.add(students_permission)

    # Re-processing model: opencourse.profiles.models.User

    profiles_user_1.groups.add(auth_group_2)
    profiles_user_3.groups.add(auth_group_1)
Ejemplo n.º 11
0
        nominations[row[0]].append(row[1])

print(nominations)

with open('members.csv') as csvfile:
    member_csv = csv.reader(csvfile)
    for row in member_csv:
        if row[5] == "*****@*****.**":
            user = User.objects.get(email='*****@*****.**')
        else:
            user = User()
            user.email = row[5]
            user.save()

        email = EmailAddress()
        email.user = user
        email.email = row[5]
        email.verified = True
        email.save()

        address = Address()
        address.user = user
        address.street = row[8]
        address.unit = row[9]
        address.city = row[10]
        address.state = row[11]
        address.postal_code = row[12]
        address.phone_number = row[13]
        address.save()

        member = Member()
Ejemplo n.º 12
0
    def test_update_email(self):
        user = JobSeekerFactory()
        old_email = user.email
        new_email = "*****@*****.**"

        self.client.login(username=user.email, password=DEFAULT_PASSWORD)
        url = reverse("dashboard:edit_user_email")
        response = self.client.get(url)

        email_address = EmailAddress(email=old_email,
                                     verified=True,
                                     primary=True)
        email_address.user = user
        email_address.save()

        post_data = {"email": new_email, "email_confirmation": new_email}
        response = self.client.post(url, data=post_data)
        self.assertEqual(response.status_code, 302)

        # User is logged out
        user.refresh_from_db()
        self.assertEqual(response.request.get("user"), None)
        self.assertEqual(user.email, new_email)
        self.assertEqual(user.emailaddress_set.count(), 0)

        # User cannot log in with his old address
        post_data = {"login": old_email, "password": DEFAULT_PASSWORD}
        url = reverse("account_login")
        response = self.client.post(url, data=post_data)
        self.assertEqual(response.status_code, 200)
        self.assertFalse(response.context_data["form"].is_valid())

        # User cannot log in until confirmation
        post_data = {"login": new_email, "password": DEFAULT_PASSWORD}
        url = reverse("account_login")
        response = self.client.post(url, data=post_data)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.url,
                         reverse("account_email_verification_sent"))

        # User receives an email to confirm his new address.
        email = mail.outbox[0]
        self.assertIn("Confirmez votre adresse e-mail", email.subject)
        self.assertIn(
            "Afin de finaliser votre inscription, cliquez sur le lien suivant",
            email.body)
        self.assertEqual(email.to[0], new_email)

        # Confirm email + auto login.
        confirmation_token = EmailConfirmationHMAC(
            user.emailaddress_set.first()).key
        confirm_email_url = reverse("account_confirm_email",
                                    kwargs={"key": confirmation_token})
        response = self.client.post(confirm_email_url)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.url, reverse("account_login"))

        post_data = {"login": user.email, "password": DEFAULT_PASSWORD}
        url = reverse("account_login")
        response = self.client.post(url, data=post_data)
        self.assertTrue(response.context.get("user").is_authenticated)

        user.refresh_from_db()
        self.assertEqual(user.email, new_email)
        self.assertEqual(user.emailaddress_set.count(), 1)
        new_address = user.emailaddress_set.first()
        self.assertEqual(new_address.email, new_email)
        self.assertTrue(new_address.verified)