Skip to content

Commit 3e7234e

Browse files
author
Guillim
committed
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
1 parent d7ccf57 commit 3e7234e

File tree

5 files changed

+35
-18
lines changed

5 files changed

+35
-18
lines changed

app/authentification/templates/base_auth.html

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,9 @@
22

33
{% block content %}
44
<div class="hero-body">
5-
<div class="container" style="max-width:600px">
6-
<div class="card is-shady">
5+
<div class="container">
6+
<div class="card is-shady column is-4 is-offset-4">
77
{% block content_auth %}{% endblock %}
8-
<!-- <div class="card-image">
9-
<figure class="image is-4by3">
10-
<img src="https://source.unsplash.com/6Ticnhs1AG0" alt="Placeholder image">
11-
</figure>
12-
</div>
13-
<div class="card-content">
14-
<div class="content">
15-
<h4>Language independent</h4>
16-
<p>doccano is independent on any languages. You can annotate texts regardless of your languages. You can quickly start annotating text.</p>
17-
</div>
18-
</div> -->
198
</div>
209
</div>
2110
</div>

app/authentification/templates/signup.html

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
{% load utils_templating %}
44
{% block content_auth %}
5+
{% if allow_signup %}
56
<div class="card-content">
6-
<div style="text-align:center;font-size:1.5em">
7+
<!-- <div style="text-align:center;font-size:1.5em">
78
<h2>Sign up</h2>
8-
</div>
9+
</div> -->
910
<form method="post">
1011
{% csrf_token %}
1112
{% for field in form %}
@@ -24,8 +25,21 @@ <h2>Sign up</h2>
2425

2526
{% endfor %}
2627
<div style="text-align:center">
27-
<button type="submit" class="button is-link">Sign up</button>
28+
<button type="submit" class="button is-block is-primary is-fullwidth is-middle">Sign up</button>
29+
</div>
30+
<div class="field">
31+
<span class="checkbox" style="margin-top:30px">
32+
Already registered ? <a href="{% url 'login' %}"> login </a>
33+
</span>
2834
</div>
2935
</form>
3036
</div>
37+
38+
{% else %}
39+
<div class="card-content">
40+
<div>
41+
You can't signup yourself, please contact the admin in order to get your username and your password!
42+
</div>
43+
</div>
44+
{% endif %}
3145
{% endblock %}

app/authentification/views.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@
88
from django.core.mail import EmailMessage
99
from django.views.generic import TemplateView
1010

11+
from app import settings
12+
1113
class SignupView(TemplateView):
1214
template_name = 'signup.html'
1315
form_class = SignupForm
1416

1517
def get(self, request, *args, **kwargs):
1618
form = self.form_class()
17-
return render(request, self.template_name, {'form': form})
19+
return render(request, self.template_name, {'form': form, 'allow_signup': bool(settings.ALLOW_SIGNUP)})
1820

1921
def post(self, request, *args, **kwargs):
2022
form = self.form_class(request.POST)
23+
24+
# here we make sure that a post request won't trigger a subscription in case allow_signup is False
25+
if not bool(settings.ALLOW_SIGNUP):
26+
return redirect('signup')
2127

2228
if form.is_valid():
2329
user = form.save(commit=False)

app/server/templates/login.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
</label>
4848
</div>
4949
<input class="button is-block is-primary is-middle is-fullwidth" type="submit" value="Login" />
50+
{% if allow_signup %}
51+
<div class="field">
52+
<span class="checkbox" style="margin-top:10px">
53+
Not registered yet ? <a href="{% url 'signup' %}"> Sign up </a>
54+
</span>
55+
</div>
56+
{% endif %}
5057
<input type="hidden" name="next" value="{{ next }}" />
5158
</form>
5259
{% if social_login_enabled %}
@@ -68,4 +75,4 @@
6875
</div>
6976
</div>
7077
</section>
71-
{% endblock %}
78+
{% endblock %}

app/server/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class LoginView(BaseLoginView):
9090
extra_context = {
9191
'github_login': bool(settings.SOCIAL_AUTH_GITHUB_KEY),
9292
'aad_login': bool(settings.SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_TENANT_ID),
93+
'allow_signup' : bool(settings.ALLOW_SIGNUP),
9394
}
9495

9596
def get_context_data(self, **kwargs):

0 commit comments

Comments
 (0)