91 lines
3.3 KiB
Java
91 lines
3.3 KiB
Java
package _VisualDVM.ComponentsServer.UserAccount;
|
|
import Common.Database.Objects.DBObject;
|
|
import Common.Database.Objects.iDBObject;
|
|
import Common.Utils.TextLog;
|
|
import _VisualDVM.ComponentsServer.BugReport.BugReport;
|
|
import _VisualDVM.Global;
|
|
import com.sun.org.glassfish.gmbal.Description;
|
|
public class UserAccount extends iDBObject {
|
|
public String name = "";
|
|
public String email = "";
|
|
@Description("DEFAULT ''")
|
|
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(){
|
|
|
|
}
|
|
public UserAccount(UserAccount account_in) {
|
|
this.SynchronizeFields(account_in);
|
|
}
|
|
@Override
|
|
public void SynchronizeFields(DBObject src) {
|
|
super.SynchronizeFields(src);
|
|
UserAccount src_ = (UserAccount) src;
|
|
name = src_.name;
|
|
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;
|
|
}
|
|
//todo часть устарело.разобрать.
|
|
public boolean CheckRegistered(TextLog Log) {
|
|
if (role.equals(AccountRole.Undefined)) {
|
|
if (Log != null) {
|
|
Log.Writeln("Пользователь не зарегистрирован");
|
|
if (Global.mainModule.getUI().hasMainWindow())
|
|
Global.mainModule.getUI().getMainWindow().FocusCallback();
|
|
}
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public boolean isRegistered() {
|
|
return !role.equals(AccountRole.Undefined);
|
|
}
|
|
public boolean CheckAuthorship(String address_in, TextLog log) {
|
|
if (!isAdmin() && (!email.equals(address_in))) {
|
|
if (log != null)
|
|
log.Writeln_("Вы не являетесь автором или администратором");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
public boolean CheckAccessRights(String address_in, TextLog log) {
|
|
return (CheckRegistered(log) && CheckAuthorship(address_in, log));
|
|
}
|
|
public boolean ExtendedCheckAccessRights(BugReport bugReport, TextLog log) {
|
|
if (CheckRegistered(log)) {
|
|
if (email.equals(bugReport.executor_address)) {
|
|
//метод вывести как нерабочий.когда будет изменена схема админства.
|
|
return true;
|
|
} else {
|
|
if (!isAdmin() && (!email.equals(bugReport.sender_address))) {
|
|
log.Writeln_("Вы не являетесь автором, исполнителем, или администратором");
|
|
return false;
|
|
} else return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
public boolean isAdmin() {
|
|
return role.equals(AccountRole.Admin);
|
|
}
|
|
public boolean CheckAdmin(TextLog log) {
|
|
if (!isAdmin()) {
|
|
log.Writeln_("Вы не являетесь администратором!");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
//---
|
|
}
|