Skip to content
Snippets Groups Projects
Commit 1f3e391f authored by Adam Drake's avatar Adam Drake
Browse files

fixed bug with AI profiles and userprofiles not being properly created

parent 61ad627f
Branches
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
......@@ -4,7 +4,7 @@ from django.contrib.auth.models import User
class UserRegisterForm(UserCreationForm):
email = forms.EmailField()
role = forms.ChoiceField(choices=[('user', 'User'), ('ai_engineer', 'AI Engineer')], widget=forms.RadioSelect)
role = forms.ChoiceField(choices=[('user', 'User'), ('AI Engineer', 'AI Engineer')], widget=forms.RadioSelect)
class Meta:
model = User
......
......@@ -67,10 +67,11 @@ def register(request):
# Create EndUser if role is 'user'
if role == 'user':
EndUser.objects.create(user=user_profile)
elif role == 'ai_engineer':
elif role == 'AI Engineer':
AIEngineer.objects.create(user=user_profile, is_authorized=False)
messages.success(request, f'Account created for {username}!')
messages.success(request, f'Role value {role}!')
return redirect('MLAAS-login')
else:
form = UserRegisterForm()
......@@ -92,7 +93,7 @@ def MLAAS_login(request):
if user is not None:
try:
if user.userprofile.role == 'ai_engineer':
if user.userprofile.role == 'AI Engineer':
ai_engineer = AIEngineer.objects.get(user=user.userprofile)
if not ai_engineer.is_authorized:
messages.error(request, 'You are not authorized to access the MLaaS system. Please wait for admin authorization.')
......@@ -122,7 +123,7 @@ def create_post(request):
post.author = request.user
# Check if the user is an AI engineer or an admin
if request.user.userprofile.role == 'ai_engineer' or request.user.is_superuser:
if request.user.userprofile.role == 'AI Engineer' or request.user.is_superuser:
post.save()
messages.success(request, 'Your post has been created successfully.')
return redirect('MLAAS-home', pk=post.pk) # Redirect to the post detail page
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment