улучшает логи и добавляет метод для удаления пользователя
This commit is contained in:
parent
ff9e5827b7
commit
c8bb88a734
@ -117,6 +117,22 @@ namespace AwesomeEmailExtractor
|
|||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteUser(string login)
|
||||||
|
{
|
||||||
|
if (User.Role != UserRoles.ADMIN)
|
||||||
|
{
|
||||||
|
throw new Exception("Недостаточно прав!");
|
||||||
|
}
|
||||||
|
|
||||||
|
SqliteCommand command = new SqliteCommand();
|
||||||
|
command.Connection = Globals.db;
|
||||||
|
command.CommandText = "DELETE FROM users WHERE login = @login";
|
||||||
|
|
||||||
|
SqliteParameter loginParam = new SqliteParameter("@login", login);
|
||||||
|
command.Parameters.Add(loginParam);
|
||||||
|
|
||||||
|
command.ExecuteNonQuery();
|
||||||
|
}
|
||||||
public List<User> getAllUsers()
|
public List<User> getAllUsers()
|
||||||
{
|
{
|
||||||
if (User.Role != UserRoles.ADMIN)
|
if (User.Role != UserRoles.ADMIN)
|
||||||
|
@ -22,6 +22,7 @@ namespace AwesomeEmailExtractor
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Globals.currentUser = Authorization.Login(entryLogin.Text, entryPassword.Text);
|
Globals.currentUser = Authorization.Login(entryLogin.Text, entryPassword.Text);
|
||||||
|
Logs.Log(Globals.currentUser, Logs.Action.Login, new Dictionary<string, object>());
|
||||||
|
|
||||||
var mainForm = FormManager.Current.CreateForm<MainForm>();
|
var mainForm = FormManager.Current.CreateForm<MainForm>();
|
||||||
FormManager.Current.Navigate(this, mainForm);
|
FormManager.Current.Navigate(this, mainForm);
|
||||||
|
@ -66,7 +66,7 @@ namespace AwesomeEmailExtractor
|
|||||||
command.CommandText = "CREATE TABLE IF NOT EXISTS logs_actions (id INTEGER PRIMARY KEY, name TEXT NOT NULL)";
|
command.CommandText = "CREATE TABLE IF NOT EXISTS logs_actions (id INTEGER PRIMARY KEY, name TEXT NOT NULL)";
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
|
|
||||||
command.CommandText = "INSERT OR IGNORE INTO logs_actions (id, name) VALUES (0, 'Выполнение');";
|
command.CommandText = "INSERT OR IGNORE INTO logs_actions (id, name) VALUES (0, 'Выполнение'), (1, 'Вход'), (2, 'Регистрация');";
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
|
|
||||||
command.CommandText = "CREATE TABLE IF NOT EXISTS logs (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL, date TEXT NOT NULL, action INTEGER NOT NULL, message TEXT NOT NULL, FOREIGN KEY(action) REFERENCES logs_actions(id));";
|
command.CommandText = "CREATE TABLE IF NOT EXISTS logs (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL, date TEXT NOT NULL, action INTEGER NOT NULL, message TEXT NOT NULL, FOREIGN KEY(action) REFERENCES logs_actions(id));";
|
||||||
|
22
Logs.cs
22
Logs.cs
@ -19,6 +19,8 @@ namespace AwesomeEmailExtractor
|
|||||||
public enum Action
|
public enum Action
|
||||||
{
|
{
|
||||||
Execute,
|
Execute,
|
||||||
|
Login,
|
||||||
|
Registration
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Log(User user, Action action, Dictionary<string, object> options)
|
public static void Log(User user, Action action, Dictionary<string, object> options)
|
||||||
@ -68,7 +70,15 @@ namespace AwesomeEmailExtractor
|
|||||||
command.Parameters.AddWithValue("@dbpath", Globals.getAppDatabase());
|
command.Parameters.AddWithValue("@dbpath", Globals.getAppDatabase());
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
|
|
||||||
command.CommandText = "SELECT user_id, appDB.users.login, appDB.users.id as role_id, date, action, message FROM logs LEFT JOIN appDB.users ON logs.user_id = appDB.users.id ORDER BY date DESC ";
|
command.CommandText = @"
|
||||||
|
SELECT
|
||||||
|
user_id,
|
||||||
|
CASE WHEN appDB.users.login is NULL THEN 'Deleted_' || user_id ELSE appDB.users.login END AS login
|
||||||
|
appDB.users.role,
|
||||||
|
date,
|
||||||
|
action,
|
||||||
|
message
|
||||||
|
from logs LEFT JOIN appDB.users on logs.user_id = appDB.users.id ORDER BY date DESC";
|
||||||
|
|
||||||
SqliteDataReader reader = command.ExecuteReader();
|
SqliteDataReader reader = command.ExecuteReader();
|
||||||
|
|
||||||
@ -100,10 +110,16 @@ namespace AwesomeEmailExtractor
|
|||||||
$"Найдено {count} email-ов.\n" +
|
$"Найдено {count} email-ов.\n" +
|
||||||
$"Список уникальных: {String.Join(", ", uniqueEmails)}.";
|
$"Список уникальных: {String.Join(", ", uniqueEmails)}.";
|
||||||
}
|
}
|
||||||
else
|
if (action == Action.Login)
|
||||||
{
|
{
|
||||||
|
return "Пользователь вошел в систему.";
|
||||||
|
}
|
||||||
|
if (action == Action.Registration)
|
||||||
|
{
|
||||||
|
return "Пользователь зарегистрировался в системе.";
|
||||||
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -45,7 +45,7 @@ namespace AwesomeEmailExtractor
|
|||||||
uniqueListBox.DataSource = uniqueEmails;
|
uniqueListBox.DataSource = uniqueEmails;
|
||||||
|
|
||||||
Logs.Log(
|
Logs.Log(
|
||||||
new User(1, "", UserRoles.ADMIN),
|
Globals.currentUser,
|
||||||
Logs.Action.Execute,
|
Logs.Action.Execute,
|
||||||
new Dictionary<string, object>() {
|
new Dictionary<string, object>() {
|
||||||
{ "sourceText", sourceText },
|
{ "sourceText", sourceText },
|
||||||
|
@ -28,6 +28,7 @@ namespace AwesomeEmailExtractor
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Globals.currentUser = Authorization.Register(entryLogin.Text, entryPassword.Text);
|
Globals.currentUser = Authorization.Register(entryLogin.Text, entryPassword.Text);
|
||||||
|
Logs.Log(Globals.currentUser, Logs.Action.Registration, new Dictionary<string, object>());
|
||||||
|
|
||||||
var form = FormManager.Current.CreateForm<MainForm>();
|
var form = FormManager.Current.CreateForm<MainForm>();
|
||||||
FormManager.Current.Navigate(this, form);
|
FormManager.Current.Navigate(this, form);
|
||||||
|
Reference in New Issue
Block a user