The reset password button generates a temporary random password which expires after 1 day and is sent to the email address of the user. The temporary password does not work as soon as a new password has been set. The trytond-admin asks the email address for admin user and has an option to set the admin email and to reset its password. issue7037 review41761002
113 lines
4.3 KiB
Python
113 lines
4.3 KiB
Python
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
|
# this repository contains the full copyright notices and license terms.
|
|
import sys
|
|
import os
|
|
import logging
|
|
from getpass import getpass
|
|
|
|
from sql import Table
|
|
|
|
from trytond.transaction import Transaction
|
|
from trytond import backend
|
|
from trytond.pool import Pool
|
|
from trytond.config import config
|
|
|
|
__all__ = ['run']
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def run(options):
|
|
Database = backend.get('Database')
|
|
init = {}
|
|
for db_name in options.database_names:
|
|
init[db_name] = False
|
|
with Transaction().start(db_name, 0, _nocache=True):
|
|
database = Database(db_name)
|
|
database.connect()
|
|
if options.update:
|
|
if not database.test():
|
|
logger.info("init db")
|
|
database.init()
|
|
init[db_name] = True
|
|
elif not database.test():
|
|
raise Exception('"%s" is not a Tryton database.' % db_name)
|
|
|
|
for db_name in options.database_names:
|
|
if options.update:
|
|
with Transaction().start(db_name, 0) as transaction,\
|
|
transaction.connection.cursor() as cursor:
|
|
database = Database(db_name)
|
|
database.connect()
|
|
if not database.test():
|
|
raise Exception('"%s" is not a Tryton database.' % db_name)
|
|
lang = Table('ir_lang')
|
|
cursor.execute(*lang.select(lang.code,
|
|
where=lang.translatable == True))
|
|
lang = set([x[0] for x in cursor.fetchall()])
|
|
main_lang = config.get('database', 'language')
|
|
lang.add(main_lang)
|
|
else:
|
|
lang = set()
|
|
lang |= set(options.languages)
|
|
pool = Pool(db_name)
|
|
pool.init(update=options.update, lang=list(lang),
|
|
installdeps=options.installdeps)
|
|
|
|
if options.update_modules_list:
|
|
with Transaction().start(db_name, 0) as transaction:
|
|
Module = pool.get('ir.module')
|
|
Module.update_list()
|
|
|
|
if lang:
|
|
with Transaction().start(db_name, 0) as transaction:
|
|
pool = Pool()
|
|
Lang = pool.get('ir.lang')
|
|
languages = Lang.search([
|
|
('code', 'in', lang),
|
|
])
|
|
Lang.write(languages, {
|
|
'translatable': True,
|
|
})
|
|
|
|
for db_name in options.database_names:
|
|
with Transaction().start(db_name, 0) as transaction:
|
|
pool = Pool()
|
|
User = pool.get('res.user')
|
|
admin, = User.search([('login', '=', 'admin')])
|
|
|
|
if options.email is not None:
|
|
admin.email = options.email
|
|
elif init[db_name]:
|
|
admin.email = raw_input(
|
|
'"admin" email for "%s": ' % db_name)
|
|
if init[db_name] or options.password:
|
|
# try to read password from environment variable
|
|
# TRYTONPASSFILE, empty TRYTONPASSFILE ignored
|
|
passpath = os.getenv('TRYTONPASSFILE')
|
|
password = ''
|
|
if passpath:
|
|
try:
|
|
with open(passpath) as passfile:
|
|
password, = passfile.read().splitlines()
|
|
except Exception, err:
|
|
sys.stderr.write('Can not read password '
|
|
'from "%s": "%s"\n' % (passpath, err))
|
|
|
|
if not password and not options.reset_password:
|
|
while True:
|
|
password = getpass(
|
|
'"admin" password for "%s": ' % db_name)
|
|
password2 = getpass('"admin" password confirmation: ')
|
|
if password != password2:
|
|
sys.stderr.write('"admin" password confirmation '
|
|
'doesn\'t match "admin" password.\n')
|
|
continue
|
|
if not password:
|
|
sys.stderr.write('"admin" password is required.\n')
|
|
continue
|
|
admin.password = password
|
|
break
|
|
admin.save()
|
|
if options.reset_password:
|
|
User.reset_password([admin])
|