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
35 changes: 35 additions & 0 deletions DJANGO PROJECTS/Chat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Django Chat Application

## Overview

This is a simple django chat applications for real time chatting. One needs to create an account to be able to chat with others. User can create their own room for chatting.

## Libraries and Frameworks:

These are the libraries and frameworks used to build this chat application.
1.Django == 3.0.2
2.django-environ == 4.1.4
3.channels == 3.0.4

[![Screenshot-70.png](https://i.postimg.cc/jqWhGBq1/Screenshot-70.png)](https://postimg.cc/fkNXd297)


## Getting started with project
First clone the repository from Github and cd into the Djagno Projects/Chat

Activate the virtualenv for the project

Install project dependencies
```bash
$ pip install -r requirements.txt
```

Then aplly the migrations
```bash
$ python manage.py runserver
```

Now you can run the server
```bash
$ python manage.py runserver
```
Empty file.
3 changes: 3 additions & 0 deletions DJANGO PROJECTS/Chat/chat/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 DJANGO PROJECTS/Chat/chat/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ChatConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'chat'
23 changes: 23 additions & 0 deletions DJANGO PROJECTS/Chat/chat/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User

class NewUserForm(UserCreationForm):
email = forms.EmailField(required=True)

class Meta:
model = User
fields = ('username', 'email', 'password1', 'password2')

def save(self, commit=True):
user = super(NewUserForm,self).save(commit=False)
user.email = self.cleaned_data['email']
if commit:
user.save()
return user

def __init__(self, *args, **kwargs):
super(UserCreationForm, self).__init__(*args, **kwargs)
self.fields['username'].help_text = None
self.fields['password2'].help_text = None
self.fields['password1'].help_text = None
Empty file.
3 changes: 3 additions & 0 deletions DJANGO PROJECTS/Chat/chat/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 DJANGO PROJECTS/Chat/chat/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends 'base.html' %}
{% block title %}Home{% endblock %}

{% block content %}

<div class="container">
{% if user.is_authenticated %}
<div class="container fixed-card card">
<h1>User is authenticated</h1>
<p>This is a <strong>chat system app</strong> build in <strong>Python-Django</strong>.<br>

<ul style="text-align: left;">
Featues:
<li>Sign up to chat.</li>
<li>Log in and log out from the app.</li>
<li>Send messages and read messages.</li>
<li>Create new rooms.</li>
</ul></p>
</div>
{% else %}
<div class="container fixed-card card">
<h1>User is not authenticated</h1>
<p>Make sure or <strong>logged in</strong> else you can <strong>sign up</strong>.</p>
<a href="{% url 'login' %}" style="text-decoration: underline;">Follow this link to login or check the top right corner.</a>
<a href="{% url 'register' %}" style="text-decoration: underline;">Follow this link to sign up or check the top right corner.</a>
</div>
{% endif %}
</div>

{% endblock %}
16 changes: 16 additions & 0 deletions DJANGO PROJECTS/Chat/chat/templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends 'base.html' %}
{% block title %}LogIn{% endblock %}

{% block content %}

<div class="container card">
<h1 class="head">Log In</h1>

<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="LogIn" class="btn btn-dark in">
</form>
</div>

{% endblock %}
14 changes: 14 additions & 0 deletions DJANGO PROJECTS/Chat/chat/templates/signin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends 'base.html' %}

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

{% block content %}
<div class="container card register-card">
<h1>Register</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Sign In" class="btn btn-dark in">
</form>
</div>
{% endblock %}
13 changes: 13 additions & 0 deletions DJANGO PROJECTS/Chat/chat/templates/user.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends 'base.html' %}

{% block title %}User Detail{% endblock %}

{% block content %}
<div class="container user-card card">
<h1>User Detail</h1>
<h5>Username : {{ user.username }}</h5>
<h5>Email : {{ user.email }}</h5>
<a href="{% url 'logout' %}"><input type="submit" value="Log Out" class="btn btn-dark in new-btn"></a>
</div>

{% endblock %}
3 changes: 3 additions & 0 deletions DJANGO PROJECTS/Chat/chat/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 DJANGO PROJECTS/Chat/chat/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.urls import path
from . import views
from django.contrib.auth.views import LoginView, LogoutView

urlpatterns = [
path('',views.index, name="index"),
path('accounts/login/',LoginView.as_view(), name="login"),
path('accounts/logout/',LogoutView.as_view(), name='logout'),
path('accounts/register/',views.register, name='register'),
path('user/',views.user, name="user")
]
28 changes: 28 additions & 0 deletions DJANGO PROJECTS/Chat/chat/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from django.shortcuts import render, redirect
from .forms import NewUserForm
from django.contrib.auth import login
from django.contrib import messages

# Create your views here.
def index(request):
return render(request, 'index.html')

def register(request):
if request.method == "POST":
form = NewUserForm(request.POST)
if form.is_valid():
user = form.save()
login(request, user)
messages.success(request, 'Sign In successfull!')
return redirect('index')
messages.error(request, 'Invalid Information, Please try again!')
form = NewUserForm
return render(request, 'signin.html', context={'form':form})

def user(request):
user = request.user
context = {
'user' : user
}

return render(request, 'user.html', context)
22 changes: 22 additions & 0 deletions DJANGO PROJECTS/Chat/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
Empty file.
30 changes: 30 additions & 0 deletions DJANGO PROJECTS/Chat/project/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
ASGI config for project 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/4.1/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import AllowedHostsOriginValidator
from channels.auth import AuthMiddlewareStack

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

import room.routing

application = ProtocolTypeRouter(
{
"http":get_asgi_application(),
"websocket": AllowedHostsOriginValidator(
AuthMiddlewareStack(URLRouter(room.routing.websocket_urlpatterns))
)
}
)


Loading