ключ теперь не поле бд а отдельный файл на сервере.
This commit is contained in:
@@ -7,11 +7,10 @@ import _VisualDVM.ComponentsServer.BugReport.Json.BugReportAdditionJson;
|
||||
import _VisualDVM.ComponentsServer.Component.ComponentType;
|
||||
import _VisualDVM.ComponentsServer.Component.Json.ComponentPublicationInfoJson;
|
||||
import _VisualDVM.ComponentsServer.Component.Json.ComponentVersionsInfoJson;
|
||||
import _VisualDVM.ComponentsServer.Subscribes.Subscriber;
|
||||
import _VisualDVM.ComponentsServer.UserAccount.AccountRole;
|
||||
import _VisualDVM.ComponentsServer.UserAccount.UserAccount;
|
||||
import _VisualDVM.Constants;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.ComponentsServer.UserAccount.AccountRole;
|
||||
import _VisualDVM.GlobalData.Machine.Machine;
|
||||
import _VisualDVM.GlobalData.Machine.MachineType;
|
||||
import _VisualDVM.GlobalData.RemoteFile.RemoteFile;
|
||||
@@ -49,7 +48,7 @@ public class ComponentsServer extends RepositoryServer<BugReportsDatabase> {
|
||||
"dvmh.keldysh.ru",
|
||||
22, MachineType.Server),
|
||||
new User("dvmuser1", "mprit_2011"))
|
||||
));
|
||||
));
|
||||
//-
|
||||
protected Thread backUp = new Thread(() -> {
|
||||
while (true) {
|
||||
@@ -221,7 +220,7 @@ public class ComponentsServer extends RepositoryServer<BugReportsDatabase> {
|
||||
response.object = Utils_.fileToBytes(archives);
|
||||
} else throw new RepositoryRefuseException("Не удалось запаковать архивы");
|
||||
}
|
||||
void ReceiveBugReportsDatabase() throws Exception{
|
||||
void ReceiveBugReportsDatabase() throws Exception {
|
||||
response.object = Utils_.fileToBytes(db.getFile());
|
||||
}
|
||||
void ReceiveBugReport() throws Exception {
|
||||
@@ -329,23 +328,24 @@ public class ComponentsServer extends RepositoryServer<BugReportsDatabase> {
|
||||
}
|
||||
void GetUserAccountByKey() throws Exception {
|
||||
UserAccount account = credentials_db.userAccounts.getByKey(request.arg);
|
||||
response.object = account==null? null: account;
|
||||
response.object = account == null ? null : account;
|
||||
}
|
||||
void GetUserAccountByEmail() throws Exception {
|
||||
UserAccount account_info = (UserAccount) request.object;
|
||||
UserAccount account = credentials_db.userAccounts.getByEmail(account_info.email);
|
||||
if (account==null){
|
||||
if (account == null) {
|
||||
account = new UserAccount(account_info);
|
||||
account.role = Constants.admins_mails.contains(account.email)? AccountRole.Admin: AccountRole.User;
|
||||
account.security_key = RandomStringUtils.random(100, true, true);
|
||||
account.role = Constants.admins_mails.contains(account.email) ? AccountRole.Admin : AccountRole.User;
|
||||
credentials_db.Insert(account);
|
||||
FileUtils.writeStringToFile(account.getServerKeyFile(), RandomStringUtils.random(100, true, true));
|
||||
}
|
||||
response.object = account;
|
||||
response.arg = FileUtils.readFileToString(account.getServerKeyFile());
|
||||
}
|
||||
void ReceiveCredentialsDatabase() throws Exception{
|
||||
void ReceiveCredentialsDatabase() throws Exception {
|
||||
response.object = Utils_.fileToBytes(credentials_db.getFile());
|
||||
}
|
||||
void EditUserAccount() throws Exception{
|
||||
void EditUserAccount() throws Exception {
|
||||
UserAccount new_object = (UserAccount) request.object;
|
||||
credentials_db.UpdateWithCheck(new_object);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,10 @@ import Common.Utils.TextLog;
|
||||
import _VisualDVM.ComponentsServer.BugReport.BugReport;
|
||||
import _VisualDVM.Global;
|
||||
import com.sun.org.glassfish.gmbal.Description;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
|
||||
import java.io.File;
|
||||
public class UserAccount extends iDBObject {
|
||||
public String name = "";
|
||||
public String email = "";
|
||||
@@ -12,7 +16,6 @@ public class UserAccount extends iDBObject {
|
||||
public String telegram_name="";
|
||||
@Description("DEFAULT 1")
|
||||
public int subscribe_active = 1;
|
||||
public String security_key = "";
|
||||
@Description("DEFAULT 'Undefined'")
|
||||
public AccountRole role = AccountRole.Undefined; //права доступа
|
||||
public UserAccount(){
|
||||
@@ -29,13 +32,21 @@ public class UserAccount extends iDBObject {
|
||||
email = src_.email;
|
||||
telegram_name=src_.telegram_name;
|
||||
subscribe_active=src_.subscribe_active;
|
||||
security_key = src_.security_key;
|
||||
role = src_.role;
|
||||
}
|
||||
public UserAccount(String name_in, String email_in){
|
||||
name = name_in;
|
||||
email=email_in;
|
||||
}
|
||||
public File getClientKeyFile(){
|
||||
return new File(Global.KeysDirectory,"key");
|
||||
}
|
||||
public File getServerKeyFile(){
|
||||
return new File(Global.KeysDirectory,String.valueOf(id));
|
||||
}
|
||||
public String getKey() throws Exception{
|
||||
return FileUtils.readFileToString(getServerKeyFile());
|
||||
}
|
||||
//todo часть устарело.разобрать.
|
||||
public boolean CheckRegistered(TextLog Log) {
|
||||
if (role.equals(AccountRole.Undefined)) {
|
||||
|
||||
@@ -8,9 +8,9 @@ public class UserAccountsDBTable extends iDBTable<UserAccount> {
|
||||
public UserAccountsDBTable() {
|
||||
super(UserAccount.class);
|
||||
}
|
||||
public UserAccount getByKey(String key_in){
|
||||
public UserAccount getByKey(String key_in) throws Exception{
|
||||
for (UserAccount userAccount: Data.values()){
|
||||
if (userAccount.security_key.equals(key_in))
|
||||
if (userAccount.getKey().equals(key_in))
|
||||
return userAccount;
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user