|
@@ -1,6 +1,3 @@
|
|
|
-#!/usr/bin/env python
|
|
|
-# -*- coding: utf-8 -*-
|
|
|
-import logging
|
|
|
import os
|
|
|
import traceback
|
|
|
|
|
@@ -8,15 +5,14 @@ import boto3
|
|
|
import botocore
|
|
|
from botocore import client
|
|
|
import simplejson as json
|
|
|
-from django.core.files.storage import FileSystemStorage
|
|
|
from django.http import HttpResponse
|
|
|
from django.utils.decorators import method_decorator
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
from django.views.generic import TemplateView, View
|
|
|
|
|
|
-from Ansjer.config import BASE_DIR, SERVER_TYPE, ACCESS_KEY_ID, SECRET_ACCESS_KEY, REGION_NAME, AVATAR_BUCKET
|
|
|
+from Ansjer.config import BASE_DIR, ACCESS_KEY_ID, SECRET_ACCESS_KEY, REGION_NAME, AVATAR_BUCKET
|
|
|
from Ansjer.config import SERVER_DOMAIN
|
|
|
-from Model.models import Role, Device_User, UserOauth2Model, UserExModel, CountryLanguageModel
|
|
|
+from Model.models import Role, Device_User, UserOauth2Model, UserExModel, CountryLanguageModel, LanguageModel
|
|
|
from Object.RedisObject import RedisObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
@@ -24,7 +20,6 @@ from Service.CommonService import CommonService
|
|
|
from Service.ModelService import ModelService
|
|
|
|
|
|
|
|
|
-# http://192.168.136.40:8077/account/showUserMore?token=test
|
|
|
class showUserMoreView(TemplateView):
|
|
|
@method_decorator(csrf_exempt)
|
|
|
def dispatch(self, *args, **kwargs):
|
|
@@ -32,58 +27,80 @@ class showUserMoreView(TemplateView):
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
request.encoding = 'utf-8'
|
|
|
- token = request.POST.get('token', None)
|
|
|
-
|
|
|
- return self.ValidationError(token)
|
|
|
+ return self.validation(request.POST)
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
request.encoding = 'gb2312'
|
|
|
- token = request.GET.get('token', None)
|
|
|
+ return self.validation(request.GET)
|
|
|
|
|
|
- return self.ValidationError(token)
|
|
|
-
|
|
|
- def ValidationError(self, token):
|
|
|
+ def validation(self, request_dict):
|
|
|
response = ResponseObject()
|
|
|
+ token = request_dict.get('token', None)
|
|
|
+ lang = request_dict.get('lang', 'en')
|
|
|
+
|
|
|
tko = TokenObject(token)
|
|
|
response.lang = tko.lang
|
|
|
if tko.code != 0:
|
|
|
return response.json(tko.code)
|
|
|
- userID = tko.userID
|
|
|
- if not userID:
|
|
|
+ user_id = tko.userID
|
|
|
+ if not user_id:
|
|
|
return response.json(104)
|
|
|
- return self.showUserMore(userID, response)
|
|
|
|
|
|
- def showUserMore(self, userID, response):
|
|
|
- User = Device_User.objects.filter(userID=userID)
|
|
|
- if not User.exists():
|
|
|
+ return self.show_user_more(user_id, lang, response)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def show_user_more(user_id, lang, response):
|
|
|
+ """
|
|
|
+ 获取用户完整信息
|
|
|
+ @param user_id: 用户id
|
|
|
+ @param lang: 语言
|
|
|
+ @param response: 响应
|
|
|
+ @return: response
|
|
|
+ """
|
|
|
+ device_user_qs = Device_User.objects.filter(userID=user_id)
|
|
|
+ if not device_user_qs.exists():
|
|
|
return response.json(104)
|
|
|
- sqlDict = CommonService.qs_to_dict(User)
|
|
|
- for k, v in enumerate(sqlDict["datas"]):
|
|
|
- sqlDict['datas'][k]['fields'].pop('password')
|
|
|
- userIconPath = sqlDict['datas'][k]['fields']['userIconPath']
|
|
|
- if userIconPath:
|
|
|
- if userIconPath.find('static/') != -1:
|
|
|
- userIconPath = userIconPath.replace('static/', '').replace('\\', '/')
|
|
|
- userIconUrl = SERVER_DOMAIN + 'account/getAvatar/' + userIconPath
|
|
|
- sqlDict['datas'][k]['fields']['userIconUrl'] = userIconUrl
|
|
|
- if len(v['fields']['role']):
|
|
|
- roleName = ModelService.getRole(rid=v['fields']['role'][0])
|
|
|
- sqlDict["datas"][k]['fields']['rolename'] = roleName
|
|
|
- region_country = sqlDict["datas"][k]['fields']['region_country']
|
|
|
- if not region_country == 0:
|
|
|
- country_qs = CountryLanguageModel.objects.filter(country_id=region_country).values(
|
|
|
- 'country__region__api')
|
|
|
- sqlDict["datas"][k]['fields']['api'] = country_qs[0]['country__region__api']
|
|
|
- else:
|
|
|
- sqlDict["datas"][k]['fields']['api'] = ''
|
|
|
+ try:
|
|
|
+ sqlDict = CommonService.qs_to_dict(device_user_qs)
|
|
|
+ for k, v in enumerate(sqlDict["datas"]):
|
|
|
+ sqlDict['datas'][k]['fields'].pop('password')
|
|
|
+ userIconPath = sqlDict['datas'][k]['fields']['userIconPath']
|
|
|
+ region_status = sqlDict['datas'][k]['fields']['region_status']
|
|
|
+ if userIconPath:
|
|
|
+ if userIconPath.find('static/') != -1:
|
|
|
+ userIconPath = userIconPath.replace('static/', '').replace('\\', '/')
|
|
|
+ userIconUrl = SERVER_DOMAIN + 'account/getAvatar/' + userIconPath
|
|
|
+ sqlDict['datas'][k]['fields']['userIconUrl'] = userIconUrl
|
|
|
+
|
|
|
+ # 确认地区字段和当前地区
|
|
|
+ sqlDict['datas'][k]['fields']['region_status'] = 1 if region_status else 0
|
|
|
+ sqlDict['datas'][k]['fields']['region'] = ''
|
|
|
+ if region_status:
|
|
|
+ region_country = sqlDict['datas'][k]['fields']['region_country']
|
|
|
+ language_qs = LanguageModel.objects.filter(lang=lang).values('id')
|
|
|
+ region_qs = CountryLanguageModel.objects.filter(country_id=region_country,
|
|
|
+ language_id=language_qs[0]['id']).values('country_name')
|
|
|
+ sqlDict['datas'][k]['fields']['region'] = region_qs[0]['country_name'] if region_qs.exists() else ''
|
|
|
+
|
|
|
+ if len(v['fields']['role']):
|
|
|
+ roleName = ModelService.getRole(rid=v['fields']['role'][0])
|
|
|
+ sqlDict["datas"][k]['fields']['rolename'] = roleName
|
|
|
+ region_country = sqlDict["datas"][k]['fields']['region_country']
|
|
|
+ if not region_country == 0:
|
|
|
+ country_qs = CountryLanguageModel.objects.filter(country_id=region_country).values(
|
|
|
+ 'country__region__api')
|
|
|
+ sqlDict["datas"][k]['fields']['api'] = country_qs[0]['country__region__api']
|
|
|
+ else:
|
|
|
+ sqlDict["datas"][k]['fields']['api'] = ''
|
|
|
|
|
|
- # 增加oauth2关联数据
|
|
|
- ua_qs = UserOauth2Model.objects.filter(userID_id=userID).values_list('authType', flat=True)
|
|
|
- sqlDict["oauth2"] = list(ua_qs)
|
|
|
- return response.json(0, sqlDict)
|
|
|
+ # 增加oauth2关联数据
|
|
|
+ ua_qs = UserOauth2Model.objects.filter(userID_id=user_id).values_list('authType', flat=True)
|
|
|
+ sqlDict['oauth2'] = list(ua_qs)
|
|
|
+ return response.json(0, sqlDict)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, repr(e))
|
|
|
|
|
|
|
|
|
-# http://192.168.136.40:8077/account/perfectUserInfo?token=test&content={"NickName":"333"}
|
|
|
class perfectUserInfoView(TemplateView):
|
|
|
# 完善个人信息
|
|
|
@method_decorator(csrf_exempt)
|