Browse Source

coding style fixes

pull/250/head
Guillim 6 years ago
parent
commit
a6ea2a772a
11 changed files with 61 additions and 49 deletions
  1. 1
      app/authentification/forms.py
  2. 10
      app/authentification/templates/base_auth.html
  3. 38
      app/authentification/templates/password_reset_confirm.html
  4. 2
      app/authentification/templates/password_reset_form.html
  5. 28
      app/authentification/templates/signup.html
  6. 1
      app/authentification/templatetags/utils_templating.py
  7. 4
      app/authentification/tokens.py
  8. 13
      app/authentification/urls.py
  9. 4
      app/authentification/utils.py
  10. 7
      app/authentification/views.py
  11. 2
      app/server/views.py

1
app/authentification/forms.py

@ -2,6 +2,7 @@ from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
class SignupForm(UserCreationForm):
email = forms.EmailField(max_length=200, help_text='Required')

10
app/authentification/templates/base_auth.html

@ -1,11 +1,11 @@
{% extends 'base.html' %}
{% block content %}
<div class="hero-body">
<div class="container">
<div class="card is-shady column is-4 is-offset-4">
{% block content_auth %}{% endblock %}
</div>
<div class="hero-body">
<div class="container">
<div class="card is-shady column is-4 is-offset-4">
{% block content_auth %}{% endblock %}
</div>
</div>
</div>
{% endblock %}

38
app/authentification/templates/password_reset_confirm.html

@ -1,25 +1,25 @@
{% extends "base_auth.html" %}
{% block content_auth %}
{% if validlink %}
<div class="card-content">
<div style="text-align:center;font-size:1.5em">
<h2>Change password</h2>
</div>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<div style="text-align:center">
<button type="submit" class="button is-link">Change password</button>
</div>
</form>
{% if validlink %}
<div class="card-content">
<div style="text-align:center;font-size:1.5em">
<h2>Change password</h2>
</div>
{% else %}
<div class="card-content">
The password reset link was invalid, possibly because it has already been used.
Please request a new password reset.
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<div style="text-align:center">
<button type="submit" class="button is-link">Change password</button>
</div>
{% endif %}
</form>
</div>
{% else %}
<div class="card-content">
The password reset link was invalid, possibly because it has already been used.
Please request a new password reset.
</div>
{% endif %}
{% endblock %}

2
app/authentification/templates/password_reset_form.html

@ -11,7 +11,7 @@
{% csrf_token %}
{{ form.as_p }}
<div style="text-align:center">
<button type="submit" class="button is-link">Submit</button>
<button type="submit" class="button is-link">Submit</button>
</div>
</form>

28
app/authentification/templates/signup.html

@ -9,23 +9,23 @@
</div> -->
<form method="post">
{% csrf_token %}
{% for field in form %}
<div class="field">
<label class="label">{{ field.label_tag }}</label>
<div class="control">
{{ field|addcss:'input' }}
{% if field.help_text %}
<small style="display: none">{{ field.help_text }}</small>
{% endif %}
{% for error in field.errors %}
<p style="color: red">{{ error }}</p>
{% endfor %}
</div>
{% for field in form %}
<div class="field">
<label class="label">{{ field.label_tag }}</label>
<div class="control">
{{ field|addcss:'input' }}
{% if field.help_text %}
<small style="display: none">{{ field.help_text }}</small>
{% endif %}
{% for error in field.errors %}
<p style="color: red">{{ error }}</p>
{% endfor %}
</div>
</div>
{% endfor %}
{% endfor %}
<div style="text-align:center">
<button type="submit" class="button is-block is-primary is-fullwidth is-middle">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">

1
app/authentification/templatetags/utils_templating.py

@ -2,6 +2,7 @@ from django import template
register = template.Library()
@register.filter(name='addcss')
def addcss(value, arg):
css_classes = value.field.widget.attrs.get('class', '').split(' ')

4
app/authentification/tokens.py

@ -1,9 +1,13 @@
from django.contrib.auth.tokens import PasswordResetTokenGenerator
from django.utils import six
class TokenGenerator(PasswordResetTokenGenerator):
def _make_hash_value(self, user, timestamp):
return (
six.text_type(user.pk) + six.text_type(timestamp) +
six.text_type(user.is_active)
)
account_activation_token = TokenGenerator()

13
app/authentification/urls.py

@ -1,14 +1,17 @@
from django.urls import path
from django.contrib.auth.views import PasswordResetDoneView, PasswordResetConfirmView, PasswordResetCompleteView
from .views import SignupView
from .utils import activate
from .views import SignupView
from .utils import activate
urlpatterns = [
path('password_reset/done/', PasswordResetDoneView.as_view(),name='password_reset_done'),
path('reset/done/', PasswordResetCompleteView.as_view(),name='password_reset_complete'),
path('reset/<uidb64>/<token>/', PasswordResetConfirmView.as_view(),name='password_reset_confirm'),
path('password_reset/done/', PasswordResetDoneView.as_view(),
name='password_reset_done'),
path('reset/done/', PasswordResetCompleteView.as_view(),
name='password_reset_complete'),
path('reset/<uidb64>/<token>/', PasswordResetConfirmView.as_view(),
name='password_reset_confirm'),
path('signup/', SignupView.as_view(), name='signup'),
path('activate/<str:uidb64>/<str:token>', activate, name='activate'),
]

4
app/authentification/utils.py

@ -6,6 +6,7 @@ from django.utils.http import urlsafe_base64_decode
from .tokens import account_activation_token
from django.contrib.auth.models import User
def activate(request, uidb64, token):
try:
uid = force_text(urlsafe_base64_decode(uidb64))
@ -15,7 +16,8 @@ def activate(request, uidb64, token):
if user is not None and account_activation_token.check_token(user, token):
user.is_active = True
user.save()
login(request=request, user=user, backend='django.contrib.auth.backends.ModelBackend')
login(request=request, user=user,
backend='django.contrib.auth.backends.ModelBackend')
return redirect('projects')
else:
return render(request, 'validate_mail_address_invalid.html')

7
app/authentification/views.py

@ -10,6 +10,7 @@ from django.views.generic import TemplateView
from app import settings
class SignupView(TemplateView):
template_name = 'signup.html'
form_class = SignupForm
@ -35,12 +36,12 @@ class SignupView(TemplateView):
message = render_to_string('acc_active_email.html', {
'user': user,
'domain': current_site.domain,
'uid':urlsafe_base64_encode(force_bytes(user.pk)).decode(),
'token':account_activation_token.make_token(user),
'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode(),
'token': account_activation_token.make_token(user),
})
to_email = form.cleaned_data.get('email')
email = EmailMessage(
mail_subject, message, to=[to_email]
mail_subject, message, to=[to_email]
)
email.send()
return render(request, 'validate_mail_address_complete.html')

2
app/server/views.py

@ -90,7 +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),
'allow_signup': bool(settings.ALLOW_SIGNUP),
}
def get_context_data(self, **kwargs):

Loading…
Cancel
Save