|
@@ -53,6 +53,23 @@ def format_useinfo(user):
|
|
|
]
|
|
|
res.pop('roleName')
|
|
|
res.pop('value')
|
|
|
+ res.pop('password')
|
|
|
+ return res
|
|
|
+
|
|
|
+
|
|
|
+def format_login_result(user):
|
|
|
+ format_user = json.loads(
|
|
|
+ serialize('json', user, ensure_ascii=False)
|
|
|
+ )
|
|
|
+ for item in format_user:
|
|
|
+ res = {}
|
|
|
+ res['userId'] = item.get('pk')
|
|
|
+ res['token'] = item.get('fields').get('token')
|
|
|
+ res['roles'] = [
|
|
|
+ {
|
|
|
+ 'roleName': item.get('fields').get('roleName'), 'value': item.get('fields').get('value')
|
|
|
+ }
|
|
|
+ ]
|
|
|
return res
|
|
|
|
|
|
|
|
@@ -116,7 +133,11 @@ class login(View):
|
|
|
user = User.objects.all().filter(username=data.get(
|
|
|
'username'), password=data.get('password'))
|
|
|
if user:
|
|
|
- res = format_useinfo(user)
|
|
|
+ print('-------user---------')
|
|
|
+ print(user)
|
|
|
+ res = format_login_result(user)
|
|
|
+ print('---------------res--------')
|
|
|
+ print(res)
|
|
|
return JsonResponse({'code': 0, 'msg': 'success', 'result': res}, json_dumps_params={"ensure_ascii": False})
|
|
|
else:
|
|
|
return JsonResponse({'code': 1, 'error': '用户名或密码不正确'}, json_dumps_params={"ensure_ascii": False})
|