I’m very new to Django.
I used allauth to make email verification and user management system simple.
I want a system where only admins (staff users) can signup users.
But as it is now signup page is only available for not logged in users.
How do I make signup page available only for logged in staff users in Django allauth?
What I tried:
I tried to add custom view, url and template to customize access to signup page and form.
I added this on urls.py:
path('accounts/signup/',views.user_register_view, name='signup'),
And this on views.py:
@login_required
def user_register_view(request):
if request.user.is_staff:
return render(request, "account/signup.html")
else:
reverse_lazy('users:dashboard')
And added a template file in template/account/signup.html, just copied the text from here:
And I added a custom text <br>THIS IS A CUSTOM TEMPLATE</br> just to see if my custom template is viewed.
What happened is just that when I sign in as admin, it instantly redirects to the signup page despite I set LOGIN_REDIRECT_URL = 'users:dashboard' in settings.py
And while only admins can access the accounts/signup page, alle the fields disappeared. This is how it looks like when you view the source:
<br>THIS IS A CUSTOM TEMPLATE</br>
<h1>Sign Up</h1>
<p>Already have an account? Then please <a href="">sign in</a>.</p>
<form class="signup" id="signup_form" method="post" action="/accounts/signup/">
<input type="hidden" name="csrfmiddlewaretoken" value="muuodB6QqTD1BBxfIj7VW16qvjx1S7OUwoUf0xBNy6WuaLSE03228uMRxjJ2COjJ">
<button type="submit">Sign Up »</button>
</form>
How do I make signup page available only for logged in staff users in Django allauth?