Skip to content

Commit 73bd973

Browse files
committed
add login to project
1 parent 9cbe7f1 commit 73bd973

File tree

15 files changed

+71
-11
lines changed

15 files changed

+71
-11
lines changed

auth/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from email.policy import default
2+
3+
4+
# default

auth/apps.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33

44
class AuthConfig(AppConfig):
55
default_auto_field = 'django.db.models.BigAutoField'
6-
name = 'auth'
6+
name = 'auth.apps'
7+
label = 'authentication'

auth/templates/auth/login.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Login</title>
8+
</head>
9+
<body>
10+
<h2>Login</h2>
11+
<form method="post">
12+
{% csrf_token %} {{ form.as_p }}
13+
<button type="submit">Login</button>
14+
</form>
15+
</body>
16+
</html>

auth/urls.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""auth urls
2+
"""
3+
from django.urls import path
4+
from django.contrib.auth import views as auth_views
5+
# from . import views
6+
7+
urlpatterns = [
8+
path(
9+
'login/',
10+
auth_views.LoginView.as_view(
11+
template_name="auth/login.html"),
12+
name='login'),
13+
path(
14+
'logout/',
15+
auth_views.LogoutView.as_view(
16+
template_name="auth/logout.html"),
17+
name='logout'),
18+
]

auth/views.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
from django.shortcuts import render
2+
from django.views.generic import TemplateView
23

3-
# Create your views here.
4+
5+
class IndexPage(TemplateView):
6+
template_name = "login.html"

chat/admin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
from datetime import datetime
44
from django.contrib import admin
5-
from .models import Message
5+
from .models import Message, Chat
66

77

88
class MessageAdmin(admin.ModelAdmin):
@@ -16,3 +16,4 @@ def time(self, model: object):
1616

1717

1818
admin.site.register(Message, MessageAdmin)
19+
admin.site.register(Chat)

chat/models.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
from django.contrib.auth.models import User
33

44

5+
class Chat(models.Model):
6+
room_name = models.CharField(
7+
max_length=256,
8+
null=False, blank=False)
9+
members = models.ManyToManyField(
10+
User,
11+
blank=False)
12+
13+
def __str__(self):
14+
return self.room_name
15+
16+
517
class Message(models.Model):
618
author = models.ForeignKey(User, on_delete=models.CASCADE)
719
content = models.TextField()

chat/routing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
from . import consumer
55

66
websocket_urlpatterns = [
7-
re_path(r'ws/(?P<room_name>\w+)/$', consumer.ChatConsumer.as_asgi()),
7+
re_path(r'ws/chat/(?P<room_name>\w+)/$', consumer.ChatConsumer.as_asgi()),
88
]

chat/templates/index.html renamed to chat/templates/chat/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ <h1>all chat rooms</h1>
2020
<a href=""><li>test</li></a>
2121
</ul>
2222
<h2>create your chat room</h2>
23+
<h2>top room</h2>
24+
<h2>last room</h2>
25+
<h2>your room</h2>
2326
<script>
2427
document.querySelector("#room-name-input").focus();
2528
document.querySelector("#room-name-input").onkeyup = function (e) {
@@ -31,7 +34,7 @@ <h2>create your chat room</h2>
3134

3235
document.querySelector("#room-name-submit").onclick = function (e) {
3336
var roomName = document.querySelector("#room-name-input").value;
34-
window.location.pathname = "/" + roomName + "/";
37+
window.location.pathname = "/chat/" + roomName + "/";
3538
};
3639
</script>
3740
</body>

chat/templates/room.html renamed to chat/templates/chat/room.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
var username = {{ username }}
8989

9090
const chatSocket = new ReconnectingWebSocket(
91-
"ws://" + window.location.host + "/ws/" + roomName + "/"
91+
"ws://" + window.location.host + "/ws/chat/" + roomName + "/"
9292
);
9393

9494
chatSocket.onopen = function (e) {

0 commit comments

Comments
 (0)