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
24 changes: 16 additions & 8 deletions reallibrary/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@

import os

from dotenv import load_dotenv

#from dotenv import load_dotenv
from pathlib import Path

load_dotenv()
#load_dotenv()

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand Down Expand Up @@ -45,6 +46,7 @@
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"web.apps.WebConfig",
]

MIDDLEWARE = [
Expand All @@ -55,6 +57,7 @@
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",

]

ROOT_URLCONF = "reallibrary.urls"
Expand Down Expand Up @@ -84,11 +87,11 @@
DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": os.environ.get("MYSQL_DATABASE"),
"HOST": os.environ.get("MYSQL_DATABASE_HOST"),
"PORT": os.environ.get("MYSQL_DATABASE_PORT"),
"USER": os.environ.get("MYSQL_USER"),
"PASSWORD": os.environ.get("MYSQL_PASSWORD"),
"NAME": 'FinalDemo',
"HOST": '127.0.0.1',
"PORT": '3306',
"USER": 'root',
"PASSWORD": 'liuyuyang',
}
}

Expand Down Expand Up @@ -127,7 +130,12 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/

STATIC_URL = "static/"
STATIC_URL = '/static/'

STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]


# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
Expand Down
8 changes: 8 additions & 0 deletions reallibrary/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@
from django.contrib import admin
from django.urls import include, path

from web.views import index,logins,regist,log_out
from reallibrary import settings
from django.conf.urls.static import static

urlpatterns = [
path("events/", include("events.urls")),
path("inventory/", include("inventory.urls")),
path("rooms/", include("rooms.urls")),
path("admin/", admin.site.urls),
path("",index,name='home_page'),
path("regist/",regist,name='regist_page'),
path("login/",logins,name="log_in_page"),
path("logout/",log_out)
]
Empty file added web/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions web/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 web/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class WebConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "web"
Empty file added web/migrations/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions web/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.
Binary file added web/static/img/library.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/static/img/publications.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions web/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{%load static%}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
<title>Home Page</title>
</head>

<body style="background-color: rgb(245, 245, 245);">
<div style="min-height: 70px;" class="ui inverted fixed stackable blue large menu">
<a class="item">Real-Libarary System</a>
{%if request.user.is_active %}
<div class="right menu">
<a class="item">{{request.user.username}}</a>
<a class="item" href="/logout/">Log out</a>

</div>
{% else %}
<div class="right menu">
<a class="item" href="/regist/">Register</a>
<a class="item" href="/login/">Log in</a>
</div>
{%endif%}
</div>

<div align="center">
<img src="{% static 'img/library.jpg' %}" alt="My image">
</div>



<div style="padding: 30px 0 30px 0;" class="ui vertical segment">
<div class="ui centered grid">
<div class="ui pagination menu">
<a class="item">
<i class="icon left arrow"></i>
</a>

<a class="item" href="events/">
Events
</a>

<a class="item" href="rooms/">
Rooms
</a>
<a class="item" href="inventory/">
Inventory
</a>

<a class="item">
<i class="icon right arrow"></i>
</a>
</div>

</div>
</div>
</div>





</body>

</html>
38 changes: 38 additions & 0 deletions web/templates/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
<title>Log in</title>
</head>

<body style="background-image: url(img/backimg.gif);">
<div style="width: 70%; margin: 0 auto; padding-top: 20em;padding-bottom: 20em;">
<div class="ui stackable centered column grid">
<div class="centered row">
<div class="six wide column">
<div style="padding-bottom: 5em; background-color: rgba(245, 245, 245,0.5);" class="ui segment">
<form action="" method="POST" class="ui form">
{%csrf_token%}
<h3 style="color: red;">{{msg}}</h3>
<div class="field">
<label for="username">Username:</label>
<input type="text" name="username" id="">
</div>
<div class="field">
<label for="password">Password:</label>
<input type="password" name="password" id="">
</div>
<input style="float: right;" class="ui inverted blue button" type="submit" value="Log in">
</form>
</div>
</div>
</div>
</div>
</div>

</body>

</html>
46 changes: 46 additions & 0 deletions web/templates/regist.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
<title>注册</title>
</head>

<body style="background-image: url(img/backimg.gif);">
<div style="width: 70%; margin: 0 auto; padding-top: 20em;padding-bottom: 20em;">
<div class="ui stackable centered column grid">
<div class="centered row">
<div class="six wide column">
<div style="padding-bottom: 5em; background-color: rgba(245, 245, 245,0.5);" class="ui segment">
<form action="" method="POST" class="ui form">
{%csrf_token%}
<h3 style="color: red;">{{msg}}</h3>
<div class="field">
<label for="username">Username:</label>
<input type="text" name="username" id="">
</div>
<div class="field">
<label for="password">Password:</label>
<input type="password" name="password" id="">
</div>
<div class="field">
<label for="password2">Confirm Password:</label>
<input type="password" name="password2" id="">
</div>
<div class="field">
<label for="email">Email:</label>
<input type="text" name="email" id="">
</div>
<input style="float: right;" class="ui inverted blue button" type="submit" value="Regist">
</form>
</div>
</div>
</div>
</div>

</div>
</body>

</html>
3 changes: 3 additions & 0 deletions web/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.
47 changes: 47 additions & 0 deletions web/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

from django.shortcuts import render, redirect
from django.contrib.auth.models import User
from django.contrib.auth import authenticate,login,logout
# Create your views here.
def index(request):
return render(request,'index.html')

def logins(request):
if(request.method=='POST'):
username=request.POST.get('username')
password=request.POST.get('password')
user=authenticate(username=username,password=password)
if user:
login(request,user)
return redirect('/')
else:
msg=('Incorrect Password')
return render(request,'login.html',locals())
return render(request,'login.html')


def regist(request):
if(request.method=='POST'):
username=request.POST.get('username')
password=request.POST.get('password')
password2=request.POST.get('password2')
email=request.POST.get('email')
if(password!=password2):
msg='the confirmed password not matched'
return render(request,'regist.html',locals())
elif username=='':
msg='password should not be null'
return render(request,'regist.html',locals())
cuser=User.objects.create_user(username=username,password=password,email=email)
cuser.save()
return redirect('/login/')
return render(request,'regist.html')


def log_out(request):
logout(request)
return redirect('/')