73 lines
3.2 KiB
Java
73 lines
3.2 KiB
Java
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);
|
||
if (SendRequest(ServerCode.GetUserAccountByKey,key)){
|
||
if (request.server_response.object!=null){
|
||
//ключ актуальный.
|
||
Global.mainModule.setAccount((UserAccount) request.server_response.object);
|
||
}else {
|
||
//ключ неактуальный. регистрируемся по новой.
|
||
UI.Error("Текущий ключ неверен. Он будет удален.");
|
||
Utils_.forceDeleteWithCheck(keyFile);
|
||
confirmEmail();
|
||
}
|
||
}
|
||
}else {
|
||
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); //если проверка успешна, кнопку больше не показывать.
|
||
}
|
||
}
|