Skip to content

Commit

Permalink
raising validation error for sending emails if no email address is pr…
Browse files Browse the repository at this point in the history
…ovided
  • Loading branch information
sonicnkt committed Apr 8, 2021
1 parent ea532f0 commit d83c08c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/adminview.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ def no_root_allowed(form, field):

# Add custom Fields
form_extra_fields = {
'password': PasswordField('Password'),
'password': PasswordField('Password',
render_kw={"autocomplete": "new-password"},
description='TEMP'),
'send_pw_reset_link': BooleanField('Send Password Reset Link'),
# Make this a button in the list view?
'send_invite_link': BooleanField('Send Invite Link')
Expand Down Expand Up @@ -142,6 +144,9 @@ def create_form(self, obj=None):
form.pgroup.query = Group.query.filter_by(primary=True).all()
form.othergroups.query = Group.query.filter_by(primary=False).all()

# Add Password field description
form.password.description = 'Leave empty if you want to autogenerate a password.'

default_unixid=5001
highest_user=User.query.order_by(User.unixid.desc()).limit(1).all()
if highest_user:
Expand All @@ -157,6 +162,9 @@ def edit_form(self, obj):
# Change form attribute?
#setattr(form, 'TEST', BooleanField('DummyTest') )

# Add Password field description
form.password.description = 'Leave empty to keep the current password.'

# Modify query result for query form
# Primarygroup.query.filter(Primarygroup.name.like('%test%')).all()
form.pgroup.query = Group.query.filter_by(primary=True).all()
Expand All @@ -171,6 +179,8 @@ def on_model_change(self, form, model, is_created):

# If new users was created without password
if is_created:
if form.send_invite_link.data and ((not form.mail.data) or form.mail.data == '' ):
raise ValidationError('A valid Email Address is required for sending invite links.')
if not form.password.data or form.password.data == '':
# Generate random password
password = ''.join(choices(ascii_uppercase + ascii_lowercase + digits, k=8))
Expand All @@ -195,6 +205,8 @@ def on_model_change(self, form, model, is_created):
model.set_password(form.password.data)
# If Reset PW Optione is enabled
if hasattr(form, 'send_pw_reset_link'):
if form.send_pw_reset_link.data and ((not form.mail.data) or form.mail.data == '' ):
raise ValidationError('A valid Email Address is required for sending password reset links.')
if form.send_pw_reset_link.data:
# Disable Account
model.is_active = False
Expand Down

0 comments on commit d83c08c

Please sign in to comment.