Saturday, January 28, 2023

Re: Django microservice authentication problem.

Are you trying to authenticate via Django Rest FrameWork API or via the standard Django authentication system?  It shouldn't really matter which it is as both can be scaled horizontally and you'll have no issue with authenticating so in order for us to help we'd need to understand what you are doing better.

For example are you trying to share the database across multiple domains? Are you simply placing multiple servers behind a load balancer on the same domain?

On Saturday, 28 January 2023 at 06:53:12 UTC mdanar...@gmail.com wrote:
How to communicate and authenticate with multiple Django servers. Is it possible?

If possible you can help me, I am trying more than 15 days in this section but not getting any solution.

Please share with me any requirements like books, videos, blogs, or code examples.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/16326b9e-0656-45b4-b975-faf9b676a559n%40googlegroups.com.

Thursday, January 26, 2023

Object Level Access Rules

Hello,

We need some of Access Control on an object basis, so that the user and
his groups determines which objects he can see.

It is not practical to define this on the individual objects, but
instead generic access rules should be used.
For example User Group UA is only allowed to see products of the groups
GA1 and GA2. (where product groups is a field of the model)

In an essence we would need something like Row Level Security in
Postgresql [1] but within the django orm, since we do not want to
replicate all django users / groups into the database

[1] https://www.postgresql.org/docs/15/ddl-rowsecurity.html

I have seen django-guardian and django-rules and others but they seem to
build an the Django standard Object Level Permission interface, which is
located on the presentation layer instead of the database layer.
This is fine for altering the GUI but can be dangerous if checks in the
view / template are forgotten. Also those checks have to be redundant
in the API views.

Is there something like this I did not find?

If not, I am thinking about creating an app that introduces an Objects
Manager that requires the user in the get_queryset method and applies
filters accordingly to the rules for the user.

Thoughts on that?

Thanks.

--
Greg

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20230127074915.6227f5cc%40florenz.

Re: Custom user model password is not hashed


Did you try make_password before saving data from registration form ? 

On Wed, 25 Jan 2023 at 18:36, Roger Mukai <mukaiguy@gmail.com> wrote:
@Tejas or @Sebs, do you still have a question how to do this? I think I figured it out

On Tuesday, December 6, 2022 at 7:25:08 PM UTC-5 sebs...@gmail.com wrote:
Hey Ben, please help with the repo for the same code. I'm getting same error here.

On Saturday, 7 May 2022 at 22:37:32 UTC Tejas Agrawal wrote:
Hey Benjamin, can you please share your github repo for the same code. I'm also getting the same error in one of my project, can't figure out how to solve it.

On Friday, November 13, 2015 at 6:11:09 PM UTC+5:30 benjamin...@gmail.com wrote:
The problem was, when creating a custom user, one has to define a custom model form and model admin that handles the password properly. After that it was solved.

Thank you.

