diff --git a/vagus/template/index.html b/vagus/template/index.html
index 5dac01b..9976360 100755
--- a/vagus/template/index.html
+++ b/vagus/template/index.html
@@ -10,6 +10,7 @@
+
diff --git a/vagus/template/users/register.html b/vagus/template/users/register.html
new file mode 100755
index 0000000..b2d8f9f
--- /dev/null
+++ b/vagus/template/users/register.html
@@ -0,0 +1,41 @@
+{% extends 'index.html' %}
+{% load static %}
+
+{% block content %}
+
+
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/vagus/users/__pycache__/admin.cpython-37.pyc b/vagus/users/__pycache__/admin.cpython-37.pyc
index 9fe3d05..1b193de 100755
Binary files a/vagus/users/__pycache__/admin.cpython-37.pyc and b/vagus/users/__pycache__/admin.cpython-37.pyc differ
diff --git a/vagus/users/__pycache__/forms.cpython-37.pyc b/vagus/users/__pycache__/forms.cpython-37.pyc
index 1f7197a..824e5d8 100755
Binary files a/vagus/users/__pycache__/forms.cpython-37.pyc and b/vagus/users/__pycache__/forms.cpython-37.pyc differ
diff --git a/vagus/users/__pycache__/models.cpython-37.pyc b/vagus/users/__pycache__/models.cpython-37.pyc
index 9560114..75c7f42 100755
Binary files a/vagus/users/__pycache__/models.cpython-37.pyc and b/vagus/users/__pycache__/models.cpython-37.pyc differ
diff --git a/vagus/users/__pycache__/urls.cpython-37.pyc b/vagus/users/__pycache__/urls.cpython-37.pyc
index 02ab3c3..982904e 100755
Binary files a/vagus/users/__pycache__/urls.cpython-37.pyc and b/vagus/users/__pycache__/urls.cpython-37.pyc differ
diff --git a/vagus/users/__pycache__/views.cpython-37.pyc b/vagus/users/__pycache__/views.cpython-37.pyc
index 076411f..2ec2f8a 100755
Binary files a/vagus/users/__pycache__/views.cpython-37.pyc and b/vagus/users/__pycache__/views.cpython-37.pyc differ
diff --git a/vagus/users/admin.py b/vagus/users/admin.py
index 5694c0c..789e208 100755
--- a/vagus/users/admin.py
+++ b/vagus/users/admin.py
@@ -1,13 +1,10 @@
from django.contrib import admin
-from .models import Base_User, OwnerUser, NormalUser
+from .models import Base_User, OwnerUser
from .forms import CustomUserCreationForm, CustomUserChangeForm
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import Group
-class NormalUserInline(admin.StackedInline):
- model = NormalUser
- can_delete = False
- verbose_name_plural = 'Normal user'
+
class OwnerUserInLine(admin.StackedInline):
model = OwnerUser
@@ -20,17 +17,17 @@ class CustomUserAdmin(UserAdmin):
form = CustomUserChangeForm
model = Base_User
- inlines = (NormalUserInline,OwnerUserInLine)
+ inlines = [OwnerUserInLine,]
list_display = ('id','email', "is_staff", "is_active","is_superuser",'status')
fieldsets = (
- (None, {'fields': ('email','phone','first_name','last_name', 'password','status','avatar')}),
+ (None, {'fields': ('email','first_name','last_name', 'password','status','avatar')}),
('Permissions', {'fields': ('is_staff', 'is_active',)}),
)
add_fieldsets = (
(None, {
'classes': ('wide',),
- 'fields': ('email','phone','first_name','last_name', 'password1', 'password2', 'is_staff', 'is_active','status','avatar')}
+ 'fields': ('email','first_name','last_name', 'password1', 'password2', 'is_staff', 'is_active','status','avatar')}
),
)
ordering = ('email',)
diff --git a/vagus/users/forms.py b/vagus/users/forms.py
index 063b27d..4bb3f12 100755
--- a/vagus/users/forms.py
+++ b/vagus/users/forms.py
@@ -6,17 +6,20 @@ from .models import Base_User
class CustomUserCreationForm(UserCreationForm):
- phone = PhoneNumberField()
+ email = forms.EmailField(max_length=254,)
+
class Meta(UserCreationForm):
model = Base_User
- fields =['email','password','phone']
+ fields =['email','first_name','last_name','avatar']
-
class CustomUserChangeForm(UserChangeForm):
- phone = PhoneNumberField()
class Meta:
model = Base_User
- fields = ['email','password','phone']
+ fields = ['email','first_name','last_name','avatar']
-
\ No newline at end of file
+class LoginForm(forms.Form):
+
+ class Meta:
+ model = Base_User
+ fields = ['email','password']
\ No newline at end of file
diff --git a/vagus/users/migrations/0001_initial.py b/vagus/users/migrations/0001_initial.py
index 3ccb536..b7f931d 100755
--- a/vagus/users/migrations/0001_initial.py
+++ b/vagus/users/migrations/0001_initial.py
@@ -1,4 +1,4 @@
-# Generated by Django 3.1.3 on 2021-01-09 19:40
+# Generated by Django 3.1.3 on 2021-02-05 14:58
from django.conf import settings
from django.db import migrations, models
@@ -22,10 +22,13 @@ class Migration(migrations.Migration):
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('id', models.AutoField(primary_key=True, serialize=False)),
('email', models.EmailField(max_length=254, unique=True, verbose_name='Email')),
+ ('first_name', models.CharField(default='', max_length=30, verbose_name='First Name')),
+ ('last_name', models.CharField(default='', max_length=30, verbose_name='Last name')),
+ ('avatar', models.ImageField(blank=True, null=True, upload_to='media/avatars')),
('is_staff', models.BooleanField(default=False)),
('is_active', models.BooleanField(default=True)),
('date_joined', models.DateTimeField(auto_now_add=True, verbose_name='Date joined')),
- ('status', models.CharField(choices=[('Company_Account', 'Company account'), ('Regular_Account', 'Regular account'), ('Need_verification', 'Wait for verification'), ('BaseAcc', 'Base account'), ('Moderaotr', 'Moderator')], default='BaseAcc', max_length=32)),
+ ('status', models.CharField(choices=[('Company_Account', 'Company account'), ('Regular_Account', 'Regular account'), ('Need_verification', 'Wait for verification'), ('BaseAcc', 'Base account'), ('Moderator', 'Moderator')], default='BaseAcc', max_length=32)),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
],
@@ -38,8 +41,6 @@ class Migration(migrations.Migration):
name='OwnerUser',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
- ('first_name', models.CharField(max_length=30, verbose_name='First Name')),
- ('last_name', models.CharField(max_length=30, verbose_name='Last name')),
('company_name', models.CharField(blank=True, max_length=30, verbose_name='Company name')),
('user', models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
@@ -48,8 +49,6 @@ class Migration(migrations.Migration):
name='NormalUser',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
- ('first_name', models.CharField(max_length=30, verbose_name='First Name')),
- ('last_name', models.CharField(max_length=30, verbose_name='Last name')),
('birth_date', models.DateField(blank=True, null=True, verbose_name='Birth date')),
('user', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
diff --git a/vagus/users/migrations/0002_auto_20210114_1136.py b/vagus/users/migrations/0002_auto_20210114_1136.py
deleted file mode 100755
index ff21769..0000000
--- a/vagus/users/migrations/0002_auto_20210114_1136.py
+++ /dev/null
@@ -1,39 +0,0 @@
-# Generated by Django 3.1.3 on 2021-01-14 11:36
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('users', '0001_initial'),
- ]
-
- operations = [
- migrations.RemoveField(
- model_name='normaluser',
- name='first_name',
- ),
- migrations.RemoveField(
- model_name='normaluser',
- name='last_name',
- ),
- migrations.RemoveField(
- model_name='owneruser',
- name='first_name',
- ),
- migrations.RemoveField(
- model_name='owneruser',
- name='last_name',
- ),
- migrations.AddField(
- model_name='base_user',
- name='first_name',
- field=models.CharField(default='', max_length=30, verbose_name='First Name'),
- ),
- migrations.AddField(
- model_name='base_user',
- name='last_name',
- field=models.CharField(default='', max_length=30, verbose_name='Last name'),
- ),
- ]
diff --git a/vagus/users/migrations/0002_auto_20210205_1512.py b/vagus/users/migrations/0002_auto_20210205_1512.py
new file mode 100755
index 0000000..f9e26f2
--- /dev/null
+++ b/vagus/users/migrations/0002_auto_20210205_1512.py
@@ -0,0 +1,21 @@
+# Generated by Django 3.1.3 on 2021-02-05 15:12
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('users', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='base_user',
+ name='status',
+ field=models.CharField(choices=[('Company_Account', 'Company account'), ('Need_verification', 'Wait for verification'), ('BaseAcc', 'Base account'), ('Moderator', 'Moderator')], default='BaseAcc', max_length=32),
+ ),
+ migrations.DeleteModel(
+ name='NormalUser',
+ ),
+ ]
diff --git a/vagus/users/migrations/0003_base_user_avatar.py b/vagus/users/migrations/0003_base_user_avatar.py
deleted file mode 100755
index 93be0fc..0000000
--- a/vagus/users/migrations/0003_base_user_avatar.py
+++ /dev/null
@@ -1,18 +0,0 @@
-# Generated by Django 3.1.3 on 2021-01-14 11:37
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('users', '0002_auto_20210114_1136'),
- ]
-
- operations = [
- migrations.AddField(
- model_name='base_user',
- name='avatar',
- field=models.ImageField(blank=True, null=True, upload_to='media/avatars'),
- ),
- ]
diff --git a/vagus/users/migrations/0004_auto_20210114_2051.py b/vagus/users/migrations/0004_auto_20210114_2051.py
deleted file mode 100755
index df39c0e..0000000
--- a/vagus/users/migrations/0004_auto_20210114_2051.py
+++ /dev/null
@@ -1,18 +0,0 @@
-# Generated by Django 3.1.3 on 2021-01-14 20:51
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('users', '0003_base_user_avatar'),
- ]
-
- operations = [
- migrations.AlterField(
- model_name='base_user',
- name='status',
- field=models.CharField(choices=[('Company_Account', 'Company account'), ('Regular_Account', 'Regular account'), ('Need_verification', 'Wait for verification'), ('BaseAcc', 'Base account'), ('Moderator', 'Moderator')], default='BaseAcc', max_length=32),
- ),
- ]
diff --git a/vagus/users/migrations/0005_base_user_phone.py b/vagus/users/migrations/0005_base_user_phone.py
deleted file mode 100755
index 4578eb5..0000000
--- a/vagus/users/migrations/0005_base_user_phone.py
+++ /dev/null
@@ -1,19 +0,0 @@
-# Generated by Django 3.1.3 on 2021-01-26 19:13
-
-from django.db import migrations
-import phonenumber_field.modelfields
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('users', '0004_auto_20210114_2051'),
- ]
-
- operations = [
- migrations.AddField(
- model_name='base_user',
- name='phone',
- field=phonenumber_field.modelfields.PhoneNumberField(blank=True, default='', max_length=128, null=True, region=None, unique=True),
- ),
- ]
diff --git a/vagus/users/migrations/0006_auto_20210128_1355.py b/vagus/users/migrations/0006_auto_20210128_1355.py
deleted file mode 100755
index 16ba289..0000000
--- a/vagus/users/migrations/0006_auto_20210128_1355.py
+++ /dev/null
@@ -1,19 +0,0 @@
-# Generated by Django 3.1.3 on 2021-01-28 13:55
-
-from django.db import migrations
-import phonenumber_field.modelfields
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('users', '0005_base_user_phone'),
- ]
-
- operations = [
- migrations.AlterField(
- model_name='base_user',
- name='phone',
- field=phonenumber_field.modelfields.PhoneNumberField(default='', max_length=128, region=None, unique=True),
- ),
- ]
diff --git a/vagus/users/migrations/__pycache__/0001_initial.cpython-37.pyc b/vagus/users/migrations/__pycache__/0001_initial.cpython-37.pyc
index dca9659..e2a9749 100755
Binary files a/vagus/users/migrations/__pycache__/0001_initial.cpython-37.pyc and b/vagus/users/migrations/__pycache__/0001_initial.cpython-37.pyc differ
diff --git a/vagus/users/migrations/__pycache__/0002_auto_20210205_1512.cpython-37.pyc b/vagus/users/migrations/__pycache__/0002_auto_20210205_1512.cpython-37.pyc
new file mode 100755
index 0000000..4c37b95
Binary files /dev/null and b/vagus/users/migrations/__pycache__/0002_auto_20210205_1512.cpython-37.pyc differ
diff --git a/vagus/users/migrations/__pycache__/0007_remove_base_user_phone.cpython-37.pyc b/vagus/users/migrations/__pycache__/0007_remove_base_user_phone.cpython-37.pyc
new file mode 100755
index 0000000..56bf7fa
Binary files /dev/null and b/vagus/users/migrations/__pycache__/0007_remove_base_user_phone.cpython-37.pyc differ
diff --git a/vagus/users/migrations/__pycache__/__init__.cpython-37.pyc b/vagus/users/migrations/__pycache__/__init__.cpython-37.pyc
index 3a6be25..d5e9c91 100755
Binary files a/vagus/users/migrations/__pycache__/__init__.cpython-37.pyc and b/vagus/users/migrations/__pycache__/__init__.cpython-37.pyc differ
diff --git a/vagus/users/models.py b/vagus/users/models.py
index 83678eb..fc8be1f 100755
--- a/vagus/users/models.py
+++ b/vagus/users/models.py
@@ -6,7 +6,6 @@ from django.utils.translation import gettext_lazy as _
STATUS =(
('Company_Account', _('Company account')),
- ('Regular_Account',_('Regular account')),
('Need_verification', _("Wait for verification")),
('BaseAcc',_('Base account')),
('Moderator',_('Moderator')),
@@ -42,7 +41,6 @@ class UserManager(BaseUserManager):
class Base_User(AbstractBaseUser,PermissionsMixin):
id = models.AutoField(primary_key= True)
email = models.EmailField(_('Email'), unique= True)
- phone = PhoneNumberField(null = False, blank = False, unique = True, default = '')
avatar = models.ImageField(upload_to='media/avatars', null = True, blank = True,default='media/avatars/default.png')
first_name = models.CharField(_('First Name'), max_length=30, blank = False, default = '')
@@ -54,7 +52,6 @@ class Base_User(AbstractBaseUser,PermissionsMixin):
is_active = models.BooleanField(default=True)
date_joined = models.DateTimeField(_('Date joined'),auto_now_add=True)
- #last_login = models.DateTimeField(_("Last Login"),auto_now_add= Tr )
status = models.CharField(max_length=32, choices=STATUS, default='BaseAcc')
USERNAME_FIELD = 'email'
@@ -67,13 +64,6 @@ class Base_User(AbstractBaseUser,PermissionsMixin):
class Meta:
verbose_name = "User"
verbose_name_plural = "Users"
-
-
-class NormalUser(models.Model):
- user = models.OneToOneField(Base_User, on_delete=models.CASCADE, blank= True,null = True )
- birth_date = models.DateField(_('Birth date'),null=True, blank=True)
- #add fields Country, state, postal code, city, address1, address2
-
class OwnerUser(models.Model):
diff --git a/vagus/users/urls.py b/vagus/users/urls.py
index d155115..7905d28 100755
--- a/vagus/users/urls.py
+++ b/vagus/users/urls.py
@@ -2,9 +2,12 @@ from django.conf.urls import url
from django.urls import path
from django.conf.urls.static import static
from . import views
+from django.contrib.auth.decorators import login_required
urlpatterns = [
- path('profile', views.ProfileView.as_view(), name = 'profile_view'),
+ path('profile', login_required(views.user_profile), name = 'profile_view'),
path('logout', views.logout_view, name ='logout_user'),
+ path('register',views.Register_View.as_view(), name = 'register'),
+ path('login',views.Login_View.as_view(),name = 'login'),
]
\ No newline at end of file
diff --git a/vagus/users/views.py b/vagus/users/views.py
index 544e325..64d3a4a 100755
--- a/vagus/users/views.py
+++ b/vagus/users/views.py
@@ -1,38 +1,27 @@
from django.shortcuts import render
-from .forms import CustomUserCreationForm
+from .forms import CustomUserCreationForm, LoginForm
from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
-from .models import Base_User, NormalUser, OwnerUser
+from .models import Base_User,OwnerUser
from django.views.generic import (
View,
+ CreateView,
+ FormView
)
-from django.contrib.auth import logout
+from django.contrib.auth import authenticate,login,logout
from django.conf import settings
from django.http import HttpResponseRedirect
from django.contrib import messages
from camper.models import Offer
+from reservation.models import Reservation
+from django.contrib.auth import views as auth_views
# Create your views here.
#REJESTRACJA BASE USERA NASTĘPNIE WYBOR JAKI RODZAJ KONTA UZYTKOWNIK CCHE ZALOZYC
# * W PRZYPADKU Klikniecia 'Wynajmij swoj kamper' autoatmtycznie wybierz rodzaj konta na OwnerUser
-class RegisterBaseUser(): # tworzy BaseUsera ze statusem BaseACC dla NormalUser i OwnerUser
- def register_create_base_user(self,request):
- pass
-
- def register_auth_email(self):
- pass
-
-class UserPickAccStatus(): #uzytkownik wybiera swoj rodzaj konta i uzuieplnia danymi
- pass
-
-class UpgradeProfileToOwnerUser(): #uzytkownik moze w kazdej cwhili zmienic swoje konto na konto firmowe
- pass
-
-class DowngradeProfileToNormalUser(): #uzytkownik moze zawieisc swoje konto firmowa wracajac na status konta NormalUser
- pass
class ProfileView(View):
@@ -40,19 +29,57 @@ class ProfileView(View):
context = super().get_context_data(**kwargs)
context["offers"] = Offer.objects.filter(created_by = self.Base_User)
return context
- @method_decorator(login_required,name='dispatch')
+ @method_decorator(login_required)
def get(self,request):
self.Base_User = request.user
return render(request,'users/profile.html', {'Base_User':Base_User})
-
-
-
+def user_profile(request):
+ user = request.user
+ template_name = 'users/profile.html'
+ if user.status == ' Company_Account' or user.status =='Moderator':
+ user_offers = Offer.objects.filter(created_by = request.user).order_by('-date_added')
+ user_reservations = Reservation.objects.filter(user = request.user).order_by('-reservation_start_date')
+ return render(request,template_name, {'user':user, 'user_offers':user_offers, 'user_reservations':user_reservations})
+ if user.status == 'BaseAcc':
+ user_reservations = Reservation.objects.filter(user = request.user).order_by('-reservation_start_date')
+ return render(request,template_name, {'user':user,'user_reservation':user_reservations})
class EditProfile(): #edycja danych w profilu - zmiana hasłą + zmiana danych
pass
+class Register_View(FormView):
+ def get(self,request,*args,**kwargs):
+ if request.user.is_authenticated:
+ return redirect('/profile')
+ else:
+ context = {}
+ form = CustomUserCreationForm()
+ context['form'] = form
+ return render(request,'users/register.html',context)
+
+ def post(self,request,*args,**kwargs):
+ context = {}
+ if request.POST:
+ form = CustomUserCreationForm(request.POST)
+ if form.is_valid():
+ form.save()
+ email = form.cleaned_data.get('email')
+ raw_password = form.cleaned_data.get('password1')
+ account = authenticate(email = email, password = raw_password)
+ login(request,account)
+ return redirect('/')
+ else:
+ context['form'] = form
+ else:
+ form = CustomUserCreationForm()
+ context['form'] = form
+ return render(request,'users/register.html', context)
+
+class Login_View(auth_views.LoginView):
+ template_name = 'users/login.html'
+ success_url = '/profile'
def logout_view(request):
logout(request)
messages.success(request,'Zostałeś poprawnie wylogowany')