浏览代码

自动登出

hurixing 1 年之前
父节点
当前提交
54f8ec43d4

+ 14 - 0
baselib/src/main/java/com/yingyangfly/baselib/net/BaseObserver.kt

@@ -20,6 +20,7 @@ abstract class BaseObserver<T> : Observer<XBaseEntity<T>> {
     val TAG = "BaseObserver"
     private val SUCCESS_CODE = 200
     private val TOKENLOSEEFFICACY = 403
+    private val TOKENSTALEDATED = 401
 
     override fun onSubscribe(@NonNull d: Disposable) {
         logd("onSubscribe")
@@ -47,6 +48,19 @@ abstract class BaseObserver<T> : Observer<XBaseEntity<T>> {
             User.savePadNo("")
             User.saveOrgCode("")
             JumpUtil.jumpActivity(RouterUrlCommon.login)
+        }else if (TOKENSTALEDATED == tBaseEntity.code){
+            User.saveMobile("")
+            User.saveIdCard("")
+            User.saveUserSex("")
+            User.saveUserAge("")
+            User.saveDoctorAvatar("")
+            User.saveAvatar("")
+            User.saveName("")
+            User.saveUserId("")
+            User.saveOrgCode("")
+            User.savePadNo("")
+            User.saveToken("")
+            JumpUtil.jumpActivity(RouterUrlCommon.login)
         } else {
             loge("onNext--Failure--code:" + tBaseEntity.code + "--Message:" + tBaseEntity.message)
             onFail(tBaseEntity.message)

+ 14 - 0
baselib/src/main/java/com/yingyangfly/baselib/net/BaseResp.kt

@@ -40,6 +40,20 @@ open class BaseResp<T>(
                 User.savePadNo("")
                 JumpUtil.jumpActivity(RouterUrlCommon.login)
             }
+            ResponseCode.TOKENSTALEDATED ->{
+                User.saveMobile("")
+                User.saveIdCard("")
+                User.saveUserSex("")
+                User.saveUserAge("")
+                User.saveDoctorAvatar("")
+                User.saveAvatar("")
+                User.saveName("")
+                User.saveUserId("")
+                User.saveOrgCode("")
+                User.savePadNo("")
+                User.saveToken("")
+                JumpUtil.jumpActivity(RouterUrlCommon.login)
+            }
             else -> {
                 n {
                     this.message

+ 1 - 0
baselib/src/main/java/com/yingyangfly/baselib/net/ResponseCode.kt

@@ -3,4 +3,5 @@ package com.yingyangfly.baselib.net
 object ResponseCode {
     const val SUCCESS = 200
     const val TOKENLOSEEFFICACY = 403
+    const val TOKENSTALEDATED = 401
 }