Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions Projects/Drained/account/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions Projects/Drained/account/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AccountConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'account'
Empty file.
Binary file not shown.
3 changes: 3 additions & 0 deletions Projects/Drained/account/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Projects/Drained/account/static/account/js/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

45 changes: 45 additions & 0 deletions Projects/Drained/account/templates/account/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{% extends "base.html" %}
{%load static%}

{%block css_files%}
<link rel="stylesheet" href="{%static 'account/css/style.css'%}">
{%endblock%}




{%block content%}

<div class="container mt-3">
<div class="col">


<form action="{% url 'login' %}" method="POST">
{% csrf_token %}
{% if error %}
<div class="alert alert-danger" role="alert">
{{error}}
</div>
{% endif %}
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input type="text" class="form-control" name="username">
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" name="password">
</div>

<input type="submit" value="Login" class="btn btn-primary">

</form>


</div>
</div>

{%endblock%}

{%block js_files%}
<script src="{%static 'account/js/script.js'%}"></script>
{%endblock%}
66 changes: 66 additions & 0 deletions Projects/Drained/account/templates/account/singup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{% extends "base.html" %}
{%load static%}

{%block css_files%}
<link rel="stylesheet" href="{%static 'account/css/style.css'%}">
{%endblock%}




{%block content%}

<div class="container mt-3">
<div class="col">


<form action="{% url 'singup' %}" method="POST">
{% csrf_token %}
{% if error %}
<div class="alert alert-danger" role="alert">
{{error}}
</div>
{% endif %}
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input type="text" class="form-control" name="username" value="{{username}}">
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" name="email" value="{{email}}">
</div>
<div class="row mb-3">
<div class="col">
<label for="firstname" class="form-label">First Name</label>
<input type="text" class="form-control" name="firstname" value="{{firstname}}">
</div>
<div class="col">
<label for="lastname" class="form-label">Last Name</label>
<input type="text" class="form-control" name="lastname" value="{{lastname}}">
</div>
</div>
<div class="row mb-3">
<div class="col">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" name="password">
</div>
<div class="col">
<label for="repassword" class="form-label">Re-Password</label>
<input type="password" class="form-control" name="repassword">
</div>
</div>
<div class="mb-3"></div>

<input type="submit" value="Singup" class="btn btn-primary">

</form>


</div>
</div>

{%endblock%}

{%block js_files%}
<script src="{%static 'account/js/script.js'%}"></script>
{%endblock%}
3 changes: 3 additions & 0 deletions Projects/Drained/account/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
9 changes: 9 additions & 0 deletions Projects/Drained/account/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path
from . import views

urlpatterns = [
path("login", views.login_request, name="login"),
path("singup", views.singup_request, name="singup"),
path("logout", views.logout_request, name="logout"),

]
79 changes: 79 additions & 0 deletions Projects/Drained/account/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.models import User

def login_request(request):
if request.user.is_authenticated:
return redirect("Home")

if request.method =="POST":
username = request.POST["username"]
password = request.POST["password"]

user = authenticate(request, username = username, password = password)

if user is not None:
login(request, user)
return redirect("Home")
else:
return render(request, "account/login.html", {
"error": "Invalid username or password"
})


return render(request,"account/login.html")

def singup_request(request):
if request.user.is_authenticated:
return redirect("Home")

if request.method == "POST":
username = request.POST["username"]
email = request.POST["email"]
firstname = request.POST["firstname"]
lastname = request.POST["lastname"]
password = request.POST["password"]
repassword = request.POST["repassword"]

if password == repassword:
if User.objects.filter(username=username).exists():
return render(request, "account/singup.html",
{
"error": "Username exist",
"username": username,
"email": email,
"firstname": firstname,
"lastname": lastname,
})
else:
if User.objects.filter(email=email).exists():
return render(request, "account/singup.html",
{
"error": "Email exist",
"username": username,
"email": email,
"firstname": firstname,
"lastname": lastname,
})
else:
user = User.objects.create_user(username=username, email=email, first_name=firstname, last_name=lastname, password=password)
user.save()
return redirect("login")

else:
return render(request, "account/singup.html",
{
"error": "Password does not match",
"username": username,
"email": email,
"firstname": firstname,
"lastname": lastname,
})

return render(request,"account/singup.html")

def logout_request(request):
logout(request)
return redirect("Home")


Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17 changes: 17 additions & 0 deletions Projects/Drained/baseapp/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.contrib import admin
from .models import Note
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin

class NoteAdmin(admin.ModelAdmin):
list_display = ('title', 'user', 'created_at', 'updated_at')
search_fields = ('title', 'content', 'user__username')
list_filter = ('created_at', 'updated_at', 'user')
date_hierarchy = 'created_at'
ordering = ('-created_at',)

admin.site.register(Note, NoteAdmin)

# If you need to customize the User model admin
admin.site.unregister(User)
admin.site.register(User, UserAdmin)
6 changes: 6 additions & 0 deletions Projects/Drained/baseapp/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class BaseappConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'baseapp'
7 changes: 7 additions & 0 deletions Projects/Drained/baseapp/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django import forms
from .models import Note

class NoteForm(forms.ModelForm):
class Meta:
model = Note
fields = ['title', 'content']
103 changes: 103 additions & 0 deletions Projects/Drained/baseapp/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Generated by Django 4.2.10 on 2024-04-25 08:22

import ckeditor.fields
import django.contrib.auth.models
import django.contrib.auth.validators
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):

initial = True

dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
]

operations = [
migrations.CreateModel(
name='CustomUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('groups', models.ManyToManyField(blank=True, related_name='custom_user_groups', to='auth.group')),
('user_permissions', models.ManyToManyField(blank=True, related_name='custom_user_permissions', to='auth.permission')),
],
options={
'verbose_name': 'user',
'verbose_name_plural': 'users',
'abstract': False,
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
migrations.CreateModel(
name='Folder',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='owned_folders', to='baseapp.customuser')),
('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='subfolders', to='baseapp.folder')),
],
),
migrations.CreateModel(
name='UserSettings',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('theme', models.CharField(default='light', max_length=20)),
('notification_preference', models.CharField(default='email', max_length=50)),
('language', models.CharField(default='en', max_length=20)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='settings', to='baseapp.customuser')),
],
),
migrations.CreateModel(
name='Tag',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
('color', models.CharField(default='gray', max_length=20)),
('folders', models.ManyToManyField(related_name='tags', to='baseapp.folder')),
],
),
migrations.CreateModel(
name='Permission',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('permission_type', models.CharField(default='read', max_length=20)),
('folder', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='folder_permissions', to='baseapp.folder')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='permissions', to='baseapp.customuser')),
],
),
migrations.CreateModel(
name='ContentBlock',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('content_type', models.CharField(max_length=255)),
('content', ckeditor.fields.RichTextField()),
('title', models.CharField(blank=True, max_length=255, null=True)),
('folder', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='content_blocks', to='baseapp.folder')),
],
),
migrations.CreateModel(
name='Collaboration',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('collaborators', models.ManyToManyField(related_name='folder_collaborations', to='baseapp.customuser')),
('folder', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='collaborations', to='baseapp.folder')),
],
),
]
19 changes: 19 additions & 0 deletions Projects/Drained/baseapp/migrations/0002_alter_folder_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.10 on 2024-04-27 17:09

from django.db import migrations, models
import uuid


class Migration(migrations.Migration):

dependencies = [
('baseapp', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='folder',
name='id',
field=models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False),
),
]
Loading