промежуточный. проверка пользователя по ключу
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
package _VisualDVM.Passes.All;
|
||||
import Common.Utils.Utils_;
|
||||
import Common.Visual.UI;
|
||||
import _VisualDVM.ComponentsServer.UserAccount.UserAccount;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.GlobalData.Account.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;
|
||||
import java.io.Serializable;
|
||||
public class CheckAccount extends ComponentsServerPass<UserAccount> {
|
||||
@Override
|
||||
public String getIconPath() {
|
||||
@@ -20,10 +23,12 @@ public class CheckAccount extends ComponentsServerPass<UserAccount> {
|
||||
File keyFile;
|
||||
void confirmEmail() throws Exception{
|
||||
ConfirmEmail confirmEmailPass = (ConfirmEmail) Global.mainModule.getPass(PassCode.ConfirmEmail);;
|
||||
if (confirmEmailPass.Do()){
|
||||
if (confirmEmailPass.Do(
|
||||
new UserAccount(Global.normalProperties.Name, Global.normalProperties.Email))
|
||||
) {
|
||||
UserAccount userAccount = confirmEmailPass.target;
|
||||
//подтвердили почту. теперь проверяем ее роль на сервере. если на сервере нет акка будет создан
|
||||
if (SendRequest(ServerCode.GetUserAccountByEmail, null,userAccount)){
|
||||
if (SendRequest(ServerCode.GetUserAccountByEmail, "",userAccount)){
|
||||
target = (UserAccount) request.server_response.object;
|
||||
FileUtils.writeStringToFile(keyFile, target.security_key);
|
||||
}
|
||||
@@ -33,21 +38,29 @@ public class CheckAccount extends ComponentsServerPass<UserAccount> {
|
||||
protected boolean canStart(Object... args) throws Exception {
|
||||
target =null;
|
||||
keyFile = new File(Global.KeyDirectory, "key");
|
||||
Global.normalProperties.Role = AccountRole.Undefined;
|
||||
Global.normalProperties.Update();
|
||||
//--
|
||||
//1. Ищем ключ.
|
||||
if (keyFile.exists()) {
|
||||
//ключ есть. проверить его актуальность.
|
||||
if (SendRequest(ServerCode.GetUserAccountByKey, FileUtils.readFileToString(keyFile))){
|
||||
if (request.server_response!=null){
|
||||
String key = FileUtils.readFileToString(keyFile);
|
||||
System.out.println("ключ найден.");
|
||||
if (SendRequest(ServerCode.GetUserAccountByKey,key)){
|
||||
if (request.server_response.object!=null){
|
||||
//ключ актуальный.
|
||||
System.out.println("ключ совпал");
|
||||
target = (UserAccount) request.server_response.object;
|
||||
}else {
|
||||
System.out.println("ключ не совпал!");
|
||||
//ключ неактуальный. регистрируемся по новой.
|
||||
UI.Error("Текущий ключ неверен. Он будет удален.");
|
||||
Utils_.forceDeleteWithCheck(keyFile);
|
||||
confirmEmail();
|
||||
}
|
||||
}
|
||||
}else {
|
||||
System.out.println("ключ не найден!");
|
||||
confirmEmail();
|
||||
}
|
||||
return target!=null;
|
||||
|
||||
Reference in New Issue
Block a user