Beispiel #1
0
    def get(self, request, username, activation_key, *args, **kwargs):
        if request.user.is_authenticated():
            return redirect("forums")

        # Decoding username
        username = base64.b64decode(username.encode("utf-8")).decode("ascii")
        # Parameters for template
        data = {'username': username}

        # Get model profile
        ModelProfile = utils.get_main_model_profile()

        # Check if not expired key
        user_profile = get_object_or_404(ModelProfile,
                                         activation_key=activation_key)

        if user_profile.key_expires < timezone.now():
            return render(request, "musette/confirm_email_expired.html", data)

        # Active user
        User = get_user_model()
        user = get_object_or_404(User, username=username)
        user.is_active = True
        user.save()
        return render(request, self.template_name, data)
Beispiel #2
0
 class Meta:
     model = utils.get_main_model_profile()
     exclude = (
         'idprofile',
         'iduser',
     )
     widgets = {
         'about': widgets.TextareaWidget,
     }
Beispiel #3
0
    def post(self, request, username, *args, **kwargs):

        ModelProfile = utils.get_main_model_profile()
        profile = get_object_or_404(ModelProfile, iduser=request.user.id)

        file_name = profile.photo

        form = forms.FormEditProfile(request.POST,
                                     request.FILES,
                                     instance=profile)
        file_path = settings.MEDIA_ROOT

        if form.is_valid():

            obj = form.save(commit=False)
            about = request.POST['about']
            obj.about = about

            # If check field clear, remove file when update
            if 'attachment-clear' in request.POST:
                route_file = utils.get_route_file(file_path, file_name.name)

                try:
                    utils.remove_file(route_file)
                except Exception:
                    pass

            if 'attachment' in request.FILES:

                if not obj.id_attachment:
                    id_attachment = get_random_string(length=32)
                    obj.id_attachment = id_attachment

                file_name_post = request.FILES['photo']
                obj.photo = file_name_post

                # Route previous file
                route_file = utils.get_route_file(file_path, file_name.name)

                try:
                    # If a previous file exists it removed
                    utils.remove_file(route_file)
                except Exception:
                    pass

            # Update profile
            form.save()

            messages.success(request,
                             _("Your profile was successfully edited"))
            return self.form_valid(form, **kwargs)
        else:
            messages.error(request, _("Invalid form"))
            return self.form_invalid(form, **kwargs)
Beispiel #4
0
    def get(self, request, username, *args, **kwargs):

        ModelProfile = utils.get_main_model_profile()
        profile = get_object_or_404(ModelProfile, iduser=request.user.id)

        # Init fields form
        form = forms.FormEditProfile(instance=profile)

        data = {'form': form}

        return render(request, self.template_name, data)
Beispiel #5
0
 class Meta:
     model = utils.get_main_model_profile()
     exclude = (
         'idprofile',
         'iduser',
         'activation_key',
         'key_expires',
         'is_troll',
     )
     widgets = {
         'about': widgets.TextareaWidget,
         'photo': widgets.CustomClearableFileInput,
     }
Beispiel #6
0
    def post(self, request, *args, **kwargs):
        user_post = request.POST.get('username')
        check = True if int(request.POST.get('check')) == 1 else False

        # Get troll
        User = get_user_model()
        username = get_object_or_404(User, username=user_post)

        # Check if is user correct
        total = utils.get_total_forum_moderate_user(username)
        if not username.is_superuser and total == 0:
            # Is a troll
            ModelProfile = utils.get_main_model_profile()
            ModelProfile.objects.filter(iduser=username).update(is_troll=check)

        return redirect("profile", username=user_post)
Beispiel #7
0
    def get(self, request, username, *args, **kwargs):
        template_name = "musette/profile.html"

        # Get user param
        User = get_user_model()
        user = get_object_or_404(User, username=username)
        iduser = user.id

        # Get model extend Profile
        ModelProfile = utils.get_main_model_profile()

        # Get name app of the extend model Profile
        app = utils.get_app_model(ModelProfile)

        # Check if the model profile is extended
        count_fields_model = utils.get_count_fields_model(ModelProfile)
        count_fields_abstract = utils.get_count_fields_model(
            models.AbstractProfile)
        if count_fields_model > count_fields_abstract:
            model_profile_is_extend = True
        else:
            model_profile_is_extend = False
        profile = get_object_or_404(ModelProfile, iduser=iduser)

        photo = utils.get_photo_profile(iduser)

        # Get last topic of the profile
        topics = models.Topic.objects.filter(user=user)[:5]

        data = {
            'profile': profile,
            'photo': photo,
            'user': request.user,
            'topics': topics,
            'app': app,
            'model_profile_is_extend': model_profile_is_extend
        }

        return render(request, template_name, data)
Beispiel #8
0
    def handle(self, *args, **options):
        # Get model profile
        Profile = get_main_model_profile()
        # Get users super-admin
        User = get_user_model()
        users = User.objects.filter(is_superuser=True)

        # Create recrod profile
        if users.count() > 0:
            for user in users:
                if not Profile.objects.filter(iduser=user).exists():
                    data = get_data_confirm_email(user.email)
                    Profile.objects.create(
                        iduser=user,
                        photo="",
                        about="",
                        activation_key=data['activation_key'],
                        key_expires=data['key_expires'])
                    self.stdout.write('Profile created: ' + user.username)
                else:
                    self.stdout.write('Profile ' + user.username + ' exists.')
            self.stdout.write("Finished.")
        else:
            self.stdout.write("There is no super-user registered.")
Beispiel #9
0
    def post(self, request, username, *args, **kwargs):
        if request.user.is_authenticated():
            return redirect("forums")

        User = get_user_model()
        user = get_object_or_404(User, username=username)
        email = user.email

        # For confirm email
        data = utils.get_data_confirm_email(email)

        # Get model profile
        ModelProfile = utils.get_main_model_profile()

        # Update activation key
        profile = get_object_or_404(ModelProfile, iduser=user)
        profile.activation_key = data['activation_key']
        profile.key_expires = data['key_expires']
        profile.save()

        # Send email for confirm user
        utils.send_welcome_email(email, username, data['activation_key'])
        data = {'username': username, 'new_key': True}
        return render(request, self.template_name, data)
Beispiel #10
0
class ProfileViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = utils.get_main_model_profile().objects.all()
    serializer_class = serializers.ProfileSerializer
Beispiel #11
0
class ProfileInline(admin.StackedInline):
    model = utils.get_main_model_profile()
    can_delete = False
    verbose_name_plural = _('Profile')
    fk_name = 'iduser'
    form = forms.FormAdminProfile
 class Meta:
     model = utils.get_main_model_profile()
     fields = '__all__'