From: Costantino Vitale Date: Thu, 29 Sep 2022 11:25:50 +0000 (+0200) Subject: Commit delle app X-Git-Url: https://git.atlas4tour.it/?a=commitdiff_plain;h=790ee13b0eb164a44a3892f8f3f32e995293f61a;p=pia_atlas.git Commit delle app --- diff --git a/api/admin.py b/api/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/api/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/api/apps.py b/api/apps.py new file mode 100644 index 0000000..66656fd --- /dev/null +++ b/api/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ApiConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'api' diff --git a/api/models.py b/api/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/api/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/api/tests.py b/api/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/api/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/api/urls.py b/api/urls.py new file mode 100644 index 0000000..fca688d --- /dev/null +++ b/api/urls.py @@ -0,0 +1,10 @@ +from django.contrib import admin +from django.urls import path, include +from django.contrib.auth import views as auth_views + +from api.views import Login_v2, RegistrationAPI + +urlpatterns = [ + path('api-login/', Login_v2.as_view(), name='api_login'), + path('api-registration/', RegistrationAPI.as_view(), name='api_registration'), +] diff --git a/api/views.py b/api/views.py new file mode 100644 index 0000000..a07eb90 --- /dev/null +++ b/api/views.py @@ -0,0 +1,124 @@ +from django.http import JsonResponse +from django.shortcuts import render +from django.utils.translation import ugettext as _ +from rest_framework import status +from django.contrib.auth import authenticate +from rest_framework import serializers +from rest_framework.response import Response +from rest_framework.views import APIView +from rest_framework_simplejwt.serializers import PasswordField +from rest_framework_simplejwt.tokens import RefreshToken +from rest_framework_simplejwt.views import TokenViewBase +from rest_framework_simplejwt.exceptions import AuthenticationFailed + + +class TokenObtainLoginSerializer(serializers.Serializer): + login = 'login' + + default_error_messages = { + 'no_active_account': _('Credenziali errate') + } + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + self.fields[self.login] = serializers.CharField() + self.fields['password'] = PasswordField() + + def validate(self, attrs): + authenticate_kwargs = { + self.login: attrs[self.login], + 'password': attrs['password'], + } + try: + authenticate_kwargs['request'] = self.context['request'] + except KeyError: + pass + + self.user = authenticate(**authenticate_kwargs) + + # Prior to Django 1.10, inactive users could be authenticated with the + # default `ModelBackend`. As of Django 1.10, the `ModelBackend` + # prevents inactive users from authenticating. App designers can still + # allow inactive users to authenticate by opting for the new + # `AllowAllUsersModelBackend`. However, we explicitly prevent inactive + # users from authenticating to enforce a reasonable policy and provide + # sensible backwards compatibility with older Django versions. + if self.user is None or not self.user.is_active: + raise AuthenticationFailed( + self.error_messages['no_active_account'], + 'no_active_account', + ) + + + return {} + + @classmethod + def get_token(cls, user): + raise NotImplementedError('Must implement `get_token` method for `TokenObtainSerializer` subclasses') + + +class TokenObtainPairLoginSerializer(TokenObtainLoginSerializer): + @classmethod + def get_token(cls, user): + return RefreshToken.for_user(user) + + def validate(self, attrs): + data = super().validate(attrs) + + refresh = self.get_token(self.user) + + data['refresh'] = str(refresh) + #data['access'] = str(refresh.access_token) + data['token'] = str(refresh.access_token) + data['change_password'] = self.user.change_password + if self.user.last_login: + data['last_login'] = self.user.last_login.strftime('%Y-%M-%d %H:%M:%S') + else: + data['last_login'] = None + data['gender'] = self.user.gender + data['birth_date'] = self.user.birth_date + data['pk'] = self.user.pk + + return data + + +class Login_v2(TokenViewBase): + """ + Takes a set of user credentials and returns an access and refresh JSON web + token pair to prove the authentication of those credentials. + """ + serializer_class = TokenObtainPairLoginSerializer + + +class RegistrationAPI(APIView): + from rest_framework import permissions + permission_classes = [ + permissions.AllowAny # Or anon users can't register + ] + + def post(self, request): + dataNascita = request.data['dataNascita'] + # users = User.objects.filter(fiscal_code=request.data['cf']) + users = 0 + + if users.count() > 0: + return Response({'errors': 'Utente già registrato', 'error': True, 'data': '','messages': ['KO']}, status=status.HTTP_400_BAD_REQUEST) + else: + # user = User() + # user.username = request.data['username'] + # user.first_name = request.data['nome'] + # user.last_name = request.data['cognome'] + # user.fiscal_code = request.data['cf'] + # user.email = request.data['email'] + # user.set_password(request.data['password']) + # user.gender = request.data['sesso'][0] + # dataNascita = dataNascita.replace('/','-') + # user.birth_date = timezone.datetime.strptime(dataNascita, '%Y-%m-%d') + # user.residential_address = request.data['domicilio'] + # user.permanent_address = request.data['residenza'] + # user.save() + # + # role = Role.objects.filter(name='Paziente').first() + + return Response({'errors': '', 'error': False, 'data': '', 'messages': ['OK']}, status=status.HTTP_200_OK) \ No newline at end of file diff --git a/frontend/static/admin/img/login-1.png b/frontend/static/admin/img/login-1.png deleted file mode 100644 index 063d84b..0000000 Binary files a/frontend/static/admin/img/login-1.png and /dev/null differ diff --git a/frontend/static/admin/img/login.png b/frontend/static/admin/img/login.png deleted file mode 100644 index d5aa849..0000000 Binary files a/frontend/static/admin/img/login.png and /dev/null differ diff --git a/frontend/static/admin/img/logo-farella-white.png b/frontend/static/admin/img/logo-farella-white.png deleted file mode 100644 index 159919a..0000000 Binary files a/frontend/static/admin/img/logo-farella-white.png and /dev/null differ diff --git a/frontend/static/admin/img/logo-farella.png b/frontend/static/admin/img/logo-farella.png deleted file mode 100644 index a441adb..0000000 Binary files a/frontend/static/admin/img/logo-farella.png and /dev/null differ diff --git a/frontend/static/assets/css/custom.css b/frontend/static/assets/css/custom.css index ac49ebb..07ae234 100755 --- a/frontend/static/assets/css/custom.css +++ b/frontend/static/assets/css/custom.css @@ -171,9 +171,7 @@ body { } body { - background: #f6f6f6 url("/static/admin/img/login-1.png") no-repeat right bottom; - background-attachment: fixed; - background-size: 20%; + } .bg-light { diff --git a/frontend/static/assets/img/logo-farella-horizontal-1.png b/frontend/static/assets/img/logo-farella-horizontal-1.png deleted file mode 100644 index 51cb7e9..0000000 Binary files a/frontend/static/assets/img/logo-farella-horizontal-1.png and /dev/null differ diff --git a/frontend/static/assets/img/logo-farella-horizontal.png b/frontend/static/assets/img/logo-farella-horizontal.png deleted file mode 100644 index bbadede..0000000 Binary files a/frontend/static/assets/img/logo-farella-horizontal.png and /dev/null differ diff --git a/frontend/static/assets/img/logo-farella-mini.png b/frontend/static/assets/img/logo-farella-mini.png deleted file mode 100644 index d4e1660..0000000 Binary files a/frontend/static/assets/img/logo-farella-mini.png and /dev/null differ diff --git a/frontend/static/assets/img/logo-farella-mobile.png b/frontend/static/assets/img/logo-farella-mobile.png deleted file mode 100644 index 1342727..0000000 Binary files a/frontend/static/assets/img/logo-farella-mobile.png and /dev/null differ diff --git a/frontend/static/assets/img/logo.png b/frontend/static/assets/img/logo.png old mode 100755 new mode 100644 diff --git a/frontend/static/assets/img/logo_prima_nota.png b/frontend/static/assets/img/logo_prima_nota.png deleted file mode 100644 index e9a1450..0000000 Binary files a/frontend/static/assets/img/logo_prima_nota.png and /dev/null differ diff --git a/frontend/static/assets/img/logo_stampa.png b/frontend/static/assets/img/logo_stampa.png deleted file mode 100644 index 158e6da..0000000 Binary files a/frontend/static/assets/img/logo_stampa.png and /dev/null differ diff --git a/frontend/static/assets/img/tratta_breve.jpg b/frontend/static/assets/img/tratta_breve.jpg deleted file mode 100644 index 1cf4d53..0000000 Binary files a/frontend/static/assets/img/tratta_breve.jpg and /dev/null differ diff --git a/frontend/static/assets/img/tratta_breve.png b/frontend/static/assets/img/tratta_breve.png deleted file mode 100644 index ddf711b..0000000 Binary files a/frontend/static/assets/img/tratta_breve.png and /dev/null differ diff --git a/frontend/static/assets/img/tratta_lunga.jpg b/frontend/static/assets/img/tratta_lunga.jpg deleted file mode 100644 index be1eb05..0000000 Binary files a/frontend/static/assets/img/tratta_lunga.jpg and /dev/null differ diff --git a/frontend/static/assets/img/tratta_lunga.png b/frontend/static/assets/img/tratta_lunga.png deleted file mode 100644 index 1a56eeb..0000000 Binary files a/frontend/static/assets/img/tratta_lunga.png and /dev/null differ diff --git a/frontend/templates/base.html b/frontend/templates/base.html index 0dce525..caf29b5 100644 --- a/frontend/templates/base.html +++ b/frontend/templates/base.html @@ -7,16 +7,14 @@ - Farella Trasporti + Socoin Atlas - + - - + @@ -38,7 +36,6 @@ integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"> - @@ -83,6 +80,8 @@ + + -