Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions geonode/people/forms.py → geonode/people/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,10 @@
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from django.utils.translation import gettext_lazy as _

try:
from captcha.fields import ReCaptchaField
except ImportError:
from django_recaptcha.fields import ReCaptchaField

# Ported in from django-registration
attrs_dict = {"class": "required"}


class AllauthReCaptchaSignupForm(forms.Form):
captcha = ReCaptchaField(label=False)

def signup(self, request, user):
"""Required, or else it thorws deprecation warnings"""
pass


class ProfileCreationForm(UserCreationForm):
class Meta:
model = get_user_model()
Expand Down
41 changes: 41 additions & 0 deletions geonode/people/forms/recaptcha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#########################################################################
#
# Copyright (C) 2019 Open Source Geospatial Foundation - all rights reserved
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################

from django import forms
from allauth.account.forms import LoginForm

try:
from captcha.fields import ReCaptchaField
except ImportError:
from django_recaptcha.fields import ReCaptchaField


class AllauthReCaptchaSignupForm(forms.Form):
captcha = ReCaptchaField(label=False)

def signup(self, request, user):
"""Required, or else it thorws deprecation warnings"""
pass


class AllauthRecaptchaLoginForm(LoginForm):
captcha = ReCaptchaField(label=False)

def login(self, *args, **kwargs):
return super(AllauthRecaptchaLoginForm, self).login(*args, **kwargs)
14 changes: 14 additions & 0 deletions geonode/people/templates/people/account_login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends "account/login.html" %}
{% comment %} Inherited from Django AllAuth default login form {% endcomment %}

{% block extra_script %}
<script type="text/javascript">
$( document ).ready(function() {
let recaptchaControl= $(".g-recaptcha" );

if (recaptchaControl.length ) {
recaptchaControl.removeClass('form-control');
}
});
</script>
{% endblock extra_script %}
6 changes: 5 additions & 1 deletion geonode/people/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################
from allauth.account.views import SignupView
from allauth.account.views import SignupView, LoginView
from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import login_required
from django.contrib import messages
Expand Down Expand Up @@ -55,6 +55,10 @@ def get_context_data(self, **kwargs):
form.field_order = [f for f in form.fields.keys() if f != "captcha"] + ["captcha"]
form.order_fields(form.field_order)
return ret


class CustomLoginView(LoginView):
template_name = 'people/account_login.html'


@login_required
Expand Down
8 changes: 7 additions & 1 deletion geonode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1401,8 +1401,14 @@
if "django_recaptcha" not in INSTALLED_APPS:
INSTALLED_APPS += ("django_recaptcha",)
ACCOUNT_SIGNUP_FORM_CLASS = os.getenv(
"ACCOUNT_SIGNUP_FORM_CLASS", "geonode.people.forms.AllauthReCaptchaSignupForm"
"ACCOUNT_SIGNUP_FORM_CLASS", "geonode.people.forms.recaptcha.AllauthReCaptchaSignupForm"
)

# https://docs.allauth.org/en/dev/account/configuration.html
ACCOUNT_FORMS = dict(
login='geonode.people.forms.recaptcha.AllauthRecaptchaLoginForm'
)

"""
In order to generate reCaptcha keys, please see:
- https://pypi.org/project/django-recaptcha/#installation
Expand Down
3 changes: 2 additions & 1 deletion geonode/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from geonode.utils import check_ogc_backend
from geonode.base import register_url_event
from geonode.messaging.urls import urlpatterns as msg_urls
from .people.views import CustomSignupView
from .people.views import CustomSignupView, CustomLoginView
from oauth2_provider.urls import app_name as oauth2_app_name, base_urlpatterns, oidc_urlpatterns

admin.autodiscover()
Expand Down Expand Up @@ -92,6 +92,7 @@
re_path(r"^h_keywords_api$", views.h_keywords, name="h_keywords_api"),
# Social views
re_path(r"^account/signup/", CustomSignupView.as_view(), name="account_signup"),
re_path(r"^account/login/", CustomLoginView.as_view(), name="account_login"),
re_path(r"^account/", include("allauth.urls")),
re_path(r"^invitations/", include("geonode.invitations.urls", namespace="geonode.invitations")),
re_path(r"^people/", include("geonode.people.urls")),
Expand Down