注销账号登录弹窗和找回账号

This commit is contained in:
zu
2021-12-29 03:46:46 +08:00
parent b9b249ce9f
commit a2dd861c70
7 changed files with 164 additions and 4 deletions

View File

@@ -22,9 +22,11 @@ import com.netease.nim.uikit.StatusBarUtil;
import com.trello.rxlifecycle3.android.ActivityEvent;
import com.yizhuan.erban.R;
import com.yizhuan.erban.base.BaseLoginAct;
import com.yizhuan.erban.common.widget.dialog.DialogManager;
import com.yizhuan.erban.ui.login.ui.CodeEditText;
import com.yizhuan.xchat_android_core.auth.AuthModel;
import com.yizhuan.xchat_android_core.auth.event.LoginEvent;
import com.yizhuan.xchat_android_core.auth.exception.AccountCancelException;
import com.yizhuan.xchat_android_core.auth.exception.BanAccountException;
import com.yizhuan.xchat_android_core.auth.exception.IsSuperAdminException;
import com.yizhuan.xchat_android_core.auth.exception.ShowPhoneCodeException;
@@ -241,6 +243,43 @@ public class LoginCodeActivity extends BaseLoginAct {
start, text.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
getDialogManager().showOkCancelWithTitleDialog("您被封号了",
spannableString, "确定", "取消", null);
} else if (e instanceof AccountCancelException) {
AccountCancelException exception = (AccountCancelException) e;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日", Locale.getDefault());
String text = "注销时间:" + simpleDateFormat.format(new Date(exception.getCancelDate()));
int end = text.length();
text += "\n\n是否找回该账号";
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(new ForegroundColorSpan(ContextCompat.getColor(LoginCodeActivity.this, R.color.appColor)),
0, end, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
getDialogManager().showOkCancelWithTitleDialog("该账号已注销",
spannableString, "找回账号", "返回", new DialogManager.OkCancelDialogListener() {
@Override
public void onOk() {
getDialogManager().showProgressDialog(LoginCodeActivity.this);
AuthModel.get()
.recoverAccount(String.valueOf(exception.getErbanNo()))
.doOnError(throwable -> {
getDialogManager().dismissDialog();
toast(throwable.getMessage());
})
.doOnSuccess(result -> {
if (result.getCode() == 200) {
toast("找回账号成功");
} else {
toast(result.getMessage());
}
getDialogManager().dismissDialog();
})
.subscribe();
}
@Override
public void onCancel() {
finish();
}
});
} else if (e instanceof ShowPhoneCodeException) {
isSuperAdmin = false;
ShowPhoneCodeException showPhoneCodeException = (ShowPhoneCodeException) e;

View File

@@ -16,9 +16,11 @@ import androidx.core.content.ContextCompat;
import com.yizhuan.erban.R;
import com.yizhuan.erban.base.BaseLoginAct;
import com.yizhuan.erban.common.widget.dialog.DialogManager;
import com.yizhuan.erban.ui.setting.ResetPasswordActivity;
import com.yizhuan.xchat_android_core.auth.AuthModel;
import com.yizhuan.xchat_android_core.auth.event.LoginEvent;
import com.yizhuan.xchat_android_core.auth.exception.AccountCancelException;
import com.yizhuan.xchat_android_core.auth.exception.BanAccountException;
import com.yizhuan.xchat_android_core.auth.exception.IsSuperAdminException;
import com.yizhuan.xchat_android_core.statistic.StatisticManager;
@@ -143,6 +145,43 @@ public class LoginPasswordActivity extends BaseLoginAct {
start, text.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
getDialogManager().showOkCancelWithTitleDialog("您被封号了",
spannableString, "确定", "取消", null);
} else if (e instanceof AccountCancelException) {
AccountCancelException exception = (AccountCancelException) e;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日", Locale.getDefault());
String text = "注销时间:" + simpleDateFormat.format(new Date(exception.getCancelDate()));
int end = text.length();
text += "\n\n是否找回该账号";
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(new ForegroundColorSpan(ContextCompat.getColor(LoginPasswordActivity.this, R.color.appColor)),
0, end, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
getDialogManager().showOkCancelWithTitleDialog("该账号已注销",
spannableString, "找回账号", "返回", new DialogManager.OkCancelDialogListener() {
@Override
public void onOk() {
getDialogManager().showProgressDialog(LoginPasswordActivity.this);
AuthModel.get()
.recoverAccount(String.valueOf(exception.getErbanNo()))
.doOnError(throwable -> {
getDialogManager().dismissDialog();
toast(throwable.getMessage());
})
.doOnSuccess(result -> {
if (result.getCode() == 200) {
toast("找回账号成功");
} else {
toast(result.getMessage());
}
getDialogManager().dismissDialog();
})
.subscribe();
}
@Override
public void onCancel() {
finish();
}
});
} else {
toast(e.getMessage());
}

View File

@@ -19,11 +19,13 @@ import com.netease.nis.quicklogin.listener.QuickLoginPreMobileListener;
import com.netease.nis.quicklogin.listener.QuickLoginTokenListener;
import com.yizhuan.erban.R;
import com.yizhuan.erban.base.BaseLoginAct;
import com.yizhuan.erban.common.widget.dialog.DialogManager;
import com.yizhuan.erban.ui.login.LoginPhoneActivity;
import com.yizhuan.xchat_android_constants.XChatConstants;
import com.yizhuan.xchat_android_core.DemoCache;
import com.yizhuan.xchat_android_core.auth.AuthModel;
import com.yizhuan.xchat_android_core.auth.event.LoginEvent;
import com.yizhuan.xchat_android_core.auth.exception.AccountCancelException;
import com.yizhuan.xchat_android_core.auth.exception.BanAccountException;
import com.yizhuan.xchat_android_core.auth.exception.IsSuperAdminException;
import com.yizhuan.xchat_android_core.statistic.StatisticManager;
@@ -245,6 +247,43 @@ public class QuickPassLoginAct extends BaseLoginAct implements View.OnClickListe
start, text.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
getDialogManager().showOkCancelWithTitleDialog("您被封号了",
spannableString, "确定", "取消", null);
} else if (e instanceof AccountCancelException) {
AccountCancelException exception = (AccountCancelException) e;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日", Locale.getDefault());
String text = "注销时间:" + simpleDateFormat.format(new Date(exception.getCancelDate()));
int end = text.length();
text += "\n\n是否找回该账号";
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(new ForegroundColorSpan(ContextCompat.getColor(QuickPassLoginAct.this, R.color.appColor)),
0, end, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
getDialogManager().showOkCancelWithTitleDialog("该账号已注销",
spannableString, "找回账号", "返回", new DialogManager.OkCancelDialogListener() {
@Override
public void onOk() {
getDialogManager().showProgressDialog(QuickPassLoginAct.this);
AuthModel.get()
.recoverAccount(String.valueOf(exception.getErbanNo()))
.doOnError(throwable -> {
getDialogManager().dismissDialog();
toast(throwable.getMessage());
})
.doOnSuccess(result -> {
if (result.getCode() == 200) {
toast("找回账号成功");
} else {
toast(result.getMessage());
}
getDialogManager().dismissDialog();
})
.subscribe();
}
@Override
public void onCancel() {
finish();
}
});
} else {
toast(e.getMessage());
LoginPhoneActivity.startForResult(QuickPassLoginAct.this, quickPassRequestCode);

View File

@@ -27,10 +27,7 @@ import com.yizhuan.xchat_android_core.auth.event.GetCurrentUidEvent;
import com.yizhuan.xchat_android_core.auth.event.KickOutEvent;
import com.yizhuan.xchat_android_core.auth.event.LoginEvent;
import com.yizhuan.xchat_android_core.auth.event.LogoutEvent;
import com.yizhuan.xchat_android_core.auth.exception.BanAccountException;
import com.yizhuan.xchat_android_core.auth.exception.BigHeadPhoneException;
import com.yizhuan.xchat_android_core.auth.exception.IsSuperAdminException;
import com.yizhuan.xchat_android_core.auth.exception.ShowPhoneCodeException;
import com.yizhuan.xchat_android_core.auth.exception.*;
import com.yizhuan.xchat_android_core.base.BaseModel;
import com.yizhuan.xchat_android_core.bean.response.ServiceResult;
import com.yizhuan.xchat_android_core.bean.response.result.LoginResult;
@@ -117,6 +114,11 @@ public class AuthModel extends BaseModel implements IAuthModel {
*/
public static final int VERIFY_CODE_ERROR = 3002; // 图片验证码?
/**
* 账号已注销
*/
public static final int CODE_ACCOUNT_CANCEL = 3009;
/**
* 注册异常,请稍后再试
*/
@@ -275,6 +277,8 @@ public class AuthModel extends BaseModel implements IAuthModel {
if (!loginResult.isSuccess()) {
if (loginResult.getCode() == CODE_BAN_ACCOUNT || loginResult.getCode() == CODE_BAN_DEVICE) {
emitter.onError(new BanAccountException(loginResult.getReason(), loginResult.getDate()));
} else if (loginResult.getCode() == CODE_ACCOUNT_CANCEL) {
emitter.onError(new AccountCancelException(loginResult.getMessage(), loginResult.getErbanNo(), loginResult.getCancelDate()));
} else if (loginResult.getCode() == CODE_SHOW_CODE) {
emitter.onError(new ShowPhoneCodeException(loginResult.getMessage(), loginResult.isVerifyCode()));
} else if (loginResult.getCode() == SUPER_CODE_SHOW_CODE) {
@@ -546,6 +550,8 @@ public class AuthModel extends BaseModel implements IAuthModel {
if (!loginResult.isSuccess()) {
if (loginResult.getCode() == CODE_BAN_ACCOUNT || loginResult.getCode() == CODE_BAN_DEVICE) {
e.onError(new BanAccountException(loginResult.getReason(), loginResult.getDate()));
} else if (loginResult.getCode() == CODE_ACCOUNT_CANCEL) {
e.onError(new AccountCancelException(loginResult.getMessage(), loginResult.getErbanNo(), loginResult.getCancelDate()));
} else {
e.onError(new Throwable(loginResult.getMessage()));
}
@@ -591,6 +597,8 @@ public class AuthModel extends BaseModel implements IAuthModel {
if (!loginResult.isSuccess()) {
if (loginResult.getCode() == CODE_BAN_ACCOUNT || loginResult.getCode() == CODE_BAN_DEVICE) {
emitter.onError(new BanAccountException(loginResult.getReason(), loginResult.getDate()));
} else if (loginResult.getCode() == CODE_ACCOUNT_CANCEL) {
emitter.onError(new AccountCancelException(loginResult.getMessage(), loginResult.getErbanNo(), loginResult.getCancelDate()));
} else if (loginResult.getCode() == CODE_SHOW_CODE) {
emitter.onError(new ShowPhoneCodeException(loginResult.getMessage(), loginResult.isVerifyCode()));
} else if (loginResult.getCode() == SUPER_CODE_SHOW_CODE) {
@@ -1010,6 +1018,11 @@ public class AuthModel extends BaseModel implements IAuthModel {
.compose(new Transformer<>());
}
@Override
public Single<ServiceResult<String>> recoverAccount(String erbanNo) {
return api.recoverAccount(erbanNo)
.compose(RxHelper.handleSchedulers());
}
/****************************************************** IM *************************************************************/
@@ -1456,6 +1469,10 @@ public class AuthModel extends BaseModel implements IAuthModel {
@Field("yiDunToken") String yiDunToken
);
@FormUrlEncoded
@POST("user/recover/user")
Single<ServiceResult<String>> recoverAccount(@Field("erbanNo") String erbanNo);
}
}

View File

@@ -150,4 +150,6 @@ public interface IAuthModel extends IModel{
* 一键登录
*/
Single<String> quickPassLogin(String token, String accessToken, String shuMeiDeviceId, String yiDunToken);
Single<ServiceResult<String>> recoverAccount(String erbanNo);
}

View File

@@ -0,0 +1,21 @@
package com.yizhuan.xchat_android_core.auth.exception;
public class AccountCancelException extends Exception {
private long cancelDate;
private long erbanNo;
public AccountCancelException(String message, long erbanNo, long cancelDate) {
super(message);
this.erbanNo = erbanNo;
this.cancelDate = cancelDate;
}
public long getCancelDate() {
return cancelDate;
}
public long getErbanNo() {
return erbanNo;
}
}

View File

@@ -35,6 +35,9 @@ public class LoginResult extends ServiceResult<AccountInfo> {
*/
private int superCodeVerify;
private long cancelDate;
private long erbanNo;
public boolean isVerifyCode() {
return codeVerify == CODE_VERIFY_CODE;