|
@@ -7,6 +7,7 @@ import traceback
|
|
|
# from django.core.serializers.json import DjangoJSONEncoder
|
|
|
from django.contrib.auth.hashers import make_password, check_password
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
+from django.core.exceptions import ObjectDoesNotExist
|
|
|
from models import *
|
|
|
|
|
|
from common.common import (get_user_from_request, login_required,
|
|
@@ -27,7 +28,7 @@ def user_manage(request):
|
|
|
# user = request.session.get("user", None)
|
|
|
data = request.PARAMS
|
|
|
search_name = data.get("search_name", None)
|
|
|
- search_name = "ton"
|
|
|
+ # search_name = "ton"
|
|
|
print("search_name",search_name)
|
|
|
if search_name:
|
|
|
user_data = Users.objects.filter(username__icontains=search_name)
|
|
@@ -35,7 +36,7 @@ def user_manage(request):
|
|
|
user_data = Users.objects.all()
|
|
|
|
|
|
print("user_manage111",user_data)
|
|
|
- data =[]
|
|
|
+ data_show =[]
|
|
|
if user_data:
|
|
|
for list_data in user_data:
|
|
|
dict_data = {}
|
|
@@ -44,8 +45,8 @@ def user_manage(request):
|
|
|
dict_data["realname"] = list_data.real_name
|
|
|
dict_data["status"] = list_data.status
|
|
|
dict_data["permission"] = list_data.permission
|
|
|
- data.append(dict_data)
|
|
|
- res = {"code": 0, "msg": "get data success", "user_data": data}
|
|
|
+ data_show.append(dict_data)
|
|
|
+ res = {"code": 0, "msg": "get data success", "user_data": data_show}
|
|
|
|
|
|
else:
|
|
|
res = {"code": -1, "msg": "get no data!"}
|
|
@@ -82,12 +83,10 @@ def adduser(request):
|
|
|
obj.username = username
|
|
|
obj.real_name = real_name
|
|
|
obj.password = password
|
|
|
- obj.status = status
|
|
|
- obj.permission = permission
|
|
|
+ obj.status = int(status)
|
|
|
+ obj.permission = int(permission)
|
|
|
|
|
|
- obj.signup_time = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
|
|
|
obj.save()
|
|
|
-
|
|
|
return JsonResponse({"code": 0, "msg": u"注册成功"})
|
|
|
except:
|
|
|
traceback.print_exc()
|
|
@@ -103,7 +102,7 @@ def login(request):
|
|
|
:return: True / False
|
|
|
"""
|
|
|
data = request.PARAMS
|
|
|
-
|
|
|
+ print("login****",data)
|
|
|
if not data:
|
|
|
return JsonResponse({"code": -1, "msg": u"参数不完整"})
|
|
|
|
|
@@ -114,6 +113,7 @@ def login(request):
|
|
|
try:
|
|
|
user = Users.objects.get(username=username)
|
|
|
except ObjectDoesNotExist:
|
|
|
+ print("user not exit********")
|
|
|
return JsonResponse({"code": -1, "msg": u"该用户不存在"})
|
|
|
|
|
|
# 检查密码是否正确
|
|
@@ -124,7 +124,7 @@ def login(request):
|
|
|
print(user.username)
|
|
|
print(check_res)
|
|
|
if check_res:
|
|
|
- user_info = {"uid": user.id, "username": user.username,"realname": user.real_name,
|
|
|
+ user_info = {"uid":user.id, "username": user.username,"realname": user.real_name,
|
|
|
"status": user.status, "permission": user.permission,}
|
|
|
|
|
|
print("user_info",user_info)
|
|
@@ -155,7 +155,7 @@ def logout(request):
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
-# @login_required
|
|
|
+@login_required
|
|
|
@params
|
|
|
def modified_password(request):
|
|
|
"""
|
|
@@ -164,23 +164,27 @@ def modified_password(request):
|
|
|
:return: True / False
|
|
|
"""
|
|
|
user = get_user_from_request(request)
|
|
|
+ print("uuuuuuu",user)
|
|
|
req_params = request.PARAMS
|
|
|
old_password = req_params.get("old_password")
|
|
|
new_password = req_params.get("new_password")
|
|
|
-
|
|
|
- user_obj = Users.objects.get(id=int(user["uid"]))
|
|
|
- check_old = check_password(old_password, user_obj.password)
|
|
|
-
|
|
|
- print("mmmmmmm",check_old)
|
|
|
- res = {"code": 0, "msg": "success"}
|
|
|
- if check_old:
|
|
|
- new_pass = make_password(new_password, None, "pbkdf2_sha256")
|
|
|
- user_obj.password = new_pass
|
|
|
- user_obj.save()
|
|
|
+ uid = user["uid"]
|
|
|
+ print("*****uid",uid)
|
|
|
+ user_obj = Users.objects.filter(id=uid).first()
|
|
|
+ print("-----",user_obj)
|
|
|
+ if user_obj:
|
|
|
+ check_old = check_password(old_password, user_obj.password)
|
|
|
+
|
|
|
+ print("mmmmmmm",check_old)
|
|
|
+ if check_old:
|
|
|
+ new_pass = make_password(new_password, None, "pbkdf2_sha256")
|
|
|
+ user_obj.password = new_pass
|
|
|
+ user_obj.save()
|
|
|
+ res = {"code": 0, "msg": "success"}
|
|
|
+ else:
|
|
|
+ res = {"code": -1, "msg": "旧密码不正确"}
|
|
|
else:
|
|
|
- res["code"] = -1
|
|
|
- res["msg"] = u"旧密码不正确,请重新输入。"
|
|
|
-
|
|
|
+ res = {"code": 2, "msg": "没有登陆"}
|
|
|
print(res)
|
|
|
return JsonResponse(res)
|
|
|
|
|
@@ -195,25 +199,30 @@ def update_user(request):
|
|
|
:return: True / False
|
|
|
"""
|
|
|
req_params = request.PARAMS
|
|
|
- username = req_params.get("username", None)
|
|
|
-
|
|
|
- status = req_params.get("status")
|
|
|
- permission = req_params.get("permission")
|
|
|
- print "username --> ", username
|
|
|
- print "status --> ", status
|
|
|
- print "permission --> ", permission
|
|
|
+ if req_params:
|
|
|
+ try:
|
|
|
+ # username = req_params.get("username")
|
|
|
+ uid = req_params.get("uid")
|
|
|
+ status = req_params.get("status")
|
|
|
+ permission = req_params.get("permission")
|
|
|
+ print "status --> ", status
|
|
|
+ print "permission --> ", permission
|
|
|
|
|
|
- user_obj = Users.objects.filter(username=username).first()
|
|
|
- print("update-----",user_obj)
|
|
|
+ user_obj = Users.objects.filter(id=uid).first()
|
|
|
+ print("update-----",user_obj)
|
|
|
|
|
|
+ if user_obj:
|
|
|
+ user_obj.status = status
|
|
|
+ user_obj.permission = permission
|
|
|
+ user_obj.save()
|
|
|
+ res = {"code":0, "msg":"updte success"}
|
|
|
+ else:
|
|
|
+ res = {"code":-1, "msg":"update fail"}
|
|
|
+ except:
|
|
|
+ traceback.print_exc()
|
|
|
|
|
|
- if user_obj:
|
|
|
- user_obj.status = status
|
|
|
- user_obj.permission = permission
|
|
|
- user_obj.save()
|
|
|
- res = {"code":0, "status":user_obj.status, "permission":user_obj.permission}
|
|
|
else:
|
|
|
- res = {"code":-1, "msg":"修改失败!"}
|
|
|
+ res = {"code":-1, "msg":"参数不完整"}
|
|
|
|
|
|
print(res)
|
|
|
return JsonResponse(res)
|
|
@@ -228,17 +237,17 @@ def delete_user(request):
|
|
|
:return: True / False
|
|
|
"""
|
|
|
req_params = request.PARAMS
|
|
|
- username = req_params.get("username", None)
|
|
|
-
|
|
|
- print "username --> ", username
|
|
|
+ uid = req_params.get("uid", None)
|
|
|
|
|
|
- user_obj = Users.objects.filter(username=username).first()
|
|
|
+ user_obj = Users.objects.filter(id=uid).first()
|
|
|
+ print(user_obj)
|
|
|
if user_obj:
|
|
|
user_obj.delete()
|
|
|
- res = {"code":0, "msg":"删除成功!"}
|
|
|
+ res = {"code":0, "msg":"删除成功"}
|
|
|
else:
|
|
|
- res = {"code":-1, "msg":"修改失败!"}
|
|
|
+ res = {"code":-1, "msg":"删除失败"}
|
|
|
|
|
|
+ print(res)
|
|
|
return JsonResponse(res)
|
|
|
|
|
|
|
|
@@ -266,13 +275,13 @@ def reader_fb(request):
|
|
|
dict_data = {}
|
|
|
dict_data["rid"] = list_data.id
|
|
|
dict_data["readername"] = list_data.readername
|
|
|
- dict_data["crete_time"] = list_data.crete_time
|
|
|
+ dict_data["create_time"] = list_data.create_time
|
|
|
dict_data["question"] = list_data.question
|
|
|
data.append(dict_data)
|
|
|
res = {"code": 0, "msg": "get data success", "reader_data": data}
|
|
|
|
|
|
else:
|
|
|
- res = {"code": -1, "msg": "get no data!"}
|
|
|
+ res = {"code": -1, "msg": "get empty data!"}
|
|
|
|
|
|
print(res)
|
|
|
return JsonResponse(res)
|
|
@@ -280,7 +289,7 @@ def reader_fb(request):
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
-# @login_required
|
|
|
+@login_required
|
|
|
@params
|
|
|
def fb_question(request):
|
|
|
"""
|
|
@@ -288,25 +297,27 @@ def fb_question(request):
|
|
|
:param request: rid ,content
|
|
|
:return: True / False
|
|
|
"""
|
|
|
+
|
|
|
+ user_id = -1
|
|
|
user = get_user_from_request(request)
|
|
|
- # user_id = 2
|
|
|
- user_id = user["uid"]
|
|
|
+ if user:
|
|
|
+ user_id = user["uid"]
|
|
|
+ else:
|
|
|
+ return JsonResponse({"code":-1, "msg":"没登陆"})
|
|
|
req_params = request.PARAMS
|
|
|
- rid = req_params.get("rid", None)
|
|
|
+ rid = req_params.get("rid")
|
|
|
fb_content = req_params.get("fb_content", None)
|
|
|
|
|
|
-
|
|
|
reader_obj = Reader.objects.filter(id=rid).first()
|
|
|
print("update-----",reader_obj)
|
|
|
|
|
|
-
|
|
|
if reader_obj:
|
|
|
reader_obj.fb_content = fb_content
|
|
|
reader_obj.fb_id = user_id
|
|
|
reader_obj.save()
|
|
|
- res = {"code":0, "msg":"回复成功", "fb_content":fb_content}
|
|
|
+ res = {"code":0, "msg":"success", "fb_content":fb_content}
|
|
|
else:
|
|
|
- res = {"code":-1, "msg":"修改失败!"}
|
|
|
+ res = {"code":-1, "msg":"回复失败"}
|
|
|
|
|
|
print(res)
|
|
|
return JsonResponse(res)
|