0.2.1 增加 API 例子

This commit is contained in:
何全
2019-03-26 17:23:14 +08:00
parent b8fac35506
commit 23173f32a8
3 changed files with 22 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
from django.urls import path
from system.views import login_view, UserPasswordUpdateView, logout_view
from system.views import login_view, UserPasswordUpdateView, logout_view, GetInfo
app_name = "system"
@@ -7,4 +7,5 @@ urlpatterns = [
path('login', login_view, name="login"),
path('password_update', UserPasswordUpdateView.as_view(), name="password_update"),
path('logout', logout_view, name="logout"),
path('get_info', GetInfo.as_view()),
]

View File

@@ -1,5 +1,6 @@
import logging
from django.shortcuts import render
import json
from django.shortcuts import render, HttpResponse
from django.contrib.auth import authenticate, login
from django.shortcuts import redirect, render
from system.models import Users
@@ -15,8 +16,22 @@ from django.contrib.auth import logout
logger = logging.getLogger('system')
class CustomBackend(ModelBackend):
class GetInfo(View):
"""
为了 配合 seal-vue 项目 临时使用
"""
def get(self, request):
admin = {
'name': 'super_admin',
'user_id': '1',
'access': ['super_admin', 'admin'],
'token': 'super_admin',
'avator': 'https://file.iviewui.com/dist/a0e88e83800f138b94d2414621bd9704.png'
}
return HttpResponse(json.dumps(admin))
class CustomBackend(ModelBackend):
"""
用户名字/邮箱名字 登录
:param request:
@@ -61,7 +76,6 @@ def login_view(request):
return render(request, 'system/login.html', {'error_msg': error_msg, })
@login_required(login_url="/system/login")
def index(request):
"""
@@ -72,8 +86,6 @@ def index(request):
return render(request, 'system/index.html')
class UserPasswordUpdateView(LoginRequiredMixin, UpdateView):
"""
修改密码