wushaodong 4 år sedan
förälder
incheckning
d7ea5b33c9
3 ändrade filer med 18 tillägg och 12 borttagningar
  1. 14 7
      apps/account/views.py
  2. 0 1
      uis/views/account/login.html
  3. 4 4
      uis/views/employee/manage_range.html

+ 14 - 7
apps/account/views.py

@@ -8,7 +8,7 @@ from rest_framework.views import APIView
 from rest_framework.serializers import ValidationError
 from utils.permission import permission_required, isLogin, check_permission
 from django.contrib.auth.models import Group, Permission
-from rest_framework_jwt.views import ObtainJSONWebToken, VerifyJSONWebToken, RefreshJSONWebToken
+from rest_framework_jwt.views import ObtainJSONWebToken, RefreshJSONWebToken
 from utils import response_error, response_ok
 from django.contrib.auth import get_user_model
 from django.utils import timezone
@@ -31,16 +31,17 @@ class LoginView(ObtainJSONWebToken):
         try:
             ser = self.serializer_class(data=request.data)
             ser.request = request
-            # TODO 判断门店是否在用、在有效期内
+            # 判断门店是否在用、在有效期内
             if ser.is_valid(raise_exception=True):
                 user = User.objects.filter(id=ser.validated_data['user_id']).first()
                 store = Store.objects.filter(id=user.store_id).first()
-                if store.enable == False or (store.end_date.strftime('%Y-%m-%d')) < (timezone.now().strftime('%Y-%m-%d')):
-                    raise CustomError(u'当前帐号不可用,请联系管理员!')
+                if store and (store.enable == False or (store.end_date.strftime('%Y-%m-%d')) < (timezone.now().strftime('%Y-%m-%d')) ):
+                    raise CustomError(u'当前店面不可用,请联系管理员!')
                 return response_ok(ser.validated_data)
         except ValidationError as e:
             return response_error(e.detail['error'][0])
-
+        except CustomError as e:
+            return response_error(str(e))
 
 class RefreshTokenView(RefreshJSONWebToken):
 
@@ -48,10 +49,16 @@ class RefreshTokenView(RefreshJSONWebToken):
         try:
             ser = self.serializer_class(data=request.data)
             if ser.is_valid(raise_exception=True):
+                user = ser.validated_data['user']
+                store = Store.objects.filter(id=user.store_id).first()
+                if store and (store.enable == False or (store.end_date.strftime('%Y-%m-%d')) < (
+                timezone.now().strftime('%Y-%m-%d')) ):
+                    raise CustomError(u'当前店面不可用,请联系管理员!')
                 return response_ok({'token': ser.validated_data['token']})
         except ValidationError as e:
-            return response_error(u'登录状态失效,请重新登录')
-
+            return response_ok({'error':True})
+        except CustomError as e:
+            return response_error(str(e))
 
 class ChangePassword(APIView):
 

+ 0 - 1
uis/views/account/login.html

@@ -94,7 +94,6 @@
         ,data: {token: layui.data(setter.tableName)[setter.request.tokenName].substr(4)}
         ,type: 'post'
         ,done: function(res){
-
           //请求成功后,写入 access_token
           layui.data(setter.tableName, {
             key: setter.request.tokenName

+ 4 - 4
uis/views/employee/manage_range.html

@@ -58,20 +58,20 @@
         });
 
         form.on('submit(component-form-element)', function (data) {
-            var sotres = []
+            var stores = []
             for (var key in data.field) {
 
                 if (key.indexOf('store') > -1) {
-                    sotres.push(data.field[key])
+                    stores.push(data.field[key])
                 }
             }
-            if (sotres.length === 0) {
+            if (stores.length === 0) {
                 layer.msg('请选择门店');
                 return false;
             }
             admin.req({
                 url: '/account/employee/' + id + '/branch/'
-                , data: {sotres:JSON.stringify(sotres)}
+                , data: {stores:JSON.stringify(stores)}
                 , type: 'post'
                 , done: function (res) {
                     parent.layer.closeAll('iframe');