forked from zmister2016/MrDoc
-
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
yangjian
committed
May 16, 2020
1 parent
91e0615
commit a884179
Showing
18 changed files
with
1,119 additions
and
125 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,10 +0,0 @@ | ||
from loguru import logger | ||
from django.conf import settings | ||
import os | ||
|
||
LOG_DIR = os.path.join(settings.BASE_DIR,'log') | ||
|
||
if os.path.exists(LOG_DIR) is False: | ||
os.makedirs(LOG_DIR) | ||
|
||
logger.add(os.path.join(LOG_DIR,'{time}.log'),rotation='1 days',retention='30 days',encoding='utf-8') | ||
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
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
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
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
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,52 @@ | ||
# coding:utf-8 | ||
# @文件: auth.py | ||
# @创建者:州的先生 | ||
# #日期:2020/5/11 | ||
# 博客地址:zmister.com | ||
|
||
from django.contrib.auth.models import User | ||
from rest_framework.authentication import BaseAuthentication | ||
from rest_framework.exceptions import AuthenticationFailed | ||
from app_api.models import * | ||
|
||
|
||
class AppAuth(BaseAuthentication): | ||
'''自定义认证类''' | ||
|
||
def authenticate(self, request): | ||
token = request.query_params.get('token') | ||
# print(token) | ||
if token: | ||
# 如果请求url中携带有token参数 | ||
user_obj = AppUserToken.objects.filter(token=token).first() | ||
if user_obj: | ||
# print("ok") | ||
# token 是有效的,返回一个元组 | ||
return user_obj.user, token # request.user, request.auth | ||
else: | ||
# raise AuthenticationFailed('无效的token') | ||
return None | ||
else: | ||
# raise AuthenticationFailed('请求的URL中必须携带token参数') | ||
return None | ||
|
||
|
||
class AppMustAuth(BaseAuthentication): | ||
'''自定义认证类''' | ||
|
||
def authenticate(self, request): | ||
token = request.query_params.get('token') | ||
# print(token) | ||
if token: | ||
# 如果请求url中携带有token参数 | ||
user_obj = AppUserToken.objects.filter(token=token).first() | ||
if user_obj: | ||
# print("ok") | ||
# token 是有效的,返回一个元组 | ||
return user_obj.user, token # request.user, request.auth | ||
else: | ||
raise AuthenticationFailed('无效的token') | ||
# return None | ||
else: | ||
raise AuthenticationFailed('请求的URL中必须携带token参数') | ||
# return None |
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,28 @@ | ||
# Generated by Django 2.2.12 on 2020-05-11 20:56 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('app_api', '0002_auto_20200322_0929'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='AppUserToken', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('token', models.CharField(max_length=250, unique=True, verbose_name='token值')), | ||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'verbose_name': 'App用户Token', | ||
'verbose_name_plural': 'App用户Token', | ||
}, | ||
), | ||
] |
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
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,31 @@ | ||
# coding:utf-8 | ||
# @文件: permissions.py | ||
# @创建者:州的先生 | ||
# #日期:2020/5/11 | ||
# 博客地址:zmister.com | ||
|
||
from rest_framework.permissions import BasePermission,SAFE_METHODS | ||
|
||
|
||
class AppPermission(BasePermission): | ||
message = '只有VIP才能访问' | ||
|
||
def has_permission(self, request, view): | ||
# vip才有访问权限 | ||
# request.user:当前经过认证的用户对象 | ||
# 如果没有认证 request.user就是匿名用户 | ||
if not request.auth: | ||
# 认证没有通过 | ||
return False | ||
if request.user.vip: | ||
return True | ||
else: | ||
return False | ||
|
||
def has_object_permission(self, request, view, obj): | ||
|
||
if request.method in SAFE_METHODS: | ||
return True | ||
|
||
# 示例必须要有一个名为`owner`的属性 | ||
return obj.owner == request.user |
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,44 @@ | ||
# coding:utf-8 | ||
# @文件: serializers_app.py | ||
# @创建者:州的先生 | ||
# #日期:2020/5/11 | ||
# 博客地址:zmister.com | ||
|
||
from rest_framework.serializers import ModelSerializer | ||
from app_doc.models import * | ||
|
||
# 文集序列化器 | ||
class ProjectSerializer(ModelSerializer): | ||
class Meta: | ||
model = Project | ||
fields = ('__all__') | ||
|
||
# 文档序列化器 | ||
class DocSerializer(ModelSerializer): | ||
class Meta: | ||
model = Doc | ||
fields = ('__all__') | ||
|
||
# 文档模板序列化器 | ||
class DocTempSerializer(ModelSerializer): | ||
class Meta: | ||
model = DocTemp | ||
fields = ('__all__') | ||
|
||
# 图片序列化器 | ||
class ImageSerializer(ModelSerializer): | ||
class Meta: | ||
model = Image | ||
fields = ('__all__') | ||
|
||
# 图片分组序列化器 | ||
class ImageGroupSerializer(ModelSerializer): | ||
class Meta: | ||
model = ImageGroup | ||
fields = ('__all__') | ||
|
||
# 附件序列化器 | ||
class AttachmentSerializer(ModelSerializer): | ||
class Meta: | ||
model = Attachment | ||
fields = ('__all__') |
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,17 @@ | ||
# coding:utf-8 | ||
# @文件: urls_app.py | ||
# @创建者:州的先生 | ||
# #日期:2020/5/11 | ||
# 博客地址:zmister.com | ||
from django.urls import path,re_path | ||
from app_api import views_app | ||
|
||
urlpatterns = [ | ||
path('login/',views_app.LoginView.as_view()),# 登录 | ||
path('projects/',views_app.ProjectView.as_view()), # 文集 | ||
path('docs/',views_app.DocView.as_view()), # 文档 | ||
path('doctemps/',views_app.DocTempView.as_view()), # 文档模板 | ||
path('images/',views_app.ImageView.as_view()), # 图片 | ||
path('imggroups/',views_app.ImageGroupView.as_view()), # 图片分组 | ||
path('attachments/',views_app.AttachmentView.as_view()), # 附件 | ||
] |
Oops, something went wrong.