2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-17 07:37:19 +00:00

New User registration form

This commit is contained in:
2025-01-23 23:38:06 +00:00
parent f842dab12a
commit a5d0ad3e4f
5 changed files with 173 additions and 38 deletions

View File

@@ -25,20 +25,25 @@ todo = """
USERS_FILE = "users.json"
ENCRYPTED_DIR = "encrypted"
def register_user(u, email, password=None, pwhash=None):
def register_user(u, email, password=None, pwhash=None, fullname=None):
"""Create User and we may not have a Person to tie it to if it is a future caver.
Do not use the lastname field, put the whole free text identification into firstname
as this saves hassle and works with Wookey too
"""
try:
if existing_user := User.objects.filter(username=u): # WALRUS
print(f" - deleting existing user '{existing_user[0]}' before importing")
existing_user[0].delete()
user = User.objects.create_user(u, email)
user = User.objects.create_user(u, email, first_name=fullname)
if pwhash:
user.password = pwhash
elif password:
user.set_password(password) # function creates hash and stores hash
print(f" # hashing provided clear-text password {password} to make pwhash for user {u}")
else:
user.set_password('secret') # function creates hash and stores hash
print(f" # hashing 'secret' password to make pwhash for user {u}")
# user.set_password(None) # use Django special setting for invalid password, but then FAILS to send password reset email
user.set_password("secret") # Why is the Django logic broken. Hmph.
print(f" # setting INVALID password for user {u}, must be reset by password_reset")
user.is_staff = False
user.is_superuser = False
user.save()