user profile update
This commit is contained in:
parent
ba6507c8f9
commit
7a6576fce1
12 changed files with 124 additions and 10 deletions
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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']
|
||||
|
|
|
|||
18
apps/users/migrations/0002_user_email_verified.py
Normal file
18
apps/users/migrations/0002_user_email_verified.py
Normal file
|
|
@ -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),
|
||||
),
|
||||
]
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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/<uuid>/', UserDetailView.as_view(), name='user_detail_api'),
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,3 +15,5 @@ gevent
|
|||
redis
|
||||
celery
|
||||
drf-spectacular
|
||||
django-crispy-forms
|
||||
crispy_bootstrap5
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
39
templates/new_base.html
Executable file
39
templates/new_base.html
Executable file
|
|
@ -0,0 +1,39 @@
|
|||
{% load static %}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Login</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'bootstrap-5.1.3-dist/css/bootstrap.min.css' %}">
|
||||
<link href="{% static 'bootstrap-icons-1.7.2/bootstrap-icons.css' %}" rel="stylesheet">
|
||||
<script src="{% static 'jquery-3.6.0.min.js' %}"></script>
|
||||
<script src="{% static 'bootstrap-5.1.3-dist/js/bootstrap.bundle.min.js' %}"></script>
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'login/css/util.css' %}">
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'login/css/main.css' %}">
|
||||
<link href="{% static 'fonts.css' %}" rel="stylesheet">
|
||||
<link href="{% static 'main.css' %}" rel="stylesheet">
|
||||
<!--===============================================================================================-->
|
||||
</head>
|
||||
<body>
|
||||
<div class="limiter">
|
||||
<div class="container-login100">
|
||||
<div class="wrap-login100 p-t-50 p-b-90">
|
||||
{# <div class="text-center pb-5">#}
|
||||
{# <img src="{% static 'image/arian_saeed.png' %}" class="img-fluid">#}
|
||||
{# </div>#}
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
{% extends "base_generic.html" %}
|
||||
{% extends "new_base.html" %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
|
|
|
|||
9
templates/users/profile_detail_old.html
Normal file
9
templates/users/profile_detail_old.html
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{% extends "base_generic.html" %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h2>Homepage</h2>
|
||||
<p>Hello {{ user.username }}!</p>
|
||||
<p>your phone number {{ user.phone_number }}!</p>
|
||||
|
||||
{% endblock %}
|
||||
|
|
@ -1,9 +1,26 @@
|
|||
{% extends "base_generic.html" %}
|
||||
{% load crispy_forms_tags %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h2>Homepage</h2>
|
||||
<p>Hello {{ user.username }}!</p>
|
||||
<p>your phone number {{ user.phone_number }}!</p>
|
||||
<h2>update user profile</h2>
|
||||
<form action="{{ request.get_full_path }}" method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
<div class="row g-3">
|
||||
<div class="col-md-12 col-lg-12 mb-3" id="formset">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
{{ form|crispy }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<input class="w-100 btn btn-primary btn-lg" type="submit" value="ثبت" name="save"/>
|
||||
</div>
|
||||
{# <div class="col-6">#}
|
||||
{# <input class="w-100 btn btn-primary btn-lg" type="submit" value="انتشار" name="publish"/>#}
|
||||
{# </div>#}
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
Loading…
Add table
Reference in a new issue