промежуточный. проверка пользователя по ключу
This commit is contained in:
@@ -9,8 +9,8 @@ public class UserAccount extends iDBObject {
|
||||
@Description("DEFAULT 1")
|
||||
public int subscribe_active = 1;
|
||||
public String security_key = "";
|
||||
@Description("DEFAULT 'User'")
|
||||
public AccountRole role = AccountRole.User; //права доступа
|
||||
@Description("DEFAULT 'Undefined'")
|
||||
public AccountRole role = AccountRole.Undefined; //права доступа
|
||||
public UserAccount(){
|
||||
|
||||
}
|
||||
@@ -27,4 +27,8 @@ public class UserAccount extends iDBObject {
|
||||
security_key = src_.security_key;
|
||||
role = src_.role;
|
||||
}
|
||||
public UserAccount(String name_in, String email_in){
|
||||
name = name_in;
|
||||
email=email_in;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package _VisualDVM.GlobalData.Account;
|
||||
public enum AccountRole {
|
||||
import java.io.Serializable;
|
||||
public enum AccountRole implements Serializable {
|
||||
Undefined,
|
||||
User,
|
||||
Developer,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -13,8 +13,6 @@ public class ConfirmEmail extends ComponentsServerPass<UserAccount> {
|
||||
String password;
|
||||
UserAccountDialog f = new UserAccountDialog() {
|
||||
{
|
||||
fields.tfName.setText(Global.normalProperties.Email);
|
||||
fields.tfAddress.setText(Global.normalProperties.Email);
|
||||
fields.cbRole.setEnabled(false);
|
||||
}
|
||||
};
|
||||
@@ -27,7 +25,7 @@ public class ConfirmEmail extends ComponentsServerPass<UserAccount> {
|
||||
}
|
||||
@Override
|
||||
protected boolean canStart(Object... args) throws Exception {
|
||||
target = new UserAccount(); // объект для заполнения полей.не более.
|
||||
target = (UserAccount) args[0]; // объект для заполнения полей.не более.
|
||||
password = null;
|
||||
if (f.ShowDialog("Регистрация", target)) {
|
||||
if (!Utils_.validateEmail(target.email, Log)) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package _VisualDVM.Passes.Server;
|
||||
import Common.Database.RepositoryRefuseException;
|
||||
import Common.Passes.Pass;
|
||||
import Common.Visual.UI;
|
||||
import _VisualDVM.Constants;
|
||||
import _VisualDVM.Repository.Server.RepositoryServer;
|
||||
import _VisualDVM.Repository.Server.SafeServerExchangeUnit;
|
||||
|
||||
Reference in New Issue
Block a user