diff --git a/accounts/settings.py b/accounts/settings.py index 016ef68..09fe3e4 100644 --- a/accounts/settings.py +++ b/accounts/settings.py @@ -45,6 +45,8 @@ INSTALLED_APPS = [ 'apps.wallet', 'apps.gooyal_oauth2', 'apps.superapp', + 'crispy_forms', + 'crispy_bootstrap5', ] MIDDLEWARE = [ @@ -194,6 +196,9 @@ STATIC_URL = '/static/' # CLIENT_ID = config('CLIENT_ID') # CLIENT_SECRET = config('CLIENT_SECRET') +CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5" +CRISPY_TEMPLATE_PACK = "bootstrap5" + CELERY_BROKER_URL = config('CELERY_BROKER_URL') SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') diff --git a/apps/users/forms.py b/apps/users/forms.py index c44d2f1..9a0afd2 100644 --- a/apps/users/forms.py +++ b/apps/users/forms.py @@ -82,3 +82,9 @@ class OTPAuthenticationForm(forms.Form): code='invalid_login', params={'phone_number': self.phone_number_field.verbose_name}, ) + + +class ProfileUpdateForm(forms.ModelForm): + class Meta: + model = UserModel + fields = ['name', 'first_name', 'last_name', 'email', 'iban', 'avatar'] diff --git a/apps/users/migrations/0002_user_email_verified.py b/apps/users/migrations/0002_user_email_verified.py new file mode 100644 index 0000000..1f38c2f --- /dev/null +++ b/apps/users/migrations/0002_user_email_verified.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1 on 2022-09-08 13:01 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='email_verified', + field=models.BooleanField(null=True), + ), + ] diff --git a/apps/users/models.py b/apps/users/models.py index 78cb7e0..d339ac8 100644 --- a/apps/users/models.py +++ b/apps/users/models.py @@ -67,6 +67,7 @@ class User(AbstractUser): first_name = models.CharField(_('first name'), max_length=30, blank=True) last_name = models.CharField(_('last name'), max_length=150, blank=True) email = models.EmailField(_('email address'), blank=True) + email_verified = models.BooleanField(null=True) # country = models.CharField(_('country'), max_length=50, blank=True, null=True) # province = models.CharField(_('province'), max_length=50, blank=True, null=True) diff --git a/apps/users/urls.py b/apps/users/urls.py index f96e414..6ea61db 100644 --- a/apps/users/urls.py +++ b/apps/users/urls.py @@ -1,14 +1,15 @@ from django.urls import path from django.contrib.auth.views import LogoutView from .views import UserListView, UserDetailView, AccountView, RequestOTPView, ChangePasswordView, \ - OTPLoginView, ProfileView + OTPLoginView, ProfileDetailView, ProfileUpdateView app_name = "users" urlpatterns = [ path('login/', OTPLoginView.as_view(), name='login'), path('logout/', LogoutView.as_view(), name='logout'), - path('profile/', ProfileView.as_view(), name='profile'), + path('profile/', ProfileDetailView.as_view(), name='profile_detail'), + path('profile/update/', ProfileUpdateView.as_view(), name='profile_update'), path('api/account/', AccountView.as_view(), name='account_api'), path('api/users/', UserListView.as_view(), name='user_list_api'), path('api/users//', UserDetailView.as_view(), name='user_detail_api'), diff --git a/apps/users/views.py b/apps/users/views.py index 8d6e6a0..d4162ce 100644 --- a/apps/users/views.py +++ b/apps/users/views.py @@ -2,6 +2,7 @@ from django.contrib.auth import get_user_model from django.contrib.auth.decorators import login_required from django.contrib.auth.views import LoginView from django.shortcuts import render +from django.urls import reverse from django.utils import timezone from django.utils.decorators import method_decorator from django.views.generic import DetailView, UpdateView @@ -11,7 +12,7 @@ from rest_framework.response import Response from rest_framework.views import APIView from apps.gooyal_oauth2.rest_framework import IsAuthenticatedOrTokenMatchesOASRequirements -from apps.users.forms import OTPAuthenticationForm +from apps.users.forms import OTPAuthenticationForm, ProfileUpdateForm from apps.users.models import User from apps.users.provinces_and_cities import State from apps.users.serializers import PublicUserSerializer, AccountSerializer, RequestOTPSerializer, \ @@ -106,7 +107,7 @@ class OTPLoginView(LoginView): @method_decorator(login_required, name='dispatch') -class ProfileView(DetailView): +class ProfileDetailView(DetailView): model = User template_name = 'users/profile_detail.html' pk_url_kwarg = 'uuid' @@ -116,10 +117,18 @@ class ProfileView(DetailView): @method_decorator(login_required, name='dispatch') -class ProfileUpdate(UpdateView): +class ProfileUpdateView(UpdateView): model = User template_name = 'users/profile_update.html' pk_url_kwarg = 'uuid' + form_class = ProfileUpdateForm + + def get_success_url(self): + return reverse('users:profile_update') def get_object(self, queryset=None): return self.request.user + + def form_valid(self, form): + return super().form_valid(form) + diff --git a/requirements.in b/requirements.in index 77af700..17941b1 100644 --- a/requirements.in +++ b/requirements.in @@ -14,4 +14,6 @@ gunicorn gevent redis celery -drf-spectacular \ No newline at end of file +drf-spectacular +django-crispy-forms +crispy_bootstrap5 diff --git a/requirements.txt b/requirements.txt index 0cb7911..976fce9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -34,6 +34,8 @@ click-plugins==1.1.1 # via celery click-repl==0.2.0 # via celery +crispy-bootstrap5==0.6 + # via -r requirements.in cryptography==37.0.4 # via jwcrypto deprecated==1.2.13 @@ -43,6 +45,7 @@ deprecated==1.2.13 django==4.1 # via # -r requirements.in + # crispy-bootstrap5 # django-cors-headers # django-filter # django-model-utils @@ -52,6 +55,10 @@ django==4.1 # drf-spectacular django-cors-headers==3.13.0 # via -r requirements.in +django-crispy-forms==1.14.0 + # via + # -r requirements.in + # crispy-bootstrap5 django-filter==22.1 # via -r requirements.in django-model-utils==4.2.0 diff --git a/templates/new_base.html b/templates/new_base.html new file mode 100755 index 0000000..c551dbb --- /dev/null +++ b/templates/new_base.html @@ -0,0 +1,39 @@ +{% load static %} + + + + + Login + + + + + + + + + + + + + +
+
+
+ {#
#} + {# #} + {#
#} +
+
+ {% block content %} + {% endblock %} +
+
+ + +
+
+
+ + + diff --git a/templates/users/profile_detail.html b/templates/users/profile_detail.html index 0af303c..433ce8e 100644 --- a/templates/users/profile_detail.html +++ b/templates/users/profile_detail.html @@ -1,4 +1,4 @@ -{% extends "base_generic.html" %} +{% extends "new_base.html" %} {% block content %} diff --git a/templates/users/profile_detail_old.html b/templates/users/profile_detail_old.html new file mode 100644 index 0000000..0af303c --- /dev/null +++ b/templates/users/profile_detail_old.html @@ -0,0 +1,9 @@ +{% extends "base_generic.html" %} + +{% block content %} + +

Homepage

+

Hello {{ user.username }}!

+

your phone number {{ user.phone_number }}!

+ +{% endblock %} \ No newline at end of file diff --git a/templates/users/profile_update.html b/templates/users/profile_update.html index 0af303c..3f9ed4c 100644 --- a/templates/users/profile_update.html +++ b/templates/users/profile_update.html @@ -1,9 +1,26 @@ {% extends "base_generic.html" %} +{% load crispy_forms_tags %} {% block content %} -

Homepage

-

Hello {{ user.username }}!

-

your phone number {{ user.phone_number }}!

+

update user profile

+
+ {% csrf_token %} +
+
+
+
+ {{ form|crispy }} +
+
+
+
+ +
+ {#
#} + {# #} + {#
#} +
+
{% endblock %} \ No newline at end of file