Skip to content
Open
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 added Planteer/Planteer/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions Planteer/Planteer/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for Planteer project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/6.0/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Planteer.settings')

application = get_asgi_application()
127 changes: 127 additions & 0 deletions Planteer/Planteer/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
"""
Django settings for Planteer project.

Generated by 'django-admin startproject' using Django 6.0.4.

For more information on this file, see
https://docs.djangoproject.com/en/6.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/6.0/ref/settings/
"""

from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-=bq-yu6kds01c+*nn4^kcixwmy%(0v1r1rd7zk1vjdv3gu@3=r'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main',
'plants',
'accounts',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'Planteer.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'Planteer.wsgi.application'


# Database
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}


# Password validation
# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/6.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'
TIME_ZONE = 'Asia/Riyadh'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/6.0/howto/static-files/

STATIC_URL = 'static/'

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')


27 changes: 27 additions & 0 deletions Planteer/Planteer/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
URL configuration for Planteer project.

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/6.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path , include
from django.conf.urls.static import static
from . import settings

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('main.urls')),
path('plants/', include('plants.urls')),
path('accounts/', include('accounts.urls'))
] + static(settings.MEDIA_URL,document_root =settings.MEDIA_ROOT)
16 changes: 16 additions & 0 deletions Planteer/Planteer/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for Planteer project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/6.0/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Planteer.settings')

application = get_wsgi_application()
Empty file added Planteer/accounts/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions Planteer/accounts/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.
5 changes: 5 additions & 0 deletions Planteer/accounts/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class AccountsConfig(AppConfig):
name = 'accounts'
Empty file.
3 changes: 3 additions & 0 deletions Planteer/accounts/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.
30 changes: 30 additions & 0 deletions Planteer/accounts/templates/accounts/signin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends 'main/base.html' %}

{% block title %}Sign In{% endblock %}

{% block content %}

<div class="container d-flex flex-column justify-content-center align-items-center">
<h2 class="mb-4">Sign In</h2>

<form class="d-flex flex-column gap-3 w-50"
action="{% url 'accounts:sign_in' %}{% if 'next' in request.GET %}?next={{ request.GET.next }}{% endif %}"
method="POST">
{% csrf_token %}

<div class="form-floating">
<input type="text" class="form-control" id="username" placeholder="Username" name="username" required>
<label for="username">Username</label>
</div>

<div class="form-floating">
<input type="password" class="form-control" id="password" placeholder="Password" name="password" required>
<label for="password">Password</label>
</div>

<button class="btn btn-success w-100 py-2" type="submit">Sign In</button>
<p class="text-center text-muted">Don't have an account? <a href="{% url 'accounts:sign_up' %}">Sign Up</a></p>
</form>
</div>

{% endblock %}
43 changes: 43 additions & 0 deletions Planteer/accounts/templates/accounts/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{% extends 'main/base.html' %}
{% block title %}Sign Up{% endblock %}
{% block content %}

<div class="row justify-content-center">
<div class="col-md-5">
<h1 class="mb-4">Sign Up</h1>

{% if messages %}
{% for message in messages %}
<div class="alert {{ message.tags }}">{{ message }}</div>
{% endfor %}
{% endif %}

<form method="POST" class="d-flex flex-column gap-3">
{% csrf_token %}
<div>
<label class="form-label">First Name</label>
<input type="text" name="first_name" class="form-control" required />
</div>
<div>
<label class="form-label">Last Name</label>
<input type="text" name="last_name" class="form-control" required />
</div>
<div>
<label class="form-label">Username</label>
<input type="text" name="username" class="form-control" required minlength="3" />
</div>
<div>
<label class="form-label">Email</label>
<input type="email" name="email" class="form-control" required />
</div>
<div>
<label class="form-label">Password</label>
<input type="password" name="password" class="form-control" required />
</div>
<button type="submit" class="btn btn-success">Sign Up</button>
<p class="text-muted text-center">Already have an account? <a href="{% url 'accounts:sign_in' %}">Sign In</a></p>
</form>
</div>
</div>

{% endblock %}
3 changes: 3 additions & 0 deletions Planteer/accounts/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.
11 changes: 11 additions & 0 deletions Planteer/accounts/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.urls import path
from . import views

app_name="accounts"

urlpatterns=[

path('signup/', views.sign_up, name="sign_up"),
path('signin/', views.sign_in, name="sign_in"),
path('logout/', views.log_out, name="log_out"),
]
54 changes: 54 additions & 0 deletions Planteer/accounts/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from django.shortcuts import render,redirect
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login, logout
from django.contrib import messages
from django.http import HttpRequest,HttpResponse

# Create your views here.

def sign_up(request: HttpRequest):

if request.method == "POST":
try:
new_user = User.objects.create_user(
username=request.POST["username"],
password=request.POST["password"],
email=request.POST["email"],
first_name=request.POST["first_name"],
last_name=request.POST["last_name"]
)
new_user.save()
messages.success(request, "Registered Successfully!", "alert-success")
return redirect("accounts:sign_in")
except Exception as e:
print(e)
messages.error(request, "Username already exists!", "alert-danger")

return render(request, "accounts/signup.html")

def sign_in(request:HttpRequest):

if request.method == "POST":

#checking user credentials
user = authenticate(request, username=request.POST["username"], password=request.POST["password"])
print(user)
if user:
#login the user
login(request, user)
messages.success(request, "Logged in successfully", "alert-success")
return redirect(request.GET.get("next", "/"))
else:
messages.error(request, "Please try again. You credentials are wrong", "alert-danger")


return render(request, "accounts/signin.html")



def log_out(request: HttpRequest):

logout(request)
messages.warning(request, "logged out successfully", "alert-warning")

return redirect(request.GET.get("next", "/"))
Binary file added Planteer/db.sqlite3
Binary file not shown.
Empty file added Planteer/main/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions Planteer/main/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.
5 changes: 5 additions & 0 deletions Planteer/main/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class MainConfig(AppConfig):
name = 'main'
25 changes: 25 additions & 0 deletions Planteer/main/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 6.0.4 on 2026-04-19 18:58

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Contact',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(max_length=1024)),
('last_name', models.CharField(max_length=1024)),
('email', models.EmailField(max_length=254)),
('message', models.TextField()),
('created_at', models.DateTimeField(auto_now_add=True)),
],
),
]
Empty file.
Loading