Autocreate superuser with each schema django - django

I'm working on a multi tenant app using django-tenant-schema(and postgresql). Now as soon as the new schema is getting created, I'm using the call_command to create a superuser. I also thought of the option of using signal post_migrate.
My doubt is how can I auto create a superuser without typing the password in shell.
The use case is as soon as the user registers for his/her schema, a superuser is generated and the user logs in with the superuser username and password and can change the password thereafter.
I'm using the following to call the createsuperuser command:
call_command('createsuperuser', schema_name=self.schema_name, username='admin', email='admin#admin.com')
One way to solve the issue is to change Django's createsuperuser.py file and provide a password over there automatically, buts thats not an acceptable route, ie cahnging the source code for some use case. Could I please request for some better methods

you can "prepare" password for new superuser and pass md5 value to bash:
a=# select md5('some password'||'test');;
md5
----------------------------------
d5b3eb515b64edf295b2ee9062946d24
(1 row)
a=# create user test superuser password 'md5d5b3eb515b64edf295b2ee9062946d24';
CREATE ROLE
so you can use d5b3eb515b64edf295b2ee9062946d24 in bash, saving password somewhere else?..

Related

Django createsuperuser created admin account with wrong password

I am using django 1.11 and DRF to create an app. When I use manage.py createsuperuser command to create a superuser, it successfully created an account for me. But when I am trying to log in to the account. The login screen prompts me a login error.
When I use manage.py changepassword admin command to change the password, I can log in to the account.
This is really annoying, and I can't figure out what happened, for days Are there any reason that can cause the command creating a wrong password? :/
Anybody can help?
most probably you have override the create_superuser method you are passing the password in normal text, you should use the set_password method.
user.set_password("password")
user.save()

How to create a superuser in my own User Form?

I am creating my own form to register users, but how can I make possible to create superusers in it, and also I know django allows you, call user in the views like this:reques.user.username. I can only use that using django forms or I can also use that with my forms
I creating my own form because I donĀ“t want the restriccion django password have, is there a way to change that, in oder to not create my own form
You can run command
python manage.py createsuperuser
Other way is that while saving User data make
is_superuser = True
For password
you need to inherit from AbstractBaseUser and then override that password field and needed to update it's hash, don't know how you will manage that thing but different hash are available.
Docs for custom user

Changin admin email in Django

So I am currently building a project with Django and will need to change the admin email to someone higher up in my division. However I am not sure who's email that will be as they are not sure yet either. If I put my email in now (as I will need to be using it when building the app), can I change it once it is ready to be delivered?
There is no limit to the number of admin accounts you can make. When the time comes to transfer ownership, simply create a new super user and use it to delete the old one.
python manage.py createsuperuser

Change Wagtail password in Django

I have inherited a django project which uses Wagtail for CMS. When I go to (project_url)/cms/ I am asked for a username and password, which I do not have.
Is there any way to create a default user account in the settings.py file, or reset the existing account so that I can gain access to the CMS section?
You can run the changepassword command (django-admin changepassword your_username, for example) to change a password for the existing your_username user.
Alternatively you can create a new superuser using the createsuperuser command by running django-admin createsuperuser.

Superuser credentials not recognized for new Django website and Admin site

I've created a new website using Django 1.8, created a superuser account and logged into the admin interface to initialize some database fields. I can log continue to log into both the admin site and the actual website, as can a couple hundred users.
I've created a second Django website under a separate project (separate database, settings file, etc.) that contains identical code. I ran syncdb and created a different superuser account but when I attempt to log into the admin site with my superuser account, it tells me my username or password is incorrect. I've compared everything with the original website and I can't find anything that's not consistent.
I've confirmed:
I can log directly into the MySQL database using the database name, database user and password that are contained in the settings file
I'm referencing the correct settings file from manage.py
My user record in auth_user has is_staff, is_superuser and is_active all set to 1
I've tried to compare all the configuration files between the two projects and everything matches up as expected. Does anyone have any suggestions about what could affect the authentication or how I might debug this?
Thanks.
After running out of places to look, I deleted and recreated the site database and then reran manage.py syncdb. After that, I was able to log into the admin site. My working theory is that when I entered the superuser password the first time, I pasted into a PUTTY terminal and what it stored for the password was not what I thought it was.
Which kind of doesn't make sense because I did try to add a second superuser using manage.py createsuperuser with a really simple password and I still couldn't log in.
Anyway, thanks for the help.