Skip to content

Commit

Permalink
Fix sign up not sending email, hide username in signup form (#4152)
Browse files Browse the repository at this point in the history
* Fix sign up not sending email, hide username in signup form

* Recatchpta

* Use role display name
  • Loading branch information
dimasciput authored Aug 14, 2024
1 parent 69f6933 commit f407f3d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
23 changes: 21 additions & 2 deletions bims/forms/sign_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class CustomSignupForm(SignupForm):
queryset=Role.objects.all().order_by('order'),
required=True
)
username = forms.CharField(
widget=forms.HiddenInput(),
required=False)

def __init__(self, *args, **kwargs):
super(CustomSignupForm, self).__init__(*args, **kwargs)
Expand All @@ -33,12 +36,28 @@ def __init__(self, *args, **kwargs):
except Role.DoesNotExist:
pass

def clean_username(self):
username = self.cleaned_data.get('username')
if not username:
new_username = '{first_name}_{last_name}'.format(
first_name=self.data.get('first_name').lower(),
last_name=self.data.get('last_name').lower()
)
if Profile.objects.filter(user__username=new_username).exists():
counter = 1
unique_username = new_username
while Profile.objects.filter(user__username=unique_username).exists():
unique_username = f'{new_username}_{counter}'
counter += 1
return unique_username
return new_username
return username

def custom_signup(self, request, user):
user.first_name = self.cleaned_data['first_name']
user.last_name = self.cleaned_data['last_name']
user.organization = self.cleaned_data['organization']
if 'username' in self.cleaned_data:
user.username = self.cleaned_data["username"]
user.username = self.cleaned_data.get('username', user.email)
user.save()
bims_profile, created = Profile.objects.get_or_create(
user=user
Expand Down
3 changes: 3 additions & 0 deletions bims/models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class Profile(models.Model):
help_text="The source site where the user signed up. For tracking user registration origins."
)

def get_role_display(self):
return self.role.display_name if self.role else '-'

@property
def first_name(self):
if self.user:
Expand Down

0 comments on commit f407f3d

Please sign in to comment.