mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
1) Replace the deprecated unit test method. 2) Wraps filter usage in a list call. 3) Converts the old metaclass syntax to new. 4) Use range instead of xrange method. 5) Change Unicode to str. 6) Several other transformations. 7) Fixed change password test cases. 8) Use simplejson instead of plain JSON.
81 lines
2.3 KiB
Python
81 lines
2.3 KiB
Python
##########################################################################
|
|
#
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
#
|
|
# Copyright (C) 2013 - 2020, The pgAdmin Development Team
|
|
# This software is released under the PostgreSQL Licence
|
|
#
|
|
##########################################################################
|
|
|
|
import config
|
|
import string
|
|
import random
|
|
import os
|
|
import re
|
|
import getpass
|
|
|
|
|
|
def user_info_desktop():
|
|
print("NOTE: Configuring authentication for DESKTOP mode.")
|
|
email = config.DESKTOP_USER
|
|
p1 = ''.join([
|
|
random.choice(string.ascii_letters + string.digits)
|
|
for _ in range(32)
|
|
])
|
|
return email, p1
|
|
|
|
|
|
def user_info_server():
|
|
print("NOTE: Configuring authentication for SERVER mode.\n")
|
|
|
|
if all(value in os.environ for value in
|
|
['PGADMIN_SETUP_EMAIL', 'PGADMIN_SETUP_PASSWORD']):
|
|
email = ''
|
|
p1 = ''
|
|
if os.environ['PGADMIN_SETUP_EMAIL'] \
|
|
and os.environ['PGADMIN_SETUP_PASSWORD']:
|
|
email = os.environ['PGADMIN_SETUP_EMAIL']
|
|
p1 = os.environ['PGADMIN_SETUP_PASSWORD']
|
|
else:
|
|
# Prompt the user for their default username and password.
|
|
print(
|
|
"Enter the email address and password to use for the initial "
|
|
"pgAdmin user account:\n"
|
|
)
|
|
|
|
email_filter = re.compile(
|
|
"^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9]"
|
|
"(?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9]"
|
|
"(?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
|
|
)
|
|
|
|
email = input("Email address: ")
|
|
while email == '' or not email_filter.match(email):
|
|
print('Invalid email address. Please try again.')
|
|
email = input("Email address: ")
|
|
|
|
def pprompt():
|
|
return getpass.getpass(), getpass.getpass('Retype password:')
|
|
|
|
p1, p2 = pprompt()
|
|
while p1 != p2 or len(p1) < 6:
|
|
if p1 != p2:
|
|
print('Passwords do not match. Please try again.')
|
|
else:
|
|
print(
|
|
'Password must be at least 6 characters. '
|
|
'Please try again.'
|
|
)
|
|
p1, p2 = pprompt()
|
|
|
|
return email, p1
|
|
|
|
|
|
def user_info():
|
|
if config.SERVER_MODE is False:
|
|
email, p1 = user_info_desktop()
|
|
else:
|
|
email, p1 = user_info_server()
|
|
|
|
return email, p1
|