Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BenediktMKuehne committed Oct 24, 2024
1 parent 6509735 commit a1faeac
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 32 deletions.
31 changes: 6 additions & 25 deletions embark/templates/user/register.html
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
{% extends "base.html" %}
{% load static %}
{% load django_bootstrap5 %}
{% block style %}<link rel="stylesheet" type="text/css" href="{% static 'content/css/login.css' %}"/>{% endblock style %}
{% block title %}EMBArk register{% endblock title %}
{% block maincontent %}
<div class="login-form-container">
{% if error_message %}
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<medium>{{ message }}</medium>
</div>
{% endif %}
{% if success_message %}
<div class="alert alert-success alert-dismissible fade show" role="alert">
<medium>{{ message }}</medium>
</div>
{% endif %}
<div id="embarkLogo"><img src="{% static 'content/images/embark_logo.svg' %}" alt="EMBArk logo graphic" height="auto" width="auto"/></div>
<div class="login">
<form action="{% url 'embark-register' %}" class="login-form" method="post" novalidate>
<h2 class="title">Register</h2>
<div class="input-field" data-error="Username is required">
<svg viewBox="0 -2 25 25" xmlns="http://www.w3.org/2000/svg"><path d="m7.5.5c1.65685425 0 3 1.34314575 3 3v2c0 1.65685425-1.34314575 3-3 3s-3-1.34314575-3-3v-2c0-1.65685425 1.34314575-3 3-3zm7 14v-.7281753c0-3.1864098-3.6862915-5.2718247-7-5.2718247s-7 2.0854149-7 5.2718247v.7281753c0 .5522847.44771525 1 1 1h12c.5522847 0 1-.4477153 1-1z" fill="none" stroke="#000" stroke-linecap="round" stroke-linejoin="round" transform="translate(3 2)"/></svg>
<input type="text" placeholder="Username" name="username" required/>
</div>
<div class="input-field">
<svg viewBox="0 -2 25 25" xmlns="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd" transform="translate(4 1)"><path d="m2.5 8.5-.00586729-1.99475098c-.00728549-4.00349935 1.32800361-6.00524902 4.00586729-6.00524902s4.0112203 2.00174967 4.0000699 6.00524902v1.99475098m-8.0000699 0h8.0225317c1.0543618 0 1.9181652.81587779 1.9945143 1.8507377l.0054778.1548972-.0169048 6c-.0031058 1.1023652-.8976224 1.9943651-1.999992 1.9943651h-8.005627c-1.1045695 0-2-.8954305-2-2v-6c0-1.1045695.8954305-2 2-2z" stroke="#000" stroke-linecap="round" stroke-linejoin="round"/><circle cx="6.5" cy="13.5" fill="#000" r="1.5"/></g></svg>
<input type="password" placeholder="Password" name="password" required/>
</div>
<div class="input-field">
<svg viewBox="0 -2 25 25" xmlns="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd" transform="translate(4 1)"><path d="m2.5 8.5-.00586729-1.99475098c-.00728549-4.00349935 1.32800361-6.00524902 4.00586729-6.00524902s4.0112203 2.00174967 4.0000699 6.00524902v1.99475098m-8.0000699 0h8.0225317c1.0543618 0 1.9181652.81587779 1.9945143 1.8507377l.0054778.1548972-.0169048 6c-.0031058 1.1023652-.8976224 1.9943651-1.999992 1.9943651h-8.005627c-1.1045695 0-2-.8954305-2-2v-6c0-1.1045695.8954305-2 2-2z" stroke="#000" stroke-linecap="round" stroke-linejoin="round"/><circle cx="6.5" cy="13.5" fill="#000" r="1.5"/></g></svg>
<input type="password" placeholder="Confirm password" name="confirm_password" required/>
</div>
<form action="{% url 'embark-register' %}" class="register-form" method="post" novalidate>
{% csrf_token %}
{% for field in signup_form %}
{% bootstrap_field field %}
{% endfor %}
<input id="loginButton" type="submit" class="solid btn-login" value="Register" />
</form>
</div>
Expand Down
4 changes: 2 additions & 2 deletions embark/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import enum

from django.db import models
from django.contrib.auth.models import User as DjangoUser
from django.contrib.auth.models import AbstractUser
from django.conf import settings

from lib.choice_enum import ChoiceIntEnum
Expand All @@ -26,7 +26,7 @@ class Team(models.Model):
modified = models.DateTimeField(auto_now=True, help_text='Date time when this entry was modified')


class User(DjangoUser):
class User(AbstractUser):
timezone = models.CharField(max_length=32, choices=settings.TIMEZONES, default='UTC')


Expand Down
13 changes: 8 additions & 5 deletions embark/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def register(request):
user.is_active = False
user.save()
logger.debug('User created')
# TODO create email + token
token = default_token_generator.make_token(user)
current_site = get_current_site(request)
mail_subject = 'Activate your EMBArk account.'
Expand All @@ -62,18 +61,22 @@ def register(request):
'token': token,
})

if settings.EMAIL_ACTIVE:
if settings.EMAIL_ACTIVE == True:
send_mail(mail_subject, message, 'system@' + settings.DOMAIN, [email])
messages.success(request, 'Registration successful. Please check your email to activate')
return redirect(reverse('embark-login'))
else:
logger.debug("Registered, redirecting to login")
activate_user(user.id, token)
if activate_user(user.id, token):
messages.success(request, 'Registration successful.')
return redirect(reverse('embark-login'))
else:
raise Exception("Activation Error")
except builtins.Exception as error:
logger.exception('Wide exception in Signup: %s', error)
messages.error(request, 'Something went wrong when signing up the user.')
return render(request, 'user/register.html')
return render(request, 'user/register.html')
register_form = SignupForm()
return render(request, 'user/register.html', {'signup_form': register_form})


@require_http_methods(["GET", "POST"])
Expand Down

0 comments on commit a1faeac

Please sign in to comment.