Commit bb303ab7 authored by delanoe's avatar delanoe

[INSTALL] Default account created with init script.

parent 8a597747
...@@ -2,11 +2,45 @@ ...@@ -2,11 +2,45 @@
import sys import sys
import os import os
dirname = os.path.dirname(os.path.realpath(__file__))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gargantext.settings")
# initialize Django application
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
from django.contrib.auth import password_validation
from django.contrib.auth.hashers import ( check_password
, is_password_usable
, make_password
)
from django.db import models
from django.utils.crypto import get_random_string, salted_hmac
# retrieve Django models
import django.apps
django_models = django.apps.apps.get_models()
django_models_names = set(model._meta.db_table for model in django_models)
from gargantext.util.db import session from gargantext.util.db import session
from gargantext.models.users import User from gargantext.models.users import User
from django.core.mail import send_mail from django.core.mail import send_mail
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gargantext.settings") def make_random_password(length=10
, allowed_chars='abcdefghjkmnpqrstuvwxyz'
'ABCDEFGHJKLMNPQRSTUVWXYZ'
'0123456789'):
"""
Generate a random password with the given length and given
allowed_chars. The default value of allowed_chars does not have "I" or
"O" or letters and digits that look similar -- just to avoid confusion.
(source: django/contrib/auth)
"""
return get_random_string(length, allowed_chars)
def notify_user(username, email, password): def notify_user(username, email, password):
message = ''' message = '''
...@@ -42,10 +76,10 @@ def create_user(username, email, user=None, password=None, active=False, notify= ...@@ -42,10 +76,10 @@ def create_user(username, email, user=None, password=None, active=False, notify=
user.email = email user.email = email
user.is_active = True user.is_active = True
if password is None or password == "": if password is None or password == "":
password = User.objects.make_random_password() password = make_random_password()
#print(password) user.password = make_password(password)
user.set_password(password) session.add(user)
user.save() session.commit()
if notify == True: if notify == True:
notify_user(username, email, password) notify_user(username, email, password)
......
...@@ -99,6 +99,7 @@ service postgresql start ...@@ -99,6 +99,7 @@ service postgresql start
su gargantua su gargantua
source /srv/env_3-5/bin/activate source /srv/env_3-5/bin/activate
/srv/gargantext/manage.py runserver 0.0.0.0:8000 /srv/gargantext/manage.py runserver 0.0.0.0:8000
python /srv/gargantext/init_accounts.py /srv/gargantext/install/init/account.csv
``` ```
### Outside docker container launch browser ### Outside docker container launch browser
......
gargantua,contact@gargantext,autnagrag,
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment