Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BenediktMKuehne committed Oct 31, 2024
1 parent 2a470d9 commit 201e1cc
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 69 deletions.
37 changes: 18 additions & 19 deletions embark/templates/user/lostPassword.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
{% endblock style %}
{% block title %}Reset Lost Password{% endblock title %}
{% block maincontent %}
<div class="password-change-container">
{% if email_setting %}
<div class="reset">
<div class="password-change-container">
{% if email_setting %}
<div class="reset">
<form action="{% url 'embark-password-reset' %}" class="password-reset-form" method="post" novalidate>
<h2 class="title">Reset Password</h2>
{% csrf_token %}
Expand All @@ -18,20 +18,19 @@ <h2 class="title">Reset Password</h2>
{% endfor %}
<input id="loginButton" type="submit" class="solid btn-reset" value="reset" />
</form>

<div id="login_footer">
<a href="{% url 'embark-login' %}">
<input class="solid btn-login" type="submit" value="Login" />
</a>
</div>
{% else %}
<div class="d-flex justify-content-center">
<h1>
Contact your Admin
{{ admin_email }}
</h1>
</div>
{% endif %}

</div>
<div id="login_footer">
<a href="{% url 'embark-login' %}">
<input class="solid btn-login" type="submit" value="Login" />
</a>
</div>
</div>
{% else %}
<div class="d-flex justify-content-center">
<h1>
Contact your Admin
{{ admin_email }}
</h1>
</div>
{% endif %}
</div>
{% endblock maincontent %}
2 changes: 1 addition & 1 deletion embark/templates/user/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% block title %}EMBArk register{% endblock title %}
{% 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>
<div id="embarkLogo"><img src="{% static 'content/images/embark_logo.svg' %}" alt="EMBArk logo graphic" height="auto" width="auto"/>
<form action="{% url 'embark-register' %}" class="register-form" method="post">
{% csrf_token %}
{% for field in form %}
Expand Down
2 changes: 1 addition & 1 deletion embark/tracker/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from django_tables2 import RequestConfig

from dashboard.models import Result, SoftwareInfo
from dashboard.models import Result
from embark.helper import rnd_rgb_color, rnd_rgb_full
from uploader.models import FirmwareAnalysis, Device, Vendor
from tracker.tables import SimpleDeviceTable, SimpleSBOMTable
Expand Down
7 changes: 3 additions & 4 deletions embark/users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
__license__ = 'MIT'

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.admin import UserAdmin, GroupAdmin

from users.models import User, Team, TeamMember
from users.models import User, Team

admin.site.register(User, UserAdmin)
admin.site.register(Team, UserAdmin)
admin.site.register(TeamMember, UserAdmin)
admin.site.register(Team, GroupAdmin)
51 changes: 37 additions & 14 deletions embark/users/forms.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,46 @@
# pylint: disable=R0901
__copyright__ = 'Copyright 2024 Siemens Energy AG'
__author__ = 'Benedikt Kuehne'
__license__ = 'MIT'

from django import forms
from django.contrib.auth import password_validation
from django.contrib.auth import password_validation
from django.contrib.auth.validators import UnicodeUsernameValidator
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm, PasswordResetForm

from users.models import User


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')
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,
Expand All @@ -29,17 +50,19 @@ class SignUpForm(UserCreationForm):
widget=forms.TextInput(attrs={'class': 'form-control'})
)
usable_password = None

class Meta:
model = User
fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2',)


class LoginForm(AuthenticationForm):
error_messages = {
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",
}


class ResetForm(PasswordResetForm):
pass
pass
17 changes: 5 additions & 12 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 AbstractUser
from django.contrib.auth.models import AbstractUser, Group
from django.conf import settings

from lib.choice_enum import ChoiceIntEnum
Expand All @@ -19,8 +19,7 @@ class Role(ChoiceIntEnum):
MANAGER = 3


