Skip to content

Commit

Permalink
update registration
Browse files Browse the repository at this point in the history
  • Loading branch information
BenediktMKuehne committed Oct 25, 2024
1 parent 8757321 commit a0b2dd5
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 113 deletions.
1 change: 1 addition & 0 deletions embark/dashboard/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

# view routing
urlpatterns = [
path('', views.main_dashboard, name='embark-MainDashboard'),
path('dashboard/main/', views.main_dashboard, name='embark-MainDashboard'),
path('dashboard/service/', views.service_dashboard, name='embark-dashboard-service'),
path('dashboard/report/', views.report_dashboard, name='embark-ReportDashboard'),
Expand Down
17 changes: 11 additions & 6 deletions embark/embark/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@

SESSION_COOKIE_SAMESITE = 'Strict'
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_SECURE = False

WSGI_APPLICATION = 'embark.wsgi.application'

Expand Down Expand Up @@ -187,16 +188,19 @@

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
"OPTIONS": {
"min_length": 8,
},
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]

Expand Down Expand Up @@ -226,10 +230,10 @@
# STATICFILES_FINDERS

# URL of Login-Page
LOGIN_URL = ''
LOGIN_URL = 'user/login/'

# URL of Logout-Page
LOGOUT_REDIRECT_URL = ''
LOGOUT_REDIRECT_URL = 'user/logout'

# Added for FIle storage to get the path to save Firmware images.
MEDIA_ROOT = os.path.join(BASE_DIR.parent, 'media')
Expand Down Expand Up @@ -272,6 +276,7 @@
},
},
}
# TODO check this https://docs.djangoproject.com/en/5.1/topics/cache/
TEMP_DIR = Path("/tmp/")

try:
Expand Down
30 changes: 15 additions & 15 deletions embark/templates/user/accountDelete.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
{% block maincontent %}

<div class="auth-wrapper">
<form action="{% url 'embark-acc-delete' %}" method="post" novalidate>
<div class="box box-primary">
<div class="box-header">
<h2 class="page-header"><i class="fa fa-lock"></i> Permanently delete my Account </h2>
</div>
<div class="box box-body-second">
<p>Are you sure you want to permanently delete your account?</p>
</div>
<div class="btn-cnt">
<p>
<button class="btn-reset" type="submit" name="DeleteAcc">Delete Account</button>
</p>
</div>
</div>
</form>
<form action="{% url 'embark-acc-delete' %}" method="post" novalidate>
<div class="box box-primary">
<div class="box-header">
<h2 class="page-header"><i class="fa fa-lock"></i> Permanently delete my Account </h2>
</div>
<div class="box box-body-second">
<p>Are you sure you want to permanently delete your account?</p>
</div>
<div class="btn-cnt">
<p>
<button class="btn-reset" type="submit" name="DeleteAcc">Delete Account</button>
</p>
</div>
</div>
</form>
</div>

{% endblock maincontent %}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Dear {{ username }},

Please follow the link to confirm your registration,
http://{{ domain }}{% url 'activate' user_id=uid activation_token=token %}
http://{{ domain }}{% url 'embark-activate-user' user_id=uid token=token %}

OR manually input the following token: {{ token }}
{% endautoescape %}
8 changes: 8 additions & 0 deletions embark/templates/user/email_template_deactivation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% autoescape off %}
Dear {{ username }},

Please follow the link to confirm the account deletion,
http://{{ domain }}{% url 'embark-deactivate-user' user_id=uid activation_token=token %}

OR manually input the following token: {{ token }}
{% endautoescape %}
8 changes: 8 additions & 0 deletions embark/templates/user/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@

{% block navigation %}{% include "navigation.html" %}{% endblock navigation %}
{% block maincontent %}
{% if user.is_staff %}
<div class="d-flex justify-content-center">
<h3><span class="badge bg-secondary"><a href="{% url 'admin:index' %}">
<input class="solid btn-login" type="submit" value="Admin-page" />
</a></span></h3>

</div>
{% endif %}
<div class="container-fluid">
{% block timezone %}{% include "user/timezone.html" %}{% endblock timezone %}
</div>
Expand Down
22 changes: 11 additions & 11 deletions embark/templates/user/login.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% 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 login{% endblock title %}
{% block maincontent %}
Expand All @@ -15,24 +16,23 @@ <h2><span class="badge bg-primary">New</span> Version 0.1</h2>
<h3><span class="badge bg-secondary">New</span> New Buttons everywhere</h3>
</div>
<div class="login">
<form action="{% url 'embark-login' %}" class="login-form" method="post">
{% csrf_token %}
<form action="{% url 'embark-login' %}" class="login-form" method="post" novalidate>
<h2 class="title">Sign in</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>
<input id="loginButton" type="submit" class="solid btn-login" value="Login" />
{% csrf_token %}
{% for field in form %}
{% bootstrap_field field %}
{% endfor %}
<input id="loginButton" type="submit" class="solid btn-login" value="login" />
</form>
</div>
<div id="login_footer">
<a href="{% url 'embark-password-reset' %}">
<input class="solid btn-login" type="submit" value="Lost Password?" />
</a>
<a href="{% url 'embark-register' %}">
<input class="solid btn-login" type="submit" value="Register" />
</a>
</div>

