Commit 5b36771d authored by BERJON Matthieu's avatar BERJON Matthieu
Browse files

Merge branch '126-email-address-not-validated-when-the-user-changes-it' of...


Merge branch '126-email-address-not-validated-when-the-user-changes-it' of gitlab.inria.fr:allgo/allgo into 126-email-address-not-validated-when-the-user-changes-it
Signed-off-by: BERJON Matthieu's avatarMatthieu Berjon <matthieu.berjon@inria.fr>
parents 1cabf77d 12b87f75
Pipeline #41441 failed with stage
in 1 minute and 3 seconds
import types
from config.settings import parse_bool
import config.env
GLOBAL_CONTEXT = types.MappingProxyType({
"ALLGO_ALLOW_LOCAL_ACCOUNTS": parse_bool(config.env.ALLGO_ALLOW_LOCAL_ACCOUNTS)
})
def global_context(request):
"""This global context is imported in every rendered template"""
return GLOBAL_CONTEXT
......@@ -4,18 +4,21 @@ import os
from django.conf import settings
from django.contrib import auth
from django.contrib.auth.models import User, AnonymousUser
from django.core.exceptions import PermissionDenied
from django.core.validators import MinLengthValidator, MinValueValidator, \
RegexValidator
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from taggit.managers import TaggableManager
from allauth.socialaccount.models import SocialAccount
from django.utils.crypto import get_random_string
from .validators import job_param_validator, docker_container_id_validator, \
docker_tag_validator, docker_name_validator, \
sshkey_validator, token_validator
import config.env
......@@ -615,6 +618,10 @@ class Job(TimeStampModel):
@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
if created:
if (not config.settings.parse_bool(config.env.ALLGO_ALLOW_LOCAL_ACCOUNTS)
and not SocialAccount.objects.filter(user=instance).exists()):
# creation of local user accounts not allowed
raise PermissionDenied
AllgoUser.objects.create(user=instance)
......
......@@ -21,15 +21,21 @@
<ul class="navbar-nav ml-auto">
{% if not user.is_authenticated %}
<li class="nav-item">
{% get_providers as socialaccount_providers %}
{% if socialaccount_providers %}
{% for account in socialaccount_providers %}
<a href="{% provider_login_url account.id %}"
class="btn btn-primary {{ account.id }} text-center ">Log in with Gitlab</a>
{% endfor %}
{% if ALLGO_ALLOW_LOCAL_ACCOUNTS %}
<li class="nav-item {% is_active request 'account_login' %}">
<a class="nav-link" href="{% url 'account_login' %}">Sign in</a>
</li>
{% else %}
<li class="nav-item">
{% get_providers as socialaccount_providers %}
{% if socialaccount_providers %}
{% for account in socialaccount_providers %}
<a href="{% provider_login_url account.id %}"
class="btn btn-primary {{ account.id }} text-center ">Log in with Gitlab</a>
{% endfor %}
{% endif %}
</li>
{% endif %}
</li>
{% else %}
<li class="nav-item {% is_active request 'user_webapp_list' 'webapp_update' 'webapp_creation' 'webapp_sandbox_panel' %}">
<a class="nav-link" href="{% url 'main:user_webapp_list' user.get_username %}"><i class="fas fa-cloud"></i> Apps</a>
......
......@@ -192,6 +192,10 @@ with env_loader.EnvironmentVarLoader(__name__, "ALLGO_",
env_var("ALLGO_IMPORT_REGISTRY", default="cargo.irisa.fr:8003/allgo/prod/webapp",
help="registry of the legacy allgo instance (for importing webapps)")
env_var("ALLGO_ALLOW_LOCAL_ACCOUNTS", protected=True, default="False",
help="""Allow signing in with a local account (for development
purpose only)""")
#
# allgo authentication tokens
#
......
......@@ -220,6 +220,7 @@ TEMPLATES = [
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'main.context_processors.global_context',
],
},
},
......
......@@ -39,6 +39,7 @@ services:
ALLGO_ALLOWED_IP_ADMIN: "0.0.0.0/0"
ALLGO_DATASTORE: "/vol/rw/datastore"
ALLGO_DEBUG: "True"
ALLGO_ALLOW_LOCAL_ACCOUNTS: "True"
ALLGO_JUPYTER_URL: "http://0.0.0.0:8000/hub/login"
ALLGO_HTTP_SERVER: "django"
ALLGO_EMAIL_BACKEND: "django.core.mail.backends.console.EmailBackend"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment