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()
132 changes: 132 additions & 0 deletions Planteer/Planteer/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
"""
Django settings for Planteer project.

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

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-%0cc1#2i4e^(nfrm&@y5#6tcqx@lnftl89^+@cj*l(9l9l44vx'

# 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': [BASE_DIR / 'templates'],
'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'

USE_I18N = True

USE_TZ = True


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

STATIC_URL = '/static/'
STATICFILES_DIRS = [BASE_DIR / 'static']

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

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

LOGIN_URL = 'accounts:signin'
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'
30 changes: 30 additions & 0 deletions Planteer/Planteer/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
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 import settings
from django.conf.urls.static import static

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('main.urls')),
path('plants/', include('plants.urls')),
path('accounts/', include('accounts.urls')),
]

if settings.DEBUG:
urlpatterns += 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'
48 changes: 48 additions & 0 deletions Planteer/accounts/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from django import forms
from django.contrib.auth.models import User


class SignUpForm(forms.Form):
username = forms.CharField(
widget=forms.TextInput(attrs={'placeholder': 'Username'})
)
email = forms.EmailField(
widget=forms.EmailInput(attrs={'placeholder': 'Email'})
)
password = forms.CharField(
widget=forms.PasswordInput(attrs={'placeholder': 'Password'})
)
confirm_password = forms.CharField(
widget=forms.PasswordInput(attrs={'placeholder': 'Confirm Password'})
)

def clean_username(self):
username = self.cleaned_data.get('username', '').strip()
if User.objects.filter(username=username).exists():
raise forms.ValidationError('This username is already taken.')
return username

def clean_email(self):
email = self.cleaned_data.get('email', '').strip()
if User.objects.filter(email=email).exists():
raise forms.ValidationError('This email is already registered.')
return email

def clean(self):
cleaned_data = super().clean()
password = cleaned_data.get('password')
confirm_password = cleaned_data.get('confirm_password')

if password and confirm_password and password != confirm_password:
raise forms.ValidationError('Passwords do not match.')

return cleaned_data


class SignInForm(forms.Form):
username = forms.CharField(
widget=forms.TextInput(attrs={'placeholder': 'Username'})
)
password = forms.CharField(
widget=forms.PasswordInput(attrs={'placeholder': 'Password'})
)
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.
44 changes: 44 additions & 0 deletions Planteer/accounts/templates/accounts/signin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{% extends 'base.html' %}

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

{% block content %}
<section class="section">
<div class="container">
<div class="auth-box">
<h1 class="page-title">Sign In</h1>
<p class="page-subtitle">Welcome back</p>

{% if error_message %}
<div class="form-errors">
<p>{{ error_message }}</p>
</div>
{% endif %}

<form method="post" class="styled-form">
{% csrf_token %}

<div class="form-group">
<label for="{{ form.username.id_for_label }}">Username</label>
{{ form.username }}
{% for error in form.username.errors %}
<span class="error-text">{{ error }}</span>
{% endfor %}
</div>

<div class="form-group">
<label for="{{ form.password.id_for_label }}">Password</label>
{{ form.password }}
{% for error in form.password.errors %}
<span class="error-text">{{ error }}</span>
{% endfor %}
</div>

<button type="submit" class="btn btn-dark btn-full">Sign In</button>
</form>

<p class="auth-link">Don't have an account? <a href="{% url 'accounts:signup' %}">Sign Up</a></p>
</div>
</div>
</section>
{% endblock %}
62 changes: 62 additions & 0 deletions Planteer/accounts/templates/accounts/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{% extends 'base.html' %}

{% block title %}Sign Up{% endblock %}

{% block content %}
<section class="section">
<div class="container">
<div class="auth-box">
<h1 class="page-title">Sign Up</h1>
<p class="page-subtitle">Create a new account</p>

{% if form.non_field_errors %}
<div class="form-errors">
{% for error in form.non_field_errors %}
<p>{{ error }}</p>
{% endfor %}
</div>
{% endif %}

<form method="post" class="styled-form">
{% csrf_token %}

<div class="form-group">
<label for="{{ form.username.id_for_label }}">Username</label>
{{ form.username }}
{% for error in form.username.errors %}
<span class="error-text">{{ error }}</span>
{% endfor %}
</div>

<div class="form-group">
<label for="{{ form.email.id_for_label }}">Email</label>
{{ form.email }}
{% for error in form.email.errors %}
<span class="error-text">{{ error }}</span>
{% endfor %}
</div>

<div class="form-group">
<label for="{{ form.password.id_for_label }}">Password</label>
{{ form.password }}
{% for error in form.password.errors %}
<span class="error-text">{{ error }}</span>
{% endfor %}
</div>

<div class="form-group">
<label for="{{ form.confirm_password.id_for_label }}">Confirm Password</label>
{{ form.confirm_password }}
{% for error in form.confirm_password.errors %}
<span class="error-text">{{ error }}</span>
{% endfor %}
</div>

<button type="submit" class="btn btn-dark btn-full">Sign Up</button>
</form>

<p class="auth-link">Already have an account? <a href="{% url 'accounts:signin' %}">Sign In</a></p>
</div>
</div>
</section>
{% 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.
10 changes: 10 additions & 0 deletions Planteer/accounts/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.urls import path
from . import views

app_name = "accounts"

urlpatterns = [
path('signup/', views.sign_up, name='signup'),
path('signin/', views.sign_in, name='signin'),
path('logout/', views.log_out, name='logout'),
]
Loading