</div>
{% endblock maincontent %}
4 changes: 2 additions & 2 deletions embark/templates/user/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
{% block maincontent %}
<div class="login-form-container">
<div id="embarkLogo"><img src="{% static 'content/images/embark_logo.svg' %}" alt="EMBArk logo graphic" height="auto" width="auto"/></div>
<form action="{% url 'embark-register' %}" class="register-form" method="post" novalidate>
<form action="{% url 'embark-register' %}" class="register-form" method="post">
{% csrf_token %}
{% for field in signup_form %}
{% for field in form %}
{% bootstrap_field field %}
{% endfor %}
<input id="loginButton" type="submit" class="solid btn-login" value="Register" />
Expand Down
40 changes: 34 additions & 6 deletions embark/users/forms.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import password_validation
from django.contrib.auth.validators import UnicodeUsernameValidator
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
from users.models import User


class SignupForm(UserCreationForm):
username_validator = UnicodeUsernameValidator()


class SignUpForm(UserCreationForm):
first_name = forms.CharField(max_length=12, min_length=4, required=False, help_text='Optional: First Name',
widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'First Name'}))
last_name = forms.CharField(max_length=12, min_length=4, required=False, help_text='Optional: Last Name',
widget=(forms.TextInput(attrs={'class': 'form-control'})))
email = forms.EmailField(max_length=50, help_text='Required. Inform a valid email address.',
widget=(forms.TextInput(attrs={'class': 'form-control'})))
password1 = forms.CharField(label='Password',
widget=(forms.PasswordInput(attrs={'class': 'form-control'})),
help_text=password_validation.password_validators_help_text_html())
password2 = forms.CharField(label='Password Confirmation', widget=forms.PasswordInput(attrs={'class': 'form-control'}),
help_text='Just Enter the same password, for confirmation')
username = forms.CharField(
label='Username',
max_length=150,
help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.',
validators=[username_validator],
error_messages={'unique': "A user with that username already exists."},
widget=forms.TextInput(attrs={'class': 'form-control'})
)
usable_password = None
class Meta:
model = User
fields = ('username', 'email', 'password1', 'password2')

fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2',)

class ActivationForm(forms.Form):

token = forms.CharField(max_length=256, min_length=256)
class LoginForm(AuthenticationForm):
error_messages = {
"invalid_login": "Please enter a correct %(username)s and password. Note that both fields may be case-sensitive.",
"inactive": "This account is not yet activated",
"deactivated": "Account was deactivated",
}
1 change: 1 addition & 0 deletions embark/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Team(models.Model):

class User(AbstractUser):
timezone = models.CharField(max_length=32, choices=settings.TIMEZONES, default='UTC')
email = models.EmailField(verbose_name="email address", blank=True, unique=True)


class TeamMember(models.Model):
Expand Down
13 changes: 7 additions & 6 deletions embark/users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
urlpatterns = [
path(settings.LOGIN_URL, views.embark_login, name='embark-login'),
path('user/', views.user_main, name='embark-user-main'),
path('register/', views.register, name='embark-register'),
path('register/activate/<uuid:user_id>/', views.register, name='embark-activate-user'),
path('logout/', views.embark_logout, name='embark-logout'),
path('user/register/', views.register, name='embark-register'),
path('user/<int:user_id>/activate/<str:token>', views.activate, name='embark-activate-user'),
path('user/reset_password/', views.reset_password, name='embark-password-reset'),
path(settings.LOGOUT_REDIRECT_URL, views.embark_logout, name='embark-logout'),
path('user/password_change/', views.password_change, name='embark-password-change'),
path('user/acc_delete/', views.acc_delete, name='embark-acc-delete'),
path('user/delete/', views.acc_delete, name='embark-acc-delete'),
path('user/<int:user_id>/deactivate', views.deactivate, name='embark-deactivate-user'),
path('user/set_timezone/', views.set_timezone, name='embark-acc-timezone'),
# TODO account menu path('my-account/', views., name='embark-), for admin options etc
path('log/<int:log_type>/<int:lines>/', views.get_log, name='log'),
path('log/<int:log_type>/<int:lines>/', views.get_log, name='log'), # TODO move to admin
]
Loading

0 comments on commit a0b2dd5

Please sign in to comment.