class Team(models.Model):
name = models.CharField(max_length=150, unique=True, help_text='Name of the team')
class Team(Group):
is_active = models.BooleanField(default=True, help_text='Whether this Team is active or not')
created = models.DateTimeField(auto_now_add=True, help_text='Date time when this entry was created')
modified = models.DateTimeField(auto_now=True, help_text='Date time when this entry was modified')
Expand All @@ -29,12 +28,6 @@ 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):
team = models.ForeignKey(Team, on_delete=models.CASCADE, related_name='team_member')
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user_team_member')
role = models.IntegerField(choices=Role.choices(), default=Role.VIEWER)
is_active = models.BooleanField(default=True, help_text='Whether this team member is active or not')
created = models.DateTimeField(auto_now_add=True, help_text='Date time when this entry was created')
modified = models.DateTimeField(auto_now=True, help_text='Date time when this entry was modified')
team = models.ManyToManyField(Team, blank=True, related_name='member_of_team')
team_role = models.IntegerField(choices=Role.choices(), default=Role.VIEWER)
is_active_member = models.BooleanField(default=True, help_text='Whether this team member is active or not')
2 changes: 1 addition & 1 deletion embark/users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
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'),
path('log/<int:log_type>/<int:lines>/', views.get_log, name='log'), # TODO move to admin
path('log/<int:log_type>/<int:lines>/', views.get_log, name='log'), # TODO move to admin
]
31 changes: 15 additions & 16 deletions embark/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,18 @@ def register(request):
'domain': current_site.domain,
'uid': user.id,
'token': token,
})

if settings.EMAIL_ACTIVE == True:
})
if settings.EMAIL_ACTIVE is 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-activate-user', kwargs={'uuid':user.id}))
return redirect(reverse('embark-activate-user', kwargs={'uuid': user.id}))
else:
logger.debug("Registered, redirecting to login")
if activate_user(user, token):
messages.success(request, 'Registration successful.')
return redirect(reverse('embark-login'))
else:
raise Exception("Activation Error")
raise ValidationError("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.')
Expand Down Expand Up @@ -182,26 +181,26 @@ def acc_delete(request):
'domain': current_site.domain,
'uid': user.id,
'token': token,
})
if settings.EMAIL_ACTIVE == True:
})
if settings.EMAIL_ACTIVE is True:
send_mail(mail_subject, message, 'system@' + settings.DOMAIN, [email])
messages.success(request, 'Please check your email to confirm deletion')
return redirect(reverse('embark-deactivate-user', kwargs={'uuid':user.id}))
return redirect(reverse('embark-deactivate-user', kwargs={'uuid': user.id}))
else:
logger.debug(' %s Account: %s disabled', timezone.now().strftime("%H:%M:%S"), user)
user.username = user.get_username() + '_disactivated_' + timezone.now().strftime(
"%H:%M:%S") # workaround for not duplicating entry users_user.username
"%H:%M:%S") # workaround for not duplicating entry users_user.username
user.is_active = False
user.save()
messages.success(request, 'Account successfully deleted.')
return redirect('embark-login')
return render(request, 'user/accountDelete.html')


@require_http_methods(["POST"])
@login_required(login_url='/' + settings.LOGIN_URL)
def deactivate(request, uid):
pass
@require_http_methods(["GET"])
def deactivate(request, user_id): # TODO
logger.debug("deactivating user with id : %s", user_id)
return render(request, 'user/login.html')


@require_http_methods(["GET"])
Expand Down Expand Up @@ -290,7 +289,7 @@ def activate(request, user_id, token):
else:
messages.error(request, "Token invalid - maybe it expired?")
except ValueError as val_error:
logger.error(f"{val_error} in token {token}")
logger.error("%s in token %s", val_error, token)
return redirect(reverse('embark-MainDashboard'))


Expand All @@ -300,8 +299,8 @@ def reset_password(request):
reset_form = ResetForm(request.POST)
if reset_form.is_valid():
logger.debug('Form is valid')
reset_form.save(request=request)
messages.success(request,'Send Password reset request')
reset_form.save(request=request)
messages.success(request, 'Send Password reset request')
reset_form = ResetForm()
admin_email = User.objects.get(username='admin').email
return render(request, 'user/lostPassword.html', {'form': reset_form, 'email_setting': settings.EMAIL_ACTIVE, 'admin_email': admin_email})
3 changes: 2 additions & 1 deletion installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ save_old_env(){
}

write_env(){
local SUPER_PW="$(openssl rand -base64 8)"
local SUPER_PW=""
SUPER_PW="$(openssl rand -base64 8)"
local SUPER_EMAIL="[email protected]"
local SUPER_USER="admin"
local RANDOM_PW=""
Expand Down

0 comments on commit 201e1cc

Please sign in to comment.