delted everything that has todo with user
parent
4ae7240d68
commit
02774e6094
|
|
@ -34,7 +34,6 @@ INSTALLED_APPS = [
|
|||
'crispy_forms',
|
||||
'crispy_bootstrap4',
|
||||
'blog.apps.BlogConfig',
|
||||
'users.apps.UsersConfig',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
|
|
@ -80,11 +79,11 @@ WSGI_APPLICATION = 'BH.wsgi.application'
|
|||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'NAME': 'Name of the database Instance',
|
||||
'USER': 'USERNAME',
|
||||
'PASSWORD': 'PASSWORD of User',
|
||||
'NAME': 'BH',
|
||||
'USER': 'jukoga',
|
||||
'PASSWORD': '69420',
|
||||
'HOST': 'localhost',
|
||||
'PORT': 'SET PORT NUMBER',
|
||||
'PORT': '3306',
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ from django.urls import path, include
|
|||
|
||||
urlpatterns = [
|
||||
path('', include('blog.urls')),
|
||||
path('users/', include('users.urls')),
|
||||
path('admin/', admin.site.urls),
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
# Generated by Django 5.0.2 on 2024-07-24 19:20
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('blog', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.DeleteModel(
|
||||
name='Post',
|
||||
),
|
||||
]
|
||||
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
|
|
@ -25,31 +25,6 @@
|
|||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="ml-auto"></div>
|
||||
<div class="justify-content-center" id="navbarNav">
|
||||
<ul class="navbar-nav">
|
||||
{% if user.is_authenticated %}
|
||||
<li class="nav-item">
|
||||
{% if user.is_staff %}
|
||||
<a class="nav-link" href="{% url 'BlogCreate' %}">Post</a>
|
||||
{% endif %}
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<form action="{% url 'Logout' %}" method="post">
|
||||
{% csrf_token %}
|
||||
<button class="nav-link btn btn-link" type="submit">Logout</button>
|
||||
</form>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'Login' %}">Login</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'Register' %}">Register</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
{% block content %}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
<p class="card-text">{{ object.content | markdown | safe }}</p>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
By <cite title="{{ object.author }}"><a href="#" class="link text-dark">{{ object.author }}</a></cite> on <cite title="{{ object.date_posted }}">{{ object.date_posted|date:"M j, o" }}</cite>
|
||||
By <cite title="{{ object.author }}"></cite> on <cite title="{{ object.date_posted }}">{{ object.date_posted|date:"M j, o" }}</cite>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,24 +0,0 @@
|
|||
{% extends 'base.html' %}
|
||||
{% block content %}
|
||||
{% load crispy_forms_tags %}
|
||||
<div class="container mt-5">
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
<div class="card mb-4">
|
||||
<div class="card-header">
|
||||
Login
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{{ form | crispy }}
|
||||
<br>
|
||||
<button class="btn btn-light" type="submit"> Login </button>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<small class="text-muted">
|
||||
Don't Have An Account? <a class="link" href="{% url 'Register' %}">Register</a>
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
{% extends 'base.html' %}
|
||||
{% block content %}
|
||||
{% load crispy_forms_tags %}
|
||||
{% if messages %}
|
||||
{% for message in messages %}
|
||||
<div class="alert alert-{{message.tags}}">{{ message }}</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
<div class="container mt-5">
|
||||
<div class="card mb-4">
|
||||
<div class="card-header h5">
|
||||
You have been Logged Out
|
||||
</div>
|
||||
<div class="card-body">
|
||||
Hope you enjoyed Today!
|
||||
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<small class="text-muted">
|
||||
Go to <a href="{% url 'Home' %}" class="link">Home</a> or <a href="{% url 'Login' %}" class="link" type="submit"> Log in </a> Again?
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
|
||||
|
||||
{% extends 'base.html' %}
|
||||
{% block content %}
|
||||
|
||||
{% load markdown_extras %}
|
||||
<!-- Main Content -->
|
||||
<div class="container mt-5">
|
||||
<div class="row">
|
||||
<!-- Mainbar -->
|
||||
<div class="col-lg-8">
|
||||
<div class="card-body">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Latest Posts
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{% for post in posts %}
|
||||
{% if post.author == profileUser %}
|
||||
<!-- Posts will be dynamically added here -->
|
||||
<div class="card mb-3 userPost">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">{{ post.author.username }} <a href="#" class="link text-secondary lead" style="text-decoration: none;">@{{ post.author.id }}</a></h5>
|
||||
<p class="card-text">{{ post.content | markdown | safe }}</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<!-- End of Posts -->
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Sidebar -->
|
||||
<div class="col-lg-4">
|
||||
<div class="card mb-4">
|
||||
<div class="row" style="padding-bottom: 20px;">
|
||||
<div class="col-md-4 text-center">
|
||||
<img src="https://cdn.pixabay.com/photo/2017/06/13/12/54/profile-2398783_1280.png" alt="Profile Image" class="profile-image">
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<h2 class="mt-3" style="margin-bottom: 0px;">{{ profileUser.username }}</h2>
|
||||
<p class="text-secondary lead" style="margin-bottom: 0px;">@{{ profileUser.id }}</p>
|
||||
<p>Date Joined: Jan 1, 2022</p>
|
||||
{% if profileUser == user %}
|
||||
<a href="#" class="link">Edit Profile</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
{% extends 'base.html' %}
|
||||
{% block content %}
|
||||
{% load crispy_forms_tags %}
|
||||
<div class="container mt-5">
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
<div class="card mb-4">
|
||||
<div class="card-header">
|
||||
Create an Account
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{{ form | crispy }}
|
||||
<br>
|
||||
<button class="btn btn-light sm" type="submit"> Register </button>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<small class="text-muted">
|
||||
Already Have An Account? <a class="link" href="{% url 'Login' %}">Sign In</a>
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
from django.contrib import admin
|
||||
from .models import Profile
|
||||
|
||||
|
||||
# Register your models here.
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class UsersConfig(AppConfig):
|
||||
name = 'users'
|
||||
|
||||
def ready(self):
|
||||
import users.signals
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
from django import forms
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
from .models import Profile
|
||||
|
||||
|
||||
class UserRegisterForm(UserCreationForm):
|
||||
email = forms.EmailField()
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ['username', 'email', 'password1', 'password2']
|
||||
|
||||
|
||||
class UserUpdateForm(forms.ModelForm):
|
||||
email = forms.EmailField()
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ['username', 'email']
|
||||
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
# Generated by Django 5.0.2 on 2024-07-06 16:24
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Profile',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=100)),
|
||||
('about', models.TextField(default='Hi, I am new to TechBlog')),
|
||||
('gender', models.TextField(default='None')),
|
||||
('dob', models.DateField(default='1999-01-01')),
|
||||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
# Create your models here.
|
||||
class Profile(models.Model):
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
name = models.CharField(max_length=100)
|
||||
about = models.TextField(default='Hi, I am new to TechBlog')
|
||||
gender = models.TextField(default='None')
|
||||
dob = models.DateField(default='1999-01-01')
|
||||
# image = models.ImageField(default='default.png', name='profile_pic', upload_to='profile_pics')
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.user.username}'s Profile"
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
from django.db.models.signals import post_save
|
||||
from django.contrib.auth.models import User
|
||||
from django.dispatch import receiver
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
from django.urls import path
|
||||
from django.contrib.auth import views as login_view
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('profile/', views.profile, name='Profile'),
|
||||
path('profile/<int:pk>', views.profile, name='NamedProfile'),
|
||||
path('login/', login_view.LoginView.as_view(template_name='users/login.html'), name='Login'),
|
||||
path('logout/', login_view.LogoutView.as_view(template_name='users/logout.html'), name='Logout'),
|
||||
path('register/', views.register, name='Register')
|
||||
]
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
from django.shortcuts import render, redirect
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from .forms import UserRegisterForm
|
||||
from blog.models import *
|
||||
from .models import *
|
||||
from django.views.generic import *
|
||||
|
||||
|
||||
# Create your views here.
|
||||
# def users(request):
|
||||
# return render(request, 'users/users.html', {'title': 'Users'})
|
||||
|
||||
def getFromArr(arr, indices, *args, **kwargs):
|
||||
x = []
|
||||
for i in indices:
|
||||
x.append(arr[i])
|
||||
return x
|
||||
|
||||
|
||||
@login_required
|
||||
def profile(request, *args, **kwargs):
|
||||
try:
|
||||
user = User._default_manager.all()[kwargs['pk'] - 1]
|
||||
except:
|
||||
user = request.user
|
||||
print(user.id)
|
||||
|
||||
allow_empty = True
|
||||
queryset = None
|
||||
model = Post
|
||||
paginate_by = None
|
||||
paginate_orphans = 0
|
||||
context_object_name = 'posts'
|
||||
ordering = ['-date_posted']
|
||||
|
||||
if queryset is not None:
|
||||
queryset = queryset
|
||||
if isinstance(queryset, QuerySet):
|
||||
queryset = queryset.all()
|
||||
elif model is not None:
|
||||
queryset = model._default_manager.all()
|
||||
else:
|
||||
raise ImproperlyConfigured(
|
||||
"%(cls)s is missing a QuerySet. Define "
|
||||
"%(cls)s.model, %(cls)s.queryset, or override "
|
||||
"%(cls)s.get_queryset()." % {"cls": self.__class__.__name__}
|
||||
)
|
||||
|
||||
if ordering:
|
||||
if isinstance(ordering, str):
|
||||
ordering = (ordering,)
|
||||
queryset = queryset.order_by(*ordering)
|
||||
|
||||
return render(request, 'users/profile.html', {'title': 'Profile', 'profileUser': user, context_object_name: queryset})
|
||||
|
||||
|
||||
users = {
|
||||
'user': User.objects.all()
|
||||
}
|
||||
|
||||
|
||||
def login(request):
|
||||
return render(request, 'users/login.html', {'title': 'Login'})
|
||||
|
||||
|
||||
def register(request):
|
||||
if request.method == 'POST':
|
||||
form = UserRegisterForm(request.POST)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
username = form.cleaned_data.get('username')
|
||||
messages.success(request, f'{username}! Your account has been created.')
|
||||
return redirect('Login')
|
||||
else:
|
||||
form = UserRegisterForm()
|
||||
return render(request, 'users/register.html', {'title': 'Register', 'form': form})
|
||||
Loading…
Reference in New Issue