On Thu, Nov 12, 2015 at 9:25 PM, Andreas Kuhne <andrea...@suitopia.com> wrote:
Try to debug and check what your password value is after the set_password() statement.  Also have you checked the database after trying to create a user with the new method? It should be hashed in the database. This is stuff that should "just work" in django (it's regulated by the AbstractBaseUser and is the same that I am using in a project).

You did restart the django shell after changing the code?

2015-11-12 16:44 GMT+01:00 Benjamin Smith <benjamin...@gmail.com>:
I have changed user.set_password(self.cleaned_data["password"]) to user.set_password(password). But I am getting the same result.

On Thu, Nov 12, 2015 at 8:57 PM, Andreas Kuhne <andrea...@suitopia.com> wrote:
As aRkadeFR says, you seam to have mixed code there....

The row:
user.set_password(self.cleaned_data["password"])

is taken from a form somewhere and won't work. It should instead be :
user.set_password(password)

I suppose the password is going through to the create method via the kwargs argument at the end of you create method. But if you change like I said, everything should work.


Med vänliga hälsningar,

Andréas Kühne
Software Development Manager
Suitopia Scandinavia AB

2015-11-12 16:20 GMT+01:00 aRkadeFR <con...@arkade.info>:
Hello,

I don't quite get the code in your method: 'MyUserManager.create_user':
        user.set_password(self.cleaned_data["password"])

You're in your Manager method but call self.cleaned_data ?

You can set a breakpoint inside your method with pdb to see
what's going on with your fields?


On 11/12/2015 04:11 PM, Benjamin Smith wrote:
I have my own custom User model, and its own Manger too.

Models:

class MyUser(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(max_length=255, unique=True)
    first_name = models.CharField(max_length=35)
    last_name = models.CharField(max_length=35)
    username = models.CharField(max_length=70, unique=True)
    date_of_birth = models.DateField()
    is_active = models.BooleanField(default=True)
    is_admin = models.BooleanField(default=False)

    @property
    def is_staff(self):
        return self.is_admin

    def get_full_name(self):
        return ('%s %s') % (self.first_name, self.last_name)

    def get_short_name(self):
        return self.username

    objects = MyUserManager()
    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['first_name', 'last_name', 'username', 'date_of_birth']

Manager:

class MyUserManager(BaseUserManager):
    def create_user(self, email, first_name, last_name, username, date_of_birth, password=None, **kwargs):
        if not email:
            raise ValueError('User must have an email address')

        user = self.model(
            email=self.normalize_email(email),
            first_name=first_name,
            last_name=last_name,
            username=username,
            date_of_birth=date_of_birth,
            **kwargs
        )
        user.set_password(self.cleaned_data["password"])
        user.save(using=self._db)
        return user

    def create_superuser(self, email, first_name, last_name, username, date_of_birth, password, **kwargs):
        user = self.create_user(
            email,
            first_name=first_name,
            last_name=last_name,
            username=username,
            date_of_birth=date_of_birth,
            password=password,
            is_superuser=True,
            **kwargs
        )
        user.is_admin = True
        user.save(using=self._db)
        return user

Everything works when creating a new user without any errors. But when I try to login I can't. So I checked the user's email and password to confirm. Then I noticed that the password is displayed as plain text (eg. strongpassword), and when changed the admin form to get the hashed password using ReadOnlyPasswordHashField() I get an error inside the password field, even though I used set_password() for the Manger inside the create_user() function.

Invalid password format or unknown hashing algorithm

However, if I manually do set_password('strongpassword') for that user inside the console, then only the password is hashed. Could you please help me solve this problem. Thank you.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAM4YLWJNGdSj-rVAuhta_UA50Cjna8zg-c14FPxK%3DtdU49mngQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--   aRkadeFR

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5644AE3A.5050609%40arkade.info.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALXYUb%3D-V1fqJLJSbUaPUWaYX6srAf9s0qnZ0ZrTZOv9757o2w%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAM4YLWJ3tgcBSe_VcH6T6t4UbbA4EqTB0R0TueL2BjidZow7xg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8e7272bd-ef57-4817-9ceb-3956e0f7915bn%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAP4VW2UGcptss8RXzQcuirOE7JdPxccKDC69bSCyVoc_4%3DBV1g%40mail.gmail.com.

Re: Custom user model password is not hashed

Yup, 100% correct. Glad to hear you fixed it. Custom user models that inherit from the abstractbaseuser class can be a little tricky at first.

On Friday, November 13, 2015 at 5:41:09 AM UTC-7 benjamin...@gmail.com wrote:
The problem was, when creating a custom user, one has to define a custom model form and model admin that handles the password properly. After that it was solved.

Thank you.

On Thu, Nov 12, 2015 at 9:25 PM, Andreas Kuhne <andrea...@suitopia.com> wrote:
Try to debug and check what your password value is after the set_password() statement.  Also have you checked the database after trying to create a user with the new method? It should be hashed in the database. This is stuff that should "just work" in django (it's regulated by the AbstractBaseUser and is the same that I am using in a project).

You did restart the django shell after changing the code?

2015-11-12 16:44 GMT+01:00 Benjamin Smith <benjamin...@gmail.com>:
I have changed user.set_password(self.cleaned_data["password"]) to user.set_password(password). But I am getting the same result.

On Thu, Nov 12, 2015 at 8:57 PM, Andreas Kuhne <andrea...@suitopia.com> wrote:
As aRkadeFR says, you seam to have mixed code there....

The row:
user.set_password(self.cleaned_data["password"])

is taken from a form somewhere and won't work. It should instead be :
user.set_password(password)

I suppose the password is going through to the create method via the kwargs argument at the end of you create method. But if you change like I said, everything should work.


Med vänliga hälsningar,

Andréas Kühne
Software Development Manager
Suitopia Scandinavia AB

2015-11-12 16:20 GMT+01:00 aRkadeFR <con...@arkade.info>:
Hello,

I don't quite get the code in your method: 'MyUserManager.create_user':
        user.set_password(self.cleaned_data["password"])

You're in your Manager method but call self.cleaned_data ?

You can set a breakpoint inside your method with pdb to see
what's going on with your fields?


On 11/12/2015 04:11 PM, Benjamin Smith wrote:
I have my own custom User model, and its own Manger too.

Models:

class MyUser(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(max_length=255, unique=True)
    first_name = models.CharField(max_length=35)
    last_name = models.CharField(max_length=35)
    username = models.CharField(max_length=70, unique=True)
    date_of_birth = models.DateField()
    is_active = models.BooleanField(default=True)
    is_admin = models.BooleanField(default=False)

    @property
    def is_staff(self):
        return self.is_admin

    def get_full_name(self):
        return ('%s %s') % (self.first_name, self.last_name)

    def get_short_name(self):
        return self.username

    objects = MyUserManager()
    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['first_name', 'last_name', 'username', 'date_of_birth']

Manager:

class MyUserManager(BaseUserManager):
    def create_user(self, email, first_name, last_name, username, date_of_birth, password=None, **kwargs):
        if not email:
            raise ValueError('User must have an email address')

        user = self.model(
            email=self.normalize_email(email),
            first_name=first_name,
            last_name=last_name,
            username=username,
            date_of_birth=date_of_birth,
            **kwargs
        )
        user.set_password(self.cleaned_data["password"])
        user.save(using=self._db)
        return user

    def create_superuser(self, email, first_name, last_name, username, date_of_birth, password, **kwargs):
        user = self.create_user(
            email,
            first_name=first_name,
            last_name=last_name,
            username=username,
            date_of_birth=date_of_birth,
            password=password,
            is_superuser=True,
            **kwargs
        )
        user.is_admin = True
        user.save(using=self._db)
        return user

Everything works when creating a new user without any errors. But when I try to login I can't. So I checked the user's email and password to confirm. Then I noticed that the password is displayed as plain text (eg. strongpassword), and when changed the admin form to get the hashed password using ReadOnlyPasswordHashField() I get an error inside the password field, even though I used set_password() for the Manger inside the create_user() function.

Invalid password format or unknown hashing algorithm

However, if I manually do set_password('strongpassword') for that user inside the console, then only the password is hashed. Could you please help me solve this problem. Thank you.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAM4YLWJNGdSj-rVAuhta_UA50Cjna8zg-c14FPxK%3DtdU49mngQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--   aRkadeFR

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5644AE3A.5050609%40arkade.info.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALXYUb%3D-V1fqJLJSbUaPUWaYX6srAf9s0qnZ0ZrTZOv9757o2w%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAM4YLWJ3tgcBSe_VcH6T6t4UbbA4EqTB0R0TueL2BjidZow7xg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b6b0b579-0a84-4bec-bfe7-fee3caaeef7en%40googlegroups.com.

Tuesday, January 24, 2023

Re: Email Sending In Django not working

guys use this code for sending emails, it's working as of now
import smtplib

my_email = "someone@gmail.com"
password = "sfuyyudfgyudgfydsg"

with smtplib.SMTP('smtp.gmail.com') as connection:
connection.starttls()
connection.login(user=my_email, password=password)
connection.sendmail(
from_addr=my_email,
to_addrs="samaniabdussalam02@gmail.com",
msg="Subject: Checking out automated mail in Python\n\nI don't
know what error I will get, there is only one way to find out.."
)

On Mon, Nov 14, 2022 at 6:13 PM Lakshyaraj Dash
<dashlakshyaraj2006@gmail.com> wrote:
>
> The app name can be any name
>
> On Mon, Nov 14, 2022, 18:11 peterumimo2 <peterumimo2@gmail.com> wrote:
>>
>> I have watched the video please the app name must be any name or your project name
>>
>>
>>
>> Sent from my Samsung Galaxy smartphone.
>>
>> -------- Original message --------
>> From: Lakshyaraj Dash <dashlakshyaraj2006@gmail.com>
>> Date: 14/11/2022 13:16 (GMT+01:00)
>> To: django-users@googlegroups.com
>> Subject: Re: Email Sending In Django not working
>>
>> Please watch this video and ensure that you've properly configured the port numbers also your email address and password.
>> Note: Your email password should be the app password generated no your actual Gmail password
>>
>> https://youtu.be/uVDq4VOBMNM
>>
>> On Mon, Nov 14, 2022, 17:41 peteru mimo <peterumimo2@gmail.com> wrote:
>>>
>>> I have done all this still not working
>>>
>>> On Wednesday, November 9, 2022 at 4:34:49 PM UTC+1 dashlaksh...@gmail.com wrote:
>>>>
>>>> Even if Google has stopped the support, emails can be still sent using two step verification and generating app passwords after enabling two step verification. Please update you email password with the generated app password.
>>>>
>>>> Steps:
>>>> 1. Go to manage my Google account
>>>> 2. Go to security tab
>>>> 3. Enable two step verification and verify yourself
>>>> 4. Create your app passwords after the app passwords in the security settings is visible
>>>> 5. Select the app name (or add your custom app name) and click generate.
>>>> 6. Copy the app password as it's view once and cannot be viewed after the pop up is closed.
>>>> 7. Go to your settings.py file and replace your actual email password with the generated app password.
>>>>
>>>> Yay! You're all set.
>>>>
>>>> Dear It's Alladin, please try this also to the one who asked this question please try it once.
>>>>
>>>> Thanks and Regards
>>>> Lakshyaraj Dash
>>>> On Wed, Nov 9, 2022, 20:57 It's Aladdin <iamala...@gmail.com> wrote:
>>>>>
>>>>> Google hast stopped less secure apps, so u cant send email messages anymore with ur email and password, U will have to find some other way of sending mails.
>>>>>
>>>>> On Wed, 9 Nov, 2022, 16:26 peteru mimo, <peter...@gmail.com> wrote:
>>>>>>
>>>>>> Good day team,
>>>>>>
>>>>>> I have been facing this challenge in sending mail in django
>>>>>>
>>>>>> here is the error "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond"
>>>>>>
>>>>>> Code
>>>>>> def send_verification_email(request, user):
>>>>>> from_email = settings.DEFAULT_FROM_EMAIL
>>>>>> current_site = get_current_site(request)
>>>>>> mail_subject = 'Please activate your account'
>>>>>> message = render_to_string('accounts/emails/account_verification_email.html', {
>>>>>> 'user': user,
>>>>>> 'domain': current_site,
>>>>>> 'uid': urlsafe_base64_encode(force_bytes(user.pk)),
>>>>>> 'token': default_token_generator.make_token(user),
>>>>>> })
>>>>>> to_email = user.email
>>>>>> mail = EmailMessage(mail_subject, from_email, message, to=[to_email])
>>>>>> mail.send()
>>>>>>
>>>>>> Settings
>>>>>> EMAIL_HOST = 'smtp.google.com'
>>>>>> EMAIL_POST = '587'
>>>>>> EMAIL_HOST_USER = 'myemail'
>>>>>> EMAIL_HOST_PASSWORD = 'email_password'
>>>>>> EMAIL_USE_TLS = True
>>>>>>
>>>>>> Any solution will be appreciated. Thank you
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google Groups "Django users" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
>>>>>> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1ed5b9fc-3370-413c-b4cb-edeb2451d8f4n%40googlegroups.com.
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google Groups "Django users" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
>>>>>
>>>>> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAA5HNVoRdTC2BBZ2FEk1ETaqxfL5xKQgfBuAcbFdPES_bSRYmQ%40mail.gmail.com.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
>>> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e0ee8cb9-cc9a-47b7-9c99-71a3f1bdf0efn%40googlegroups.com.
>>
>> --
>> You received this message because you are subscribed to the Google Groups "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAF7qQgDc-3NCW0xdUaUEn%2BzgJ9TxKsV%3DjTAsk55wicoDpCqTAw%40mail.gmail.com.
>>
>> --
>> You received this message because you are subscribed to the Google Groups "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/63723757.5d0a0220.a3a9b.390e%40mx.google.com.
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAF7qQgCogwDfQd%2BzfQEJXqKyqg3g9SHar%2B%2BmqyPrYLmvswxTdA%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAA5HNVorhMEciiX2xo3958KHR2W1BsTh%2BPP93-dVPqaqXjUASQ%40mail.gmail.com.

Re: Custom user model password is not hashed

@Tejas or @Sebs, do you still have a question how to do this? I think I figured it out

On Tuesday, December 6, 2022 at 7:25:08 PM UTC-5 sebs...@gmail.com wrote:
Hey Ben, please help with the repo for the same code. I'm getting same error here.

On Saturday, 7 May 2022 at 22:37:32 UTC Tejas Agrawal wrote:
Hey Benjamin, can you please share your github repo for the same code. I'm also getting the same error in one of my project, can't figure out how to solve it.

On Friday, November 13, 2015 at 6:11:09 PM UTC+5:30 benjamin...@gmail.com wrote:
The problem was, when creating a custom user, one has to define a custom model form and model admin that handles the password properly. After that it was solved.

Thank you.

On Thu, Nov 12, 2015 at 9:25 PM, Andreas Kuhne <andrea...@suitopia.com> wrote:
Try to debug and check what your password value is after the set_password() statement.  Also have you checked the database after trying to create a user with the new method? It should be hashed in the database. This is stuff that should "just work" in django (it's regulated by the AbstractBaseUser and is the same that I am using in a project).

You did restart the django shell after changing the code?

2015-11-12 16:44 GMT+01:00 Benjamin Smith <benjamin...@gmail.com>:
I have changed user.set_password(self.cleaned_data["password"]) to user.set_password(password). But I am getting the same result.

On Thu, Nov 12, 2015 at 8:57 PM, Andreas Kuhne <andrea...@suitopia.com> wrote:
As aRkadeFR says, you seam to have mixed code there....

The row:
user.set_password(self.cleaned_data["password"])

is taken from a form somewhere and won't work. It should instead be :
user.set_password(password)

I suppose the password is going through to the create method via the kwargs argument at the end of you create method. But if you change like I said, everything should work.


Med vänliga hälsningar,

Andréas Kühne
Software Development Manager
Suitopia Scandinavia AB

2015-11-12 16:20 GMT+01:00 aRkadeFR <con...@arkade.info>:
Hello,

I don't quite get the code in your method: 'MyUserManager.create_user':
        user.set_password(self.cleaned_data["password"])

You're in your Manager method but call self.cleaned_data ?

You can set a breakpoint inside your method with pdb to see
what's going on with your fields?


On 11/12/2015 04:11 PM, Benjamin Smith wrote:
I have my own custom User model, and its own Manger too.

Models:

class MyUser(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(max_length=255, unique=True)
    first_name = models.CharField(max_length=35)
    last_name = models.CharField(max_length=35)
    username = models.CharField(max_length=70, unique=True)
    date_of_birth = models.DateField()
    is_active = models.BooleanField(default=True)
    is_admin = models.BooleanField(default=False)

    @property
    def is_staff(self):
        return self.is_admin

    def get_full_name(self):
        return ('%s %s') % (self.first_name, self.last_name)

    def get_short_name(self):
        return self.username

    objects = MyUserManager()
    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['first_name', 'last_name', 'username', 'date_of_birth']

Manager:

class MyUserManager(BaseUserManager):
    def create_user(self, email, first_name, last_name, username, date_of_birth, password=None, **kwargs):
        if not email:
            raise ValueError('User must have an email address')

        user = self.model(
            email=self.normalize_email(email),
            first_name=first_name,
            last_name=last_name,
            username=username,
            date_of_birth=date_of_birth,
            **kwargs
        )
        user.set_password(self.cleaned_data["password"])
        user.save(using=self._db)
        return user

    def create_superuser(self, email, first_name, last_name, username, date_of_birth, password, **kwargs):
        user = self.create_user(
            email,
            first_name=first_name,
            last_name=last_name,
            username=username,
            date_of_birth=date_of_birth,
            password=password,
            is_superuser=True,
            **kwargs
        )
        user.is_admin = True
        user.save(using=self._db)
        return user

Everything works when creating a new user without any errors. But when I try to login I can't. So I checked the user's email and password to confirm. Then I noticed that the password is displayed as plain text (eg. strongpassword), and when changed the admin form to get the hashed password using ReadOnlyPasswordHashField() I get an error inside the password field, even though I used set_password() for the Manger inside the create_user() function.

Invalid password format or unknown hashing algorithm

However, if I manually do set_password('strongpassword') for that user inside the console, then only the password is hashed. Could you please help me solve this problem. Thank you.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAM4YLWJNGdSj-rVAuhta_UA50Cjna8zg-c14FPxK%3DtdU49mngQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--   aRkadeFR

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5644AE3A.5050609%40arkade.info.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALXYUb%3D-V1fqJLJSbUaPUWaYX6srAf9s0qnZ0ZrTZOv9757o2w%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAM4YLWJ3tgcBSe_VcH6T6t4UbbA4EqTB0R0TueL2BjidZow7xg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8e7272bd-ef57-4817-9ceb-3956e0f7915bn%40googlegroups.com.

Monday, January 23, 2023

Re: how can i solve this error?

-----BEGIN PGP PUBLIC KEY BLOCK-----

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
BHO6KilQ+QLzSektD8IpHM7tR6P+5PP6AQ==
=NePe
-----END PGP PUBLIC KEY BLOCK-----
On 23/01/2023 18.20, Vanessa kabanyana wrote:
> ModuleNotFoundError: No module named 'agriApp.apps.agriAppConfig';
> 'agriApp.apps' is not a package
>

Since you're the only one who knows what caused that error, you're also
the only one who can solve it.

If you want someone else to help you consider taking the time to write
an actual question instead.

Kind regards,
Kasper Laudrup

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/96568578-f0de-81ca-3d93-6f829f1e438a%40stacktrace.dk.

Re: Casesentives in models in django

Show your code

On January 22, 2023 5:57:07 AM CST, Hi ND <hind.hbashneh@gmail.com> wrote:

I tried to put this code to deactivate the sensitivity of the characters when logging in, but it does not work. What is the problem with it? It still appears to me. Please consider the sensitivity of the characters

I want to use this method. I do not want to use the backend method Please help me find the problem


Re: MySQL table is missing ON DELETE CASCADE constraint

Thanks for the answers. Still not sure why it would not implement ON DELETE CASCADE in the DB itself. But whatever.

Regards,
Dennis

On 20/01/2023 20:15, Jason wrote:
https://docs.djangoproject.com/en/4.1/ref/models/fields/#django.db.models.CASCADE

> Django emulates the behavior of the SQL constraint ON DELETE CASCADE and also deletes the object containing the ForeignKey.

this is specified in the docs.  

https://code.djangoproject.com/ticket/21961
On Friday, January 20, 2023 at 10:44:48 AM UTC-5 bhuvn...@gmail.com wrote:
Hi dennis,
You can open a ticket on the trac (https://code.djangoproject.com/query) for whatever issue you are facing.It will be easier to understand there.

Regards
Bhuvnesh 


On Fri, Jan 20, 2023, 8:36 PM Dennis Tants <ta...@uni-bremen.de> wrote:
Hey folks,

I recently came across what I think is a bug. Let me try to explain it as detailed as possible.
Imagine I have two models, one is called Events, the other is called EventAccounts. EventAccounts can't exist without an Event, so I added a ForeignKey with the on_delete=models.CASCADE constraint to one field of EventAccounts. Should I delete an event, the corresponding event accounts will also be deleted. This works just fine when using Django itself (or the admin pages). See my models.py.
models.py:
class Events(models.Model):
   ...

class EventAccounts(models.Model):
   ...
  account_event = models.ForeignKey(Events, on_delete=models.CASCADE)
   ...

Now one of my tasks is to cleanup the database every day to delete events, which ended more than two weeks ago. I was thinking of creating a cronjob to run raw SQL every day. When running this command:
DELETE FROM app_eventtool_events WHERE event_end_date < (NOW() - INTERVAL 14 DAY);
I always get informed that there is an existing child and the events do not get deleted. Which is why I had a look at the table constraints with:
SHOW CREATE TABLE app_eventtool_eventaccounts;
It seems that the ON DELETE CASCADE statement at the end is missing:
CONSTRAINT `app_eventtool_eventa_account_event_id_0ff3718a_fk_app_event` FOREIGN KEY (`account_event_id`) REFERENCES `app_eventtool_events` (`event_id`)
If I now delete the above constraint and add a selfmade one, it looks like this:
ALTER TABLE app_eventtool_eventaccounts ADD CONSTRAINT app_eventtool_events_account_event_id FOREIGN KEY (account_event_id) REFERENCES app_eventtool_events (event_id) ON DELETE CASCADE ON UPDATE NO ACTION;
CONSTRAINT `app_eventtool_events_account_event_id` FOREIGN KEY (`account_event_id`) REFERENCES `app_eventtool_events` (`event_id`) ON DELETE CASCADE ON UPDATE NO ACTION
As you can see, ON DELETE CASCADE is now present. Now I am also able to delete the events with raw SQL as mentioned above. This is reproducible when dropping and creating the database fully. Updating from version 4.0.6 to version 4.1.5 did not solve the problem.

Furthermore I started testing a bit with the on_delete statement in models.py. I changed models.CASCADE to models.RESTRICT and created a new migration. The migration file itself looks fine. But when trying to get the raw SQL of the migration via:
python3 manage.py sqlmigrate app_eventtool 0002
it basically results in an empty migration:
--
-- Alter field account_event on eventaccounts
--
-- (no-op)

Maybe this is expected behaviour, but for me it seems like a bug. Can anyone confirm/deny this?

Thanks in advance,
Dennis
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cb989abd-cb08-8093-668a-03b756149be1%40uni-bremen.de.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/67684c77-0d05-4514-b675-abe6e0eb2b20n%40googlegroups.com.