-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
613 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from django.contrib import admin | ||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class ConsumerserverConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'ConsumerServer' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Generated by Django 4.0.2 on 2022-02-27 12:01 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='userP', | ||
fields=[ | ||
('userP_id', models.IntegerField(primary_key=True, serialize=False)), | ||
('img', models.CharField(max_length=256, null=True)), | ||
('buy', models.CharField(max_length=256, null=True)), | ||
('sellout', models.CharField(max_length=256, null=True)), | ||
('address', models.CharField(max_length=256, null=True)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='userS', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('user_name', models.CharField(max_length=256)), | ||
('nick', models.CharField(max_length=256)), | ||
('phone_number', models.CharField(max_length=256)), | ||
('email', models.CharField(max_length=256, null=True)), | ||
('password', models.CharField(max_length=256)), | ||
('department', models.CharField(max_length=256, null=True)), | ||
('specialty', models.CharField(max_length=256, null=True)), | ||
('puissance', models.IntegerField(default=1)), | ||
('register_date', models.DateField(auto_now_add=True)), | ||
], | ||
), | ||
] |
Empty file.
Binary file added
BIN
+1.08 KB
HServer/ConsumerServer/migrations/__pycache__/0001_initial.cpython-38.pyc
Binary file not shown.
Binary file added
BIN
+155 Bytes
HServer/ConsumerServer/migrations/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import email | ||
from django.db import models | ||
|
||
# Create your models here. | ||
class userS(models.Model): | ||
user_name=models.CharField(max_length=256,null=False) | ||
nick=models.CharField(max_length=256,null=False) | ||
phone_number=models.CharField(max_length=256,null=False) | ||
email=models.CharField(max_length=256,null=True) | ||
password=models.CharField(max_length=256,null=False) | ||
|
||
department=models.CharField(max_length=256,null=True) | ||
specialty=models.CharField(max_length=256,null=True) | ||
#权限 | ||
puissance=models.IntegerField(default=1 ) | ||
register_date=models.DateField(auto_now_add=True) | ||
class userP(models.Model): | ||
userP_id=models.IntegerField(primary_key=True) | ||
img=models.CharField(max_length=256,null=True) | ||
buy=models.CharField(max_length=256,null=True) | ||
sellout=models.CharField(max_length=256,null=True) | ||
address=models.CharField(max_length=256,null=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from urllib.parse import urlparse | ||
from django.urls import URLPattern, path | ||
|
||
from ConsumerServer import views | ||
|
||
urlpatterns={ | ||
|
||
path('login/',views.user_login), | ||
path("register",views.user_register), | ||
path('validation_session/',views.validation_session), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
|
||
from asyncio.windows_events import NULL | ||
from distutils.log import error | ||
|
||
import json | ||
from msilib.schema import Error | ||
from pyexpat import model | ||
from tkinter import E | ||
from django.http import HttpResponse | ||
from ConsumerServer.models import userP, userS | ||
#登录 | ||
def user_login(request): | ||
json_data=json.loads(request.body) | ||
phone= json_data.get("phone_number") | ||
user_pa=json_data.get("password") | ||
#session | ||
try: | ||
sql=userS.objects.get(phone_number=phone) | ||
if(sql!=''): | ||
if(sql.password==user_pa): | ||
request.session['user_id']=sql.id | ||
redata={ | ||
'code':200, | ||
'msg':'登录成功', | ||
'session':request.session.session_key, | ||
'data':{ | ||
'user_name':sql.user_name, | ||
'nick':sql.user_nick, | ||
'img':userP.objects.get(id=sql.id), | ||
} | ||
} | ||
return HttpResponse(json.dumps(redata,indent=4)) | ||
else: | ||
redata={ | ||
'code':500, | ||
'msg':'账号密码错误', | ||
'data':None | ||
} | ||
return HttpResponse(json.dumps(redata,indent=4)) | ||
else: | ||
return HttpResponse() | ||
except userS.DoesNotExist: | ||
|
||
redata={ | ||
'code':500, | ||
'msg':'账号密码错误', | ||
'data':'', | ||
} | ||
return HttpResponse(json.dumps(redata,indent=4)) | ||
|
||
|
||
|
||
def validation_session(request): | ||
if( request.session.get('user_id',None)!=None): | ||
redata={ | ||
'code':200, | ||
'msg':'有效session', | ||
'data':None | ||
} | ||
return HttpResponse(json.dumps(redata,indent=4)) | ||
else: | ||
redata={ | ||
'code':500, | ||
'msg':'无效效session', | ||
'data':None | ||
} | ||
return HttpResponse(json.dumps(redata,indent=4)) | ||
def user_register(requset): | ||
json_data=json.loads(requset.body) | ||
|
||
try: | ||
userS.objects.get(phone_number=json_data.get("phone_number")) | ||
|
||
redata={ | ||
'code':500, | ||
'msg':'手机号以被注册', | ||
'data':None | ||
} | ||
return HttpResponse(json.dumps(redata,indent=4)) | ||
except userS.DoesNotExist: | ||
userS.objects.create(user_name=json_data.get("user_name"), | ||
nick=json_data.get("nick"), | ||
phone_number=json_data.get("phone_number"), | ||
password=json_data.get("password"),puissance=1) | ||
user=userS.objects.get(phone_number=json_data.get("phone_number")) | ||
userP.objects.create(userP_id=user.id) | ||
redata={ | ||
'code':200, | ||
'msg':'注册成功200', | ||
'data':None | ||
} | ||
return HttpResponse(json.dumps(redata,indent=4)) | ||
|
||
|
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
ASGI config for HServer 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/3.2/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'HServer.settings') | ||
|
||
application = get_asgi_application() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
""" | ||
Django settings for HServer project. | ||
Generated by 'django-admin startproject' using Django 3.2.5. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/3.2/topics/settings/ | ||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/3.2/ref/settings/ | ||
""" | ||
|
||
import os | ||
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/3.2/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = 'django-insecure-b)_!azix@j%m_s9yqk6sntjl+)@9x7j@8nya8wt#37w99n((@l' | ||
|
||
# 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', | ||
'ConsumerServer', | ||
'corsheaders', | ||
'app', | ||
] | ||
|
||
MIDDLEWARE = [ | ||
'django.middleware.security.SecurityMiddleware', | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'corsheaders.middleware.CorsMiddleware', | ||
|
||
'django.middleware.common.CommonMiddleware', | ||
# 'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
] | ||
|
||
ROOT_URLCONF = 'HServer.urls' | ||
|
||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'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 = 'HServer.wsgi.application' | ||
|
||
|
||
# Database | ||
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases | ||
|
||
DATABASES = { | ||
|
||
'default': { | ||
|
||
'ENGINE': 'django.db.backends.mysql', | ||
'NAME':'mzxy',#数据库名字 | ||
'USER':'root', | ||
'PASSWORD':'123', | ||
'HOST':'127.0.0.1', | ||
'PORT':'3306',#端口 | ||
'OPTIONS': {'charset':'utf8mb4'}, #打开数据库 编码格式 ——解决4字节表情无法储存问题 | ||
} | ||
|
||
} | ||
|
||
|
||
# Password validation | ||
# https://docs.djangoproject.com/en/3.2/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/3.2/topics/i18n/ | ||
|
||
LANGUAGE_CODE = 'en-us' | ||
|
||
TIME_ZONE = 'UTC' | ||
|
||
USE_I18N = True | ||
|
||
USE_L10N = True | ||
|
||
USE_TZ = True | ||
|
||
|
||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/3.2/howto/static-files/ | ||
|
||
STATIC_URL = '/static/' | ||
|
||
# Default primary key field type | ||
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field | ||
|
||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' | ||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/3.2/howto/static-files/ | ||
STATIC_URL = '/static/' #静态文件路由 | ||
# STATICFILES_DIRS = (os.path.join('../static'),)#静态文件位置(项目外层) | ||
MEDIA_URL = '/media/' #访问上传文件路由 正式后失效 | ||
MEDIA_ROOT = os.path.join('app/media')#上传文件位置 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""HServer URL Configuration | ||
The `urlpatterns` list routes URLs to views. For more information please see: | ||
https://docs.djangoproject.com/en/3.2/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 include, path | ||
|
||
|
||
urlpatterns = [ | ||
path('admin/', admin.site.urls), | ||
path('user/',include("ConsumerServer.urls")), | ||
path('app/',include("app.urls")), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
WSGI config for HServer 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/3.2/howto/deployment/wsgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'HServer.settings') | ||
|
||
application = get_wsgi_application() |
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
Oops, something went wrong.