first updata

This commit is contained in:
2024-02-26 18:17:15 +08:00
commit 1ec018ca90
162 changed files with 123649 additions and 0 deletions
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+3
View File
@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.
+6
View File
@@ -0,0 +1,6 @@
from django.apps import AppConfig
class ServerAuthConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'server_auth'
View File
Binary file not shown.
Binary file not shown.
+80
View File
@@ -0,0 +1,80 @@
from django import http
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.backends import ModelBackend # 验证基类
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import redirect
from django.urls import reverse
from rest_framework.views import APIView
from server.util.constant_util import *
from server.util.mix_util import build_response
class AuthBackend(ModelBackend):
"""
login 方法会调用该方法
"""
pass
# 重写验证方式
# def authenticate(self, request, username=None, password=None, **kwargs):
# user = MindUser.objects.get(id=1)
# if user is not None and user.check_password(password):
# return user
# 登录方式有多种
# 1、用户名密码登录:直接匹配数据库的用户名密码
# 2、微信扫码登录:1、生成带标记的二维码 2、用户扫码 3、微信通知服务器端 4、服务器校验是否有注册,如果没有注册则新增用户 5、服务器通知前端界面
# 3、手机号短信验证码登录 1、发送短信验证码 2、用户界面向服务器提交手机号和验证码 3、服务器请求短服务商 4、服务器校验是否有注册,如果没有注册则新增用户
class LoginView(APIView):
"""
"""
def post(self, request):
username = request.POST.get('username')
password = request.POST.get('password')
# django内置认证来校验登录用户
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
# 记住登录状态
login(request, user)
return build_response(msg='登录成功')
else:
return build_response(code=CODE_FAILED, msg='登录失败')
else:
return build_response(code=CODE_FAILED, msg='登录失败')
class LogoutView(APIView):
"""
注销
"""
def get(self, request):
logout(request)
return build_response(msg='注销成功')
def post(self, request):
logout(request)
return build_response(msg='注销成功')
class LoginRequiredJSONMixin(LoginRequiredMixin):
"""自定义LoginRequiredMixin
如果用户未登录,响应JSON,且状态码为400
"""
def handle_no_permission(self):
# return build_response(code=CODE_FAILED, msg='用户未登录!')
return http.JsonResponse({'code': CODE_FAILED, 'msg': '用户未登录'})
+46
View File
@@ -0,0 +1,46 @@
# Generated by Django 3.2.11 on 2022-06-29 08:18
import django.contrib.auth.models
import django.contrib.auth.validators
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
]
operations = [
migrations.CreateModel(
name='MindUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('wx_openid', models.CharField(blank=True, max_length=64, null=True, verbose_name='微信openid')),
('wx_nick_name', models.CharField(blank=True, max_length=64, null=True, verbose_name='微信名称')),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
],
options={
'verbose_name': '脑图用户表',
'db_table': 'mind_user',
'ordering': ['-id'],
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]
View File
+15
View File
@@ -0,0 +1,15 @@
from django.db import models
from django.contrib.auth.models import AbstractUser
# Create your models here.
class MindUser(AbstractUser):
# 继承了AbstractUser拥有的所有字段
# 自定义我们需要的字段
wx_openid = models.CharField(verbose_name='微信openid', max_length=64, null=True, blank=True)
wx_nick_name = models.CharField(verbose_name='微信名称', max_length=64, null=True, blank=True)
class Meta:
db_table = 'mind_user'
ordering = ['-id']
verbose_name = "脑图用户表"
+3
View File
@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.
+9
View File
@@ -0,0 +1,9 @@
from django.shortcuts import render
# Create your views here.
def fetch_qr_code(request):
"""
获得二维码
"""
pass