Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LAB-Django-AUTH- SerenCare Finished #13

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
Binary file added .DS_Store
Binary file not shown.
Binary file added SerenCare/.DS_Store
Binary file not shown.
Empty file added SerenCare/SerenCare/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions SerenCare/SerenCare/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for SerenCare 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/5.0/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

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

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

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.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/5.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-z$4u^sf2hyc1ej!=)txhdsfc^70n8436)&g1%@&9q_())j$we='

# 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',
'accounts',
'doctors',
'clinics',
]

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 = 'SerenCare.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
#'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'SerenCare.wsgi.application'


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

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


# Password validation
# https://docs.djangoproject.com/en/5.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/5.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/5.0/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'


# Add 2 lines for media============
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')


# # Add 6 lines for email settings=========
# EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# EMAIL_HOST = config('EMAIL_HOST')
# EMAIL_PORT = config('EMAIL_PORT', cast=int)
# EMAIL_USE_TLS = config('EMAIL_USE_TLS', cast=bool)
# EMAIL_HOST_USER = config('EMAIL_HOST_USER')
# EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD')



# key = config('ENCRYPTION_KEY').encode()
# encrypted_password = config('EMAIL_HOST_PASSWORD').encode()

# # Create a Fernet instance
# cipher_suite = Fernet(key)

# # Decrypt the password
# try:
# EMAIL_HOST_PASSWORD = cipher_suite.decrypt(encrypted_password).decode()
# except InvalidToken:
# print("Decryption failed: Invalid token")
31 changes: 31 additions & 0 deletions SerenCare/SerenCare/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
URL configuration for SerenCare project.

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/5.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('', include('accounts.urls')),
path('', include('doctors.urls')),
path('', include('clinics.urls')),

] + static(settings.MEDIA_URL, document_root= settings.MEDIA_ROOT)

16 changes: 16 additions & 0 deletions SerenCare/SerenCare/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for SerenCare 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/5.0/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

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

application = get_wsgi_application()
Binary file added SerenCare/accounts/.DS_Store
Binary file not shown.
Empty file added SerenCare/accounts/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions SerenCare/accounts/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.contrib import admin
from .models import Profile

# Register your models here.

admin.site.register(Profile)
6 changes: 6 additions & 0 deletions SerenCare/accounts/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AccountsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'accounts'
26 changes: 26 additions & 0 deletions SerenCare/accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 5.0.7 on 2024-08-07 02:33

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.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('phone_number', models.CharField(blank=True, max_length=15, null=True)),
('address', models.TextField(blank=True, null=True)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
Empty file.
16 changes: 16 additions & 0 deletions SerenCare/accounts/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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)
phone_number = models.CharField(max_length=15, blank=True, null= True)
address = models.TextField(blank=True, null=True)


def __str__(self) -> str:
return f"Profile {self.user.username}"




Binary file added SerenCare/accounts/templates/.DS_Store
Binary file not shown.
52 changes: 52 additions & 0 deletions SerenCare/accounts/templates/accounts/profile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{% extends 'main/base.html'%}


{% block title %} profile for {{user.username}} {% endblock %}

{% block content %}


<div class="row">

<div class="col">
<h2>Mr. {{user.get_full_name}} </h2>
<div>
<h6>User Name: @{{user.username}}</h6>
<h6>Email: {{user.email}}</h6>
</div>
<div class=" mb-4">
<h6>Mobile: {{user.profile.phone_number}} </h6>
<h6>{{user.profile.address}} </h6>
</div>
{% if request.user == user %}
<a href="{% url 'accounts:update_user_profile' %}" class="sky-bg rounded-pill p-2 ">update profile</a>

{% endif %}
</div>

</div>

<hr>

<div class="d-flex justify-content-center">
<h2>Your appointments</h2>
</div>
<hr>

<div class="row mt-2 row-cols-1 row-cols-md-2 g-4">

{% for appointment in appointments%}
<div class="col">
<div class="d-flex flex-column justify-content-center align-items-centert h-100 w-100 shadow m-2 p-3 gap-2 bg-body-secondary bg-opacity-75">
<h5 class="m-0 p-0">Clinic: <span class="fw-normal text-black">{{appointment.clinic.name}}</span></h5>
<h5 class="m-0 p-0">Physician: <span class="fw-normal text-black" > Dr. {{appointment.doctor.full_name}} </span></h5>
<h5 class="m-0 p-0">Date: <span class="fw-normal text-black"> {{appointment.date}}</span></h5>
<h5 class="m-0 p-0">Time: <span class="fw-normal text-black"> {{appointment.time_slot}} </span></h5>

</div>
</div>
{% endfor %}
</div>


{% endblock %}
31 changes: 31 additions & 0 deletions SerenCare/accounts/templates/accounts/signin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% 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>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="floatingInput" placeholder="username" name="username">
<label for="floatingInput">User name</label>
</div>


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


<button class="btn sky-bg w-100 py-2" type="submit">Sign In</button>
</form>
</div>

{% endblock %}
Loading