Merge pull request #30 from PI20v/21-add-more-logs

Добавляет сообщения DeleteAccount и ChangePassword
This commit is contained in:
Maxim Slipenko 2022-05-24 13:03:12 +03:00 committed by GitHub
commit c25a92b271
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 5 deletions

View File

@ -66,10 +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, 'Выполнение'), (1, 'Вход'), (2, 'Регистрация');"; 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);";
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.ExecuteNonQuery(); command.ExecuteNonQuery();
command.CommandText = "ATTACH DATABASE @dbpath AS appDB"; command.CommandText = "ATTACH DATABASE @dbpath AS appDB";

12
Logs.cs
View File

@ -33,7 +33,9 @@ namespace AwesomeEmailExtractor
{ {
Execute, Execute,
Login, Login,
Registration Registration,
DeleteAccount,
ChangePassword
} }
public static void Log(User user, Action action, Dictionary<string, object> options) public static void Log(User user, Action action, Dictionary<string, object> options)
@ -151,6 +153,14 @@ namespace AwesomeEmailExtractor
{ {
return "Пользователь зарегистрировался в системе."; return "Пользователь зарегистрировался в системе.";
} }
if (action == Action.DeleteAccount)
{
return "Пользователь удалил аккаунт из системы.";
}
if (action == Action.ChangePassword)
{
return "Пользователь сменил пароль.";
}
return ""; return "";
} }

View File

@ -24,6 +24,7 @@ namespace AwesomeEmailExtractor
if (result == DialogResult.Yes) if (result == DialogResult.Yes)
{ {
Globals.currentUser.Delete(); Globals.currentUser.Delete();
Logs.Log(Globals.currentUser, Logs.Action.DeleteAccount, new Dictionary<string, object>());
MessageBox.Show("Аккаунт удален!"); MessageBox.Show("Аккаунт удален!");
this.Close(); this.Close();
@ -42,6 +43,7 @@ namespace AwesomeEmailExtractor
} }
Globals.currentUser.ChangePassword(entryNewPassword.Text); Globals.currentUser.ChangePassword(entryNewPassword.Text);
Logs.Log(Globals.currentUser, Logs.Action.ChangePassword, new Dictionary<string, object>());
MessageBox.Show("Пароль изменен!"); MessageBox.Show("Пароль изменен!");
} }
} }