diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..507fb29 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +.venv/ \ No newline at end of file diff --git a/CMS_Django_Backend/__init__.py b/CMS_Django_Backend/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/CMS_Django_Backend/__pycache__/__init__.cpython-311.pyc b/CMS_Django_Backend/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..cd2958a Binary files /dev/null and b/CMS_Django_Backend/__pycache__/__init__.cpython-311.pyc differ diff --git a/CMS_Django_Backend/__pycache__/settings.cpython-311.pyc b/CMS_Django_Backend/__pycache__/settings.cpython-311.pyc new file mode 100644 index 0000000..089c21a Binary files /dev/null and b/CMS_Django_Backend/__pycache__/settings.cpython-311.pyc differ diff --git a/CMS_Django_Backend/__pycache__/urls.cpython-311.pyc b/CMS_Django_Backend/__pycache__/urls.cpython-311.pyc new file mode 100644 index 0000000..5c4af90 Binary files /dev/null and b/CMS_Django_Backend/__pycache__/urls.cpython-311.pyc differ diff --git a/CMS_Django_Backend/__pycache__/wsgi.cpython-311.pyc b/CMS_Django_Backend/__pycache__/wsgi.cpython-311.pyc new file mode 100644 index 0000000..7444898 Binary files /dev/null and b/CMS_Django_Backend/__pycache__/wsgi.cpython-311.pyc differ diff --git a/CMS_Django_Backend/asgi.py b/CMS_Django_Backend/asgi.py new file mode 100644 index 0000000..114a236 --- /dev/null +++ b/CMS_Django_Backend/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for CMS_Django_Backend 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.1/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'CMS_Django_Backend.settings') + +application = get_asgi_application() diff --git a/CMS_Django_Backend/settings.py b/CMS_Django_Backend/settings.py new file mode 100644 index 0000000..a667bc1 --- /dev/null +++ b/CMS_Django_Backend/settings.py @@ -0,0 +1,136 @@ +""" +Django settings for CMS_Django_Backend project. + +Generated by 'django-admin startproject' using Django 5.1. + +For more information on this file, see +https://docs.djangoproject.com/en/5.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/5.1/ref/settings/ +""" + +from pathlib import Path + +# 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.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-mm$)j^vw#wtb$%f2m-=p@4d4ziy^-_zv^t21(i@9j+7+#eqzby' + +# 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', + 'apps.auth.apps.AuthConfig', + 'apps.api.apps.ApiConfig', +] + +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 = 'CMS_Django_Backend.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [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 = 'CMS_Django_Backend.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/5.1/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'data/db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/5.1/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.1/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.1/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +# session设置 +# 设置会话cookie的有效期(默认为两周) +# SESSION_COOKIE_AGE = 1209600 # 2 weeks, in seconds + +# 设置会话cookie的过期时间(默认为False,表示关闭浏览器时失效) +SESSION_EXPIRE_AT_BROWSER_CLOSE = True + +# 如果设置了True,每次用户会话更新时,会话cookie的过期时间都会被更新 +SESSION_SAVE_EVERY_REQUEST = False \ No newline at end of file diff --git a/CMS_Django_Backend/urls.py b/CMS_Django_Backend/urls.py new file mode 100644 index 0000000..a26249f --- /dev/null +++ b/CMS_Django_Backend/urls.py @@ -0,0 +1,26 @@ +""" +URL configuration for CMS_Django_Backend project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/5.1/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 + +urlpatterns = [ + # path('admin/', admin.site.urls), + # path('login', include('apps.login.urls')) + # path('auth', include('apps.auth.urls')) + path('api/', include('apps.api.urls')), + path('auth/', include('apps.auth.urls')) +] diff --git a/CMS_Django_Backend/wsgi.py b/CMS_Django_Backend/wsgi.py new file mode 100644 index 0000000..83b669b --- /dev/null +++ b/CMS_Django_Backend/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for CMS_Django_Backend 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.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'CMS_Django_Backend.settings') + +application = get_wsgi_application() diff --git a/apps/api/__init__.py b/apps/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/apps/api/__pycache__/__init__.cpython-311.pyc b/apps/api/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..2bc0fb4 Binary files /dev/null and b/apps/api/__pycache__/__init__.cpython-311.pyc differ diff --git a/apps/api/__pycache__/apps.cpython-311.pyc b/apps/api/__pycache__/apps.cpython-311.pyc new file mode 100644 index 0000000..bc42f2b Binary files /dev/null and b/apps/api/__pycache__/apps.cpython-311.pyc differ diff --git a/apps/api/__pycache__/models.cpython-311.pyc b/apps/api/__pycache__/models.cpython-311.pyc new file mode 100644 index 0000000..2c7b127 Binary files /dev/null and b/apps/api/__pycache__/models.cpython-311.pyc differ diff --git a/apps/api/__pycache__/urls.cpython-311.pyc b/apps/api/__pycache__/urls.cpython-311.pyc new file mode 100644 index 0000000..d30a7a9 Binary files /dev/null and b/apps/api/__pycache__/urls.cpython-311.pyc differ diff --git a/apps/api/__pycache__/views.cpython-311.pyc b/apps/api/__pycache__/views.cpython-311.pyc new file mode 100644 index 0000000..9f70a66 Binary files /dev/null and b/apps/api/__pycache__/views.cpython-311.pyc differ diff --git a/apps/api/admin.py b/apps/api/admin.py new file mode 100644 index 0000000..ea5d68b --- /dev/null +++ b/apps/api/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/apps/api/apps.py b/apps/api/apps.py new file mode 100644 index 0000000..404048b --- /dev/null +++ b/apps/api/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ApiConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'apps.api' diff --git a/apps/api/migrations/0001_initial.py b/apps/api/migrations/0001_initial.py new file mode 100644 index 0000000..d00b4ab --- /dev/null +++ b/apps/api/migrations/0001_initial.py @@ -0,0 +1,28 @@ +# Generated by Django 5.1 on 2024-08-17 09:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='SysConfig', + fields=[ + ('id', models.AutoField(primary_key=True, serialize=False, unique=True, verbose_name='id')), + ('name', models.CharField(blank=True, max_length=50, null=True, unique=True, verbose_name='名称')), + ('identity', models.CharField(blank=True, max_length=100, null=True, verbose_name='标识')), + ('param', models.CharField(blank=True, max_length=200, null=True, verbose_name='参数')), + ('desc', models.CharField(max_length=500, verbose_name='描述')), + ('create_by', models.CharField(max_length=50, verbose_name='创建人')), + ('create_time', models.DateTimeField(verbose_name='创建时间')), + ('update_by', models.CharField(max_length=50, verbose_name='更新人')), + ('update_time', models.DateTimeField(auto_now=True, verbose_name='更新时间')), + ], + ), + ] diff --git a/apps/api/migrations/0002_alter_sysconfig_options.py b/apps/api/migrations/0002_alter_sysconfig_options.py new file mode 100644 index 0000000..b0c6ed2 --- /dev/null +++ b/apps/api/migrations/0002_alter_sysconfig_options.py @@ -0,0 +1,17 @@ +# Generated by Django 5.1 on 2024-08-17 15:22 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0001_initial'), + ] + + operations = [ + migrations.AlterModelOptions( + name='sysconfig', + options={'verbose_name': '系统配置表'}, + ), + ] diff --git a/apps/api/migrations/__init__.py b/apps/api/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/apps/api/migrations/__pycache__/0001_initial.cpython-311.pyc b/apps/api/migrations/__pycache__/0001_initial.cpython-311.pyc new file mode 100644 index 0000000..87fd133 Binary files /dev/null and b/apps/api/migrations/__pycache__/0001_initial.cpython-311.pyc differ diff --git a/apps/api/migrations/__pycache__/0002_alter_sysconfig_options.cpython-311.pyc b/apps/api/migrations/__pycache__/0002_alter_sysconfig_options.cpython-311.pyc new file mode 100644 index 0000000..311493d Binary files /dev/null and b/apps/api/migrations/__pycache__/0002_alter_sysconfig_options.cpython-311.pyc differ diff --git a/apps/api/migrations/__pycache__/__init__.cpython-311.pyc b/apps/api/migrations/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..2c2b0cd Binary files /dev/null and b/apps/api/migrations/__pycache__/__init__.cpython-311.pyc differ diff --git a/apps/api/models.py b/apps/api/models.py new file mode 100644 index 0000000..3a00659 --- /dev/null +++ b/apps/api/models.py @@ -0,0 +1,24 @@ +from django.db import models + + +# Create your models here. +class SysConfig(models.Model): + """ + 系统配置表 + """ + id = models.AutoField(verbose_name="id", primary_key=True, unique=True) + name = models.CharField(max_length=50, unique=True, verbose_name="名称", null=True, blank=True) + identity = models.CharField(max_length=100, verbose_name="标识", null=True, blank=True) + param = models.CharField(max_length=200, verbose_name="参数", null=True, blank=True) + desc = models.CharField(max_length=500, verbose_name="描述") + create_by = models.CharField(verbose_name="创建人", max_length=50) + create_time = models.DateTimeField(verbose_name="创建时间") + update_by = models.CharField(verbose_name="更新人", max_length=50) + update_time = models.DateTimeField(verbose_name="更新时间", auto_now=True) + + def __str__(self): + return self.name + + class Meta: + verbose_name = "系统配置表" + diff --git a/apps/api/tests.py b/apps/api/tests.py new file mode 100644 index 0000000..de8bdc0 --- /dev/null +++ b/apps/api/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/apps/api/urls.py b/apps/api/urls.py new file mode 100644 index 0000000..62e0f4d --- /dev/null +++ b/apps/api/urls.py @@ -0,0 +1,6 @@ +from django.urls import path +from apps.api import views + +urlpatterns = [ + path("getconfig/", views.getconfig, name="getconfig"), +] diff --git a/apps/api/views.py b/apps/api/views.py new file mode 100644 index 0000000..6209299 --- /dev/null +++ b/apps/api/views.py @@ -0,0 +1,15 @@ +from django.shortcuts import HttpResponse +from apps.api import models as m_api +from django.views.decorators.http import require_http_methods, require_POST, require_GET + + +# Create your views here. +@require_POST +def getconfig(request): + try: + param = request.POST.get("param") + title = m_api.SysConfig.objects.filter(identity=param).first().param + return HttpResponse(title) + except Exception as e: + print(f"报错了:{e}") + return HttpResponse("报错了") diff --git a/apps/auth/__init__.py b/apps/auth/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/apps/auth/__pycache__/__init__.cpython-311.pyc b/apps/auth/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..2d36a05 Binary files /dev/null and b/apps/auth/__pycache__/__init__.cpython-311.pyc differ diff --git a/apps/auth/__pycache__/apps.cpython-311.pyc b/apps/auth/__pycache__/apps.cpython-311.pyc new file mode 100644 index 0000000..39ca4e9 Binary files /dev/null and b/apps/auth/__pycache__/apps.cpython-311.pyc differ diff --git a/apps/auth/__pycache__/models.cpython-311.pyc b/apps/auth/__pycache__/models.cpython-311.pyc new file mode 100644 index 0000000..34f0112 Binary files /dev/null and b/apps/auth/__pycache__/models.cpython-311.pyc differ diff --git a/apps/auth/__pycache__/urls.cpython-311.pyc b/apps/auth/__pycache__/urls.cpython-311.pyc new file mode 100644 index 0000000..f3cf3dd Binary files /dev/null and b/apps/auth/__pycache__/urls.cpython-311.pyc differ diff --git a/apps/auth/__pycache__/views.cpython-311.pyc b/apps/auth/__pycache__/views.cpython-311.pyc new file mode 100644 index 0000000..12eec60 Binary files /dev/null and b/apps/auth/__pycache__/views.cpython-311.pyc differ diff --git a/apps/auth/admin.py b/apps/auth/admin.py new file mode 100644 index 0000000..ea5d68b --- /dev/null +++ b/apps/auth/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/apps/auth/apps.py b/apps/auth/apps.py new file mode 100644 index 0000000..d80539a --- /dev/null +++ b/apps/auth/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class AuthConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'apps.auth' diff --git a/apps/auth/migrations/0001_initial.py b/apps/auth/migrations/0001_initial.py new file mode 100644 index 0000000..1fe0c2e --- /dev/null +++ b/apps/auth/migrations/0001_initial.py @@ -0,0 +1,30 @@ +# Generated by Django 5.1 on 2024-08-17 15:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='User', + fields=[ + ('id', models.AutoField(primary_key=True, serialize=False, unique=True, verbose_name='id')), + ('username', models.CharField(blank=True, max_length=50, null=True, unique=True, verbose_name='用户名')), + ('pwd', models.CharField(blank=True, max_length=1000, null=True, verbose_name='密码')), + ('email', models.CharField(blank=True, max_length=100, null=True, verbose_name='电子邮件')), + ('phone', models.CharField(max_length=11, verbose_name='手机')), + ('create_time', models.DateTimeField(verbose_name='注册时间')), + ('avatar', models.ImageField(upload_to='', verbose_name='头像')), + ('last_login_time', models.DateTimeField(auto_now=True, verbose_name='最后登录时间')), + ], + options={ + 'verbose_name': '用户表', + }, + ), + ] diff --git a/apps/auth/migrations/__init__.py b/apps/auth/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/apps/auth/migrations/__pycache__/0001_initial.cpython-311.pyc b/apps/auth/migrations/__pycache__/0001_initial.cpython-311.pyc new file mode 100644 index 0000000..103fd9b Binary files /dev/null and b/apps/auth/migrations/__pycache__/0001_initial.cpython-311.pyc differ diff --git a/apps/auth/migrations/__pycache__/__init__.cpython-311.pyc b/apps/auth/migrations/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..8156bcd Binary files /dev/null and b/apps/auth/migrations/__pycache__/__init__.cpython-311.pyc differ diff --git a/apps/auth/models.py b/apps/auth/models.py new file mode 100644 index 0000000..1a44ed0 --- /dev/null +++ b/apps/auth/models.py @@ -0,0 +1,22 @@ +from django.db import models + + +# Create your models here. +class User(models.Model): + """ + 用户表 + """ + id = models.AutoField(verbose_name="id", primary_key=True, unique=True) + username = models.CharField(max_length=50, unique=True, verbose_name="用户名", null=True, blank=True) + pwd = models.CharField(max_length=1000, verbose_name="密码", null=True, blank=True) + email = models.CharField(max_length=100, verbose_name="电子邮件") + phone = models.CharField(max_length=11, verbose_name="手机", null=True, blank=True) + create_time = models.DateTimeField(verbose_name="注册时间") + avatar = models.ImageField(verbose_name="头像") + last_login_time = models.DateTimeField(verbose_name="最后登录时间", auto_now=True) + + def __str__(self): + return self.username + + class Meta: + verbose_name = '用户表' diff --git a/apps/auth/tests.py b/apps/auth/tests.py new file mode 100644 index 0000000..de8bdc0 --- /dev/null +++ b/apps/auth/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/apps/auth/urls.py b/apps/auth/urls.py new file mode 100644 index 0000000..1851d14 --- /dev/null +++ b/apps/auth/urls.py @@ -0,0 +1,7 @@ +from django.urls import path +from apps.auth import views + +urlpatterns = [ + path("gettoken/", views.gettoken, name="getToken"), + path("searchuser/", views.search_user, name="searchuser"), +] diff --git a/apps/auth/views.py b/apps/auth/views.py new file mode 100644 index 0000000..56bdf45 --- /dev/null +++ b/apps/auth/views.py @@ -0,0 +1,44 @@ +import json +from django.shortcuts import HttpResponse +from django.middleware.csrf import get_token +from django.views.decorators.http import require_GET, require_POST +from apps.auth import models as auth_models + + +# Create your views here. +@require_GET +def gettoken(request): + """ + 获取token + :param request: + :return: + """ + token = get_token(request) + return HttpResponse(json.dumps({'token': token}), content_type="application/json,charset=utf-8") + + +@require_POST +def search_user(request): + """ + 查询用户名 + :param request: + :return: + """ + username = request.POST.get('username') + user = auth_models.User.objects.filter(username=username) + if user.exists(): + return HttpResponse("用户名已存在") + else: + return HttpResponse(True) + + +@require_POST +def adduser(request): + """ + 用户注册 + :param request: POST提交注册信息 + :return: 注册结果 + + 先查询数据库中用户名username是否存在,如果存在则提示用户更改用户名,若不存在则进行存储 + """ + return HttpResponse("添加用户成功") diff --git a/data/db.sqlite3 b/data/db.sqlite3 new file mode 100644 index 0000000..c2fb4b7 Binary files /dev/null and b/data/db.sqlite3 differ diff --git a/data/db.sqlite3.sql b/data/db.sqlite3.sql new file mode 100644 index 0000000..e69de29 diff --git a/data/initdata.json b/data/initdata.json new file mode 100644 index 0000000..756a81c --- /dev/null +++ b/data/initdata.json @@ -0,0 +1,16 @@ +[ + { + "model": "api.sysconfig", + "pk": 1, + "fields": { + "name": "系统名称", + "identity":"SysTitle", + "param":"图书管理系统", + "desc":"登录界面显示的系统标题", + "create_by":"admin", + "create_time":"2024-08-16 23:39:50", + "update_by":"admin", + "update_time":"2024-08-16 23:39:50" + } + } +] \ No newline at end of file diff --git a/manage.py b/manage.py new file mode 100644 index 0000000..f1ac0b9 --- /dev/null +++ b/manage.py @@ -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', 'CMS_Django_Backend.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()