Добавление учетных записей администратором
This commit is contained in:
@@ -29,6 +29,7 @@ import org.apache.commons.lang.RandomStringUtils;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
@@ -337,7 +338,7 @@ public class ComponentsServer extends RepositoryServer<BugReportsDatabase> {
|
||||
account = new UserAccount(account_info);
|
||||
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));
|
||||
account.generateKey();
|
||||
}
|
||||
response.object = account;
|
||||
response.arg = FileUtils.readFileToString(account.getServerKeyFile());
|
||||
@@ -345,9 +346,18 @@ public class ComponentsServer extends RepositoryServer<BugReportsDatabase> {
|
||||
void ReceiveCredentialsDatabase() throws Exception {
|
||||
response.object = Utils_.fileToBytes(credentials_db.getFile());
|
||||
}
|
||||
void PublishUserAccount() throws Exception {
|
||||
DBObject dbObject = (DBObject) request.object;
|
||||
response.object = (Serializable) credentials_db.InsertS(dbObject).getPK();
|
||||
//--
|
||||
credentials_db.userAccounts.get(response.object).generateKey();
|
||||
}
|
||||
void EditUserAccount() throws Exception {
|
||||
UserAccount new_object = (UserAccount) request.object;
|
||||
credentials_db.UpdateWithCheck(new_object);
|
||||
}
|
||||
void DeleteUserAccount() throws Exception {
|
||||
|
||||
}
|
||||
//--
|
||||
@Override
|
||||
@@ -385,6 +395,9 @@ public class ComponentsServer extends RepositoryServer<BugReportsDatabase> {
|
||||
@Override
|
||||
protected void Session() throws Exception {
|
||||
switch (code) {
|
||||
case PublishUserAccount:
|
||||
PublishUserAccount();
|
||||
break;
|
||||
case EditUserAccount:
|
||||
EditUserAccount();
|
||||
break;
|
||||
|
||||
@@ -4,7 +4,6 @@ import Common.Visual.DataSetControlForm;
|
||||
import Common.Visual.Menus.DataMenuBar;
|
||||
import Common.Visual.Tables.ColumnInfo;
|
||||
import Common.Visual.Windows.Dialog.DBObjectDialog;
|
||||
import _VisualDVM.ComponentsServer.Subscribes.Subscriber;
|
||||
import _VisualDVM.ComponentsServer.UserAccount.AccountRole;
|
||||
import _VisualDVM.ComponentsServer.UserAccount.UserAccount;
|
||||
import _VisualDVM.Global;
|
||||
@@ -50,7 +49,9 @@ public class UserAccountsForm extends DataSetControlForm<UserAccount> {
|
||||
}
|
||||
@Override
|
||||
protected DataMenuBar createMenuBar() {
|
||||
return new DataMenuBar(dataSource.getPluralDescription(), PassCode.SynchronizeCredentials, PassCode.EditUserAccount);
|
||||
return new DataMenuBar(dataSource.getPluralDescription(), PassCode.SynchronizeCredentials,
|
||||
PassCode.PublishUserAccount,
|
||||
PassCode.EditUserAccount);
|
||||
}
|
||||
@Override
|
||||
protected DBObjectDialog getDialog() {
|
||||
|
||||
@@ -47,6 +47,9 @@ public class UserAccount extends iDBObject {
|
||||
public String getKey() throws Exception{
|
||||
return FileUtils.readFileToString(getServerKeyFile());
|
||||
}
|
||||
public void generateKey() throws Exception {
|
||||
FileUtils.writeStringToFile(getServerKeyFile(), RandomStringUtils.random(100, true, true));
|
||||
}
|
||||
//todo часть устарело.разобрать.
|
||||
public boolean CheckRegistered(TextLog Log) {
|
||||
if (role.equals(AccountRole.Undefined)) {
|
||||
|
||||
22
src/_VisualDVM/Passes/All/PublishUserAccount.java
Normal file
22
src/_VisualDVM/Passes/All/PublishUserAccount.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package _VisualDVM.Passes.All;
|
||||
import Common.Database.Database;
|
||||
import _VisualDVM.ComponentsServer.ComponentsServer;
|
||||
import _VisualDVM.ComponentsServer.UserAccount.UserAccount;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Passes.Server.PublishServerObject;
|
||||
import _VisualDVM.Repository.Server.SafeServerExchangeUnit;
|
||||
import _VisualDVM.Repository.Server.ServerCode;
|
||||
public class PublishUserAccount extends PublishServerObject<ComponentsServer, UserAccount> {
|
||||
public PublishUserAccount() {
|
||||
super(Global.componentsServer, UserAccount.class);
|
||||
}
|
||||
@Override
|
||||
protected Database getDb() {
|
||||
return server.credentials_db;
|
||||
}
|
||||
@Override
|
||||
protected void ServerAction() throws Exception {
|
||||
Command(new SafeServerExchangeUnit(ServerCode.PublishUserAccount, "", target));
|
||||
pk = server_response.object;
|
||||
}
|
||||
}
|
||||
@@ -356,12 +356,15 @@ public enum PassCode implements PassCode_ {
|
||||
DetectSelectedTestsMinMaDim,
|
||||
ConfirmEmail,
|
||||
SynchronizeCredentials,
|
||||
PublishUserAccount,
|
||||
EditUserAccount
|
||||
;
|
||||
//--
|
||||
@Override
|
||||
public String getDescription() {
|
||||
switch (this) {
|
||||
case PublishUserAccount:
|
||||
return "Добавление учётной записи";
|
||||
case EditUserAccount:
|
||||
return "Редактирование учётной записи";
|
||||
case SynchronizeCredentials:
|
||||
|
||||
@@ -32,13 +32,10 @@ public class PublishServerObject<S extends RepositoryServer, D extends DBObject>
|
||||
}
|
||||
return false;
|
||||
}
|
||||
protected String getEmail() {
|
||||
return null;
|
||||
}
|
||||
//--
|
||||
@Override
|
||||
protected void ServerAction() throws Exception {
|
||||
Command(new SafeServerExchangeUnit(ServerCode.PublishObject, getEmail(), target));
|
||||
Command(new SafeServerExchangeUnit(ServerCode.PublishObject, "", target));
|
||||
pk = server_response.object;
|
||||
}
|
||||
@Override
|
||||
|
||||
@@ -65,9 +65,12 @@ public enum ServerCode {
|
||||
DetectTestsMinMaxDim,
|
||||
GetUserAccountByKey,
|
||||
GetUserAccountByEmail,
|
||||
EditUserAccount;
|
||||
EditUserAccount,
|
||||
PublishUserAccount;
|
||||
public String getDescription(){
|
||||
switch (this){
|
||||
case PublishUserAccount:
|
||||
return "Создание учётной записи на сервере";
|
||||
case EditUserAccount:
|
||||
return "Редактирование учётной записи на сервере";
|
||||
case ReceiveCredentialsDatabase:
|
||||
|
||||
Reference in New Issue
Block a user