Browse Source

We go on with authentification:

- we set up python restriction related to the environment variable 
"allow_signup"
- we clean a bit html code in base_auth.html
- we allow switch between signin and signup
pull/250/head
Guillim 5 years ago
parent
commit
3e7234e2a6
5 changed files with 35 additions and 18 deletions
  1. 15
      app/authentification/templates/base_auth.html
  2. 20
      app/authentification/templates/signup.html
  3. 8
      app/authentification/views.py
  4. 9
      app/server/templates/login.html
  5. 1
      app/server/views.py

15
app/authentification/templates/base_auth.html

@ -2,20 +2,9 @@
{% block content %}
<div class="hero-body">
<div class="container" style="max-width:600px">
<div class="card is-shady">
<div class="container">
<div class="card is-shady column is-4 is-offset-4">
{% block content_auth %}{% endblock %}
<!-- <div class="card-image">
<figure class="image is-4by3">
<img src="https://source.unsplash.com/6Ticnhs1AG0" alt="Placeholder image">
</figure>
</div>
<div class="card-content">
<div class="content">
<h4>Language independent</h4>
<p>doccano is independent on any languages. You can annotate texts regardless of your languages. You can quickly start annotating text.</p>
</div>
</div> -->
</div>
</div>
</div>

20
app/authentification/templates/signup.html

@ -2,10 +2,11 @@
{% load utils_templating %}
{% block content_auth %}
{% if allow_signup %}
<div class="card-content">
<div style="text-align:center;font-size:1.5em">
<!-- <div style="text-align:center;font-size:1.5em">
<h2>Sign up</h2>
</div>
</div> -->
<form method="post">
{% csrf_token %}
{% for field in form %}
@ -24,8 +25,21 @@
{% endfor %}
<div style="text-align:center">
<button type="submit" class="button is-link">Sign up</button>
<button type="submit" class="button is-block is-primary is-fullwidth is-middle">Sign up</button>
</div>
<div class="field">
<span class="checkbox" style="margin-top:30px">
Already registered ? <a href="{% url 'login' %}"> login </a>
</span>
</div>
</form>
</div>
{% else %}
<div class="card-content">
<div>
You can't signup yourself, please contact the admin in order to get your username and your password!
</div>
</div>
{% endif %}
{% endblock %}

8
app/authentification/views.py

@ -8,16 +8,22 @@ from .tokens import account_activation_token
from django.core.mail import EmailMessage
from django.views.generic import TemplateView
from app import settings
class SignupView(TemplateView):
template_name = 'signup.html'
form_class = SignupForm
def get(self, request, *args, **kwargs):
form = self.form_class()
return render(request, self.template_name, {'form': form})
return render(request, self.template_name, {'form': form, 'allow_signup': bool(settings.ALLOW_SIGNUP)})
def post(self, request, *args, **kwargs):
form = self.form_class(request.POST)
# here we make sure that a post request won't trigger a subscription in case allow_signup is False
if not bool(settings.ALLOW_SIGNUP):
return redirect('signup')
if form.is_valid():
user = form.save(commit=False)

9
app/server/templates/login.html

@ -47,6 +47,13 @@
</label>
</div>
<input class="button is-block is-primary is-middle is-fullwidth" type="submit" value="Login" />
{% if allow_signup %}
<div class="field">
<span class="checkbox" style="margin-top:10px">
Not registered yet ? <a href="{% url 'signup' %}"> Sign up </a>
</span>
</div>
{% endif %}
<input type="hidden" name="next" value="{{ next }}" />
</form>
{% if social_login_enabled %}
@ -68,4 +75,4 @@
</div>
</div>
</section>
{% endblock %}
{% endblock %}

1
app/server/views.py

@ -90,6 +90,7 @@ class LoginView(BaseLoginView):
extra_context = {
'github_login': bool(settings.SOCIAL_AUTH_GITHUB_KEY),
'aad_login': bool(settings.SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_TENANT_ID),
'allow_signup' : bool(settings.ALLOW_SIGNUP),
}
def get_context_data(self, **kwargs):

Loading…
Cancel
Save