Files
VisualSapfor/src/_VisualDVM/Passes/All/CheckAccount.java

77 lines
3.5 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package _VisualDVM.Passes.All;
import Common.Utils.Utils_;
import Common.Visual.UI;
import _VisualDVM.ComponentsServer.UserAccount.UserAccount;
import _VisualDVM.Global;
import _VisualDVM.ComponentsServer.UserAccount.AccountRole;
import _VisualDVM.Passes.PassCode;
import _VisualDVM.Passes.Server.ComponentsServerPass;
import _VisualDVM.Repository.Server.ServerCode;
import org.apache.commons.io.FileUtils;
import java.io.File;
public class CheckAccount extends ComponentsServerPass {
@Override
public String getIconPath() {
return "/icons/Registry.png";
}
@Override
protected boolean isSafe() {
return false;
}
File keyFile;
void confirmEmail() throws Exception{
ConfirmEmail confirmEmailPass = (ConfirmEmail) Global.mainModule.getPass(PassCode.ConfirmEmail);;
if (confirmEmailPass.Do(Global.mainModule.getAccount())) {
//подтвердили почту. теперь проверяем ее роль на сервере. если на сервере нет акка будет создан
if (SendRequest(ServerCode.GetUserAccountByEmail, "",Global.mainModule.getAccount())){
Global.mainModule.setAccount((UserAccount) request.server_response.object);
FileUtils.writeStringToFile(keyFile, request.server_response.arg);
}
}
}
@Override
protected boolean canStart(Object... args) throws Exception {
Global.mainModule.getAccount().role = AccountRole.Undefined;
Global.normalProperties.Update();
keyFile = new File(Global.KeysDirectory, "key");
//--
//1. Ищем ключ.
if (keyFile.exists()) {
//ключ есть. проверить его актуальность.
String key = FileUtils.readFileToString(keyFile);
System.out.println("ключ найден.");
if (SendRequest(ServerCode.GetUserAccountByKey,key)){
if (request.server_response.object!=null){
//ключ актуальный.
System.out.println("ключ совпал");
Global.mainModule.setAccount((UserAccount) request.server_response.object);
}else {
System.out.println("ключ не совпал!");
//ключ неактуальный. регистрируемся по новой.
UI.Error("Текущий ключ неверен. Он будет удален.");
Utils_.forceDeleteWithCheck(keyFile);
confirmEmail();
}
}
}else {
System.out.println("ключ не найден!");
confirmEmail();
}
return !Global.mainModule.getAccount().role.equals(AccountRole.Undefined);
}
@Override
protected void body() throws Exception {
Global.normalProperties.SynchronizeAccount(Global.mainModule.getAccount());
}
@Override
protected void showDone() throws Exception {
if (Global.mainModule.getUI().hasMainWindow()) {
Global.mainModule.getUI().getMainWindow().getCallbackWindow().ShowAccount();
if (Global.componentsServer.db.bugReports.getUI().getCurrent() != null)
Global.mainModule.getUI().getMainWindow().getCallbackWindow().ShowCurrentBugReport();
}
setControlsVisible(false); //если проверка успешна, кнопку больше не показывать.
}
}