45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
|
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("添加用户成功")
|