|
@@ -8,7 +8,7 @@ from rest_framework import serializers
|
|
from rest_framework_jwt.settings import api_settings
|
|
from rest_framework_jwt.settings import api_settings
|
|
|
|
|
|
from apps.customer.models import Customer, CustomerWechat, CustomerAddress
|
|
from apps.customer.models import Customer, CustomerWechat, CustomerAddress
|
|
-from apps.foundation.models import BizLog
|
|
|
|
|
|
+from apps.foundation.models import BizLog, Config
|
|
from apps.base import Formater
|
|
from apps.base import Formater
|
|
from utils.exceptions import CustomError
|
|
from utils.exceptions import CustomError
|
|
from apps.account import tenant_log
|
|
from apps.account import tenant_log
|
|
@@ -22,16 +22,14 @@ jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER
|
|
class CustomerMobileSignSerializer(serializers.Serializer):
|
|
class CustomerMobileSignSerializer(serializers.Serializer):
|
|
def validate(self, attrs):
|
|
def validate(self, attrs):
|
|
mobile = self.initial_data.get('mobile')
|
|
mobile = self.initial_data.get('mobile')
|
|
- vcode = self.initial_data.get('vcode')
|
|
|
|
- appid = self.initial_data.get('appid')
|
|
|
|
|
|
+ appid = Config.getConfigValue(Config.KEY_WECHAT_APPID)
|
|
|
|
|
|
- if mobile and vcode and appid:
|
|
|
|
- # VCode.verify(mobile, vcode, tenant)
|
|
|
|
|
|
+ if mobile and appid:
|
|
user = User.objects.filter(username=mobile).first()
|
|
user = User.objects.filter(username=mobile).first()
|
|
if not user:
|
|
if not user:
|
|
user = User.objects.create_customer(username=mobile)
|
|
user = User.objects.create_customer(username=mobile)
|
|
|
|
|
|
- if not user.is_active:
|
|
|
|
|
|
+ if user.status == User.DIMISSION:
|
|
msg = '该账户已被禁用'
|
|
msg = '该账户已被禁用'
|
|
raise serializers.ValidationError(msg)
|
|
raise serializers.ValidationError(msg)
|
|
|
|
|
|
@@ -42,17 +40,16 @@ class CustomerMobileSignSerializer(serializers.Serializer):
|
|
raise serializers.ValidationError(msg)
|
|
raise serializers.ValidationError(msg)
|
|
|
|
|
|
payload = jwt_payload_handler(user)
|
|
payload = jwt_payload_handler(user)
|
|
- tenant_log(user, BizLog.INSERT,u'客户短信登录,username=%s' % user.username)
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
'token': jwt_encode_handler(payload),
|
|
'token': jwt_encode_handler(payload),
|
|
'user_id': user.id,
|
|
'user_id': user.id,
|
|
|
|
+ 'customer': customer.id,
|
|
'username': user.username,
|
|
'username': user.username,
|
|
'name': customer.name or '',
|
|
'name': customer.name or '',
|
|
'tel': customer.tel or '',
|
|
'tel': customer.tel or '',
|
|
'face': customer.face and customer.face.get_path() or '',
|
|
'face': customer.face and customer.face.get_path() or '',
|
|
'gender': customer.gender or 0,
|
|
'gender': customer.gender or 0,
|
|
- 'member_id': customer.member_id or '',
|
|
|
|
}
|
|
}
|
|
else:
|
|
else:
|
|
msg = '参数无效'
|
|
msg = '参数无效'
|
|
@@ -72,7 +69,7 @@ class WechatLoginSerializer(serializers.Serializer):
|
|
}
|
|
}
|
|
|
|
|
|
user = customer_wechat.customer.user
|
|
user = customer_wechat.customer.user
|
|
- if not user.is_active:
|
|
|
|
|
|
+ if user.status == User.DIMISSION:
|
|
msg = '用户帐户已禁用.'
|
|
msg = '用户帐户已禁用.'
|
|
raise serializers.ValidationError(msg)
|
|
raise serializers.ValidationError(msg)
|
|
|
|
|
|
@@ -82,11 +79,11 @@ class WechatLoginSerializer(serializers.Serializer):
|
|
'bind': 1,
|
|
'bind': 1,
|
|
'token': jwt_encode_handler(payload),
|
|
'token': jwt_encode_handler(payload),
|
|
'openid': customer_wechat.openid,
|
|
'openid': customer_wechat.openid,
|
|
|
|
+ 'customer': customer_wechat.customer_id,
|
|
'name': customer_wechat.customer.name or '',
|
|
'name': customer_wechat.customer.name or '',
|
|
'tel': customer_wechat.customer.tel or '',
|
|
'tel': customer_wechat.customer.tel or '',
|
|
'face': customer_wechat.customer.face and customer_wechat.customer.face.get_path() or '',
|
|
'face': customer_wechat.customer.face and customer_wechat.customer.face.get_path() or '',
|
|
'gender': customer_wechat.customer.gender or 0,
|
|
'gender': customer_wechat.customer.gender or 0,
|
|
- 'member_id': customer_wechat.customer.member_id or '',
|
|
|
|
}
|
|
}
|
|
|
|
|
|
else:
|
|
else:
|
|
@@ -95,7 +92,7 @@ class WechatLoginSerializer(serializers.Serializer):
|
|
|
|
|
|
class WechatBindSerializer(serializers.Serializer):
|
|
class WechatBindSerializer(serializers.Serializer):
|
|
def validate(self, attrs):
|
|
def validate(self, attrs):
|
|
- appid = self.initial_data.get('appid')
|
|
|
|
|
|
+ appid = Config.getConfigValue(Config.KEY_WECHAT_APPID)
|
|
openid = self.initial_data.get('openid')
|
|
openid = self.initial_data.get('openid')
|
|
phoneEncryptedData = self.initial_data.get('encryptedData')
|
|
phoneEncryptedData = self.initial_data.get('encryptedData')
|
|
phoneIv = self.initial_data.get('iv')
|
|
phoneIv = self.initial_data.get('iv')
|
|
@@ -108,11 +105,11 @@ class WechatBindSerializer(serializers.Serializer):
|
|
|
|
|
|
return {
|
|
return {
|
|
'token': jwt_encode_handler(payload),
|
|
'token': jwt_encode_handler(payload),
|
|
|
|
+ 'customer': customer.id or '',
|
|
'name': customer.name or '',
|
|
'name': customer.name or '',
|
|
'tel': customer.tel or '',
|
|
'tel': customer.tel or '',
|
|
'face': customer.face and customer.face.get_path() or '',
|
|
'face': customer.face and customer.face.get_path() or '',
|
|
'gender': customer.gender or 0,
|
|
'gender': customer.gender or 0,
|
|
- 'member_id': customer.member_id or '',
|
|
|
|
}
|
|
}
|
|
|
|
|
|
else:
|
|
else:
|