diff --git a/allianceauth/authentication/views.py b/allianceauth/authentication/views.py index e48cec8b..9ddd2f85 100644 --- a/allianceauth/authentication/views.py +++ b/allianceauth/authentication/views.py @@ -95,20 +95,33 @@ class RegistrationView(BaseRegistrationView): form_class = RegistrationForm success_url = 'authentication:dashboard' - def dispatch(self, *args, **kwargs): + def get_success_url(self, user): + if not getattr(settings, 'REGISTRATION_VERIFY_EMAIL', True): + return 'authentication:dashboard', (), {} + return super().get_success_url(user) + + def dispatch(self, request, *args, **kwargs): # We're storing a key in the session to pass user information from OAuth response. Make sure it's there. if not self.request.session.get('registration_uid', None) or not User.objects.filter( pk=self.request.session.get('registration_uid')).exists(): messages.error(self.request, _('Registration token has expired.')) return redirect(settings.LOGIN_URL) - return super(RegistrationView, self).dispatch(*args, **kwargs) + if not getattr(settings, 'REGISTRATION_VERIFY_EMAIL', True): + # Keep the request so the user can be automagically logged in. + setattr(self, 'request', request) + return super(RegistrationView, self).dispatch(request, *args, **kwargs) def register(self, form): user = User.objects.get(pk=self.request.session.get('registration_uid')) user.email = form.cleaned_data['email'] user_registered.send(self.__class__, user=user, request=self.request) - # Go to Step 3 - self.send_activation_email(user) + if getattr(settings, 'REGISTRATION_VERIFY_EMAIL', True): + # Go to Step 3 + self.send_activation_email(user) + else: + user.is_active = True + user.save() + login(self.request, user, 'allianceauth.authentication.backends.StateBackend') return user def get_activation_key(self, user): diff --git a/allianceauth/project_template/project_name/settings/local.py b/allianceauth/project_template/project_name/settings/local.py index ac93427f..039feebd 100644 --- a/allianceauth/project_template/project_name/settings/local.py +++ b/allianceauth/project_template/project_name/settings/local.py @@ -41,10 +41,12 @@ ESI_SSO_CLIENT_ID = '' ESI_SSO_CLIENT_SECRET = '' ESI_SSO_CALLBACK_URL = '' -# Emails are validated before new users can log in. +# By default emails are validated before new users can log in. # It's recommended to use a free service like SparkPost or Mailgun to send email. # https://www.sparkpost.com/docs/integrations/django/ # Set the default from email to something like 'noreply@example.com' +# Email validation can be turned off by uncommenting the line below. This can break some services. +# REGISTRATION_VERIFY_EMAIL = False EMAIL_HOST = '' EMAIL_PORT = 587 EMAIL_HOST_USER = ''