def form_valid(self, form): user = form.save() logger.info("Password Reset Done for %s", str(user.username)) CommonHelpers.send_confirmation_mail(user) return super().form_valid(form)
def create_user(self, username, email, password, user_type, first_name='', last_name='', phone_number=None, date_of_birth=None, validate=True, is_active=False, send_password_mail=True, send_otp_mail=False, created_by=None): if not email or not username: raise ValueError('Users must have an email and a username') if password is None: password = self.make_random_password() validate = False username = username.lower() user = self.model( first_name=first_name, last_name=last_name, email=self.normalize_email(email), username=username, phone_number=phone_number, date_of_birth=date_of_birth, user_type=user_type, assigned_to=created_by, ) if validate: validate_password(password) user.set_password(password) # Activate User on email confirmation, bypass for superuser user.is_active = is_active user.save(using=self.db) TOTPDevice.objects.create(name='Phone', user=user, confirmed=False) if not user.is_internal_user(): account = Account.objects.create(user=user) Card.objects.create(account=account) if send_password_mail: CommonHelpers.send_password_mail(user) if send_otp_mail: CommonHelpers.send_confirmation_mail(user